59 个版本
0.19.2 | 2024 年 7 月 17 日 |
---|---|
0.18.8 | 2024 年 5 月 10 日 |
0.18.2 | 2024 年 3 月 27 日 |
0.17.2 | 2023 年 12 月 7 日 |
0.1.0 | 2021 年 10 月 14 日 |
#78 在 WebAssembly 中
626 次每月下载
1.5MB
32K SLoC
Ywasm
此项目是围绕 Yrs 的包装,并针对 Web Assembly 绑定。
它是一个用于协同文档编辑的库,使用无冲突副本数据类型。这使得在客户端设备上提供共享的文档编辑体验,而无需显式托管单个服务器 - CRDT 可以在没有中央权威的情况下自行解决潜在更新冲突 - 同时还提供一流的离线编辑功能,文档副本在彼此没有连接的情况下进行修改,并在连接启用后自动同步。
文档
示例
import * as Y from 'ywasm';
const doc = new Y.YDoc()
const text = doc.getText('name')
// append text to our collaborative document
text.insert(0, 'hello world', { bold: true })
// simulate update with remote peer
const remoteDoc = new Y.YDoc()
const remoteText = remoteDoc.getText('name')
// in order to exchange data with other documents
// we first need to create a state vector
const remoteSV = Y.encodeStateVector(remoteDoc)
// now compute a differential update based on remote document's state vector
const update = Y.encodeStateAsUpdate(doc, remoteSV)
// both update and state vector are serializable, we can pass them over the wire
// now apply update to a remote document
Y.applyUpdate(remoteDoc, update)
const str = remoteText.toString()
console.log(str)
依赖项
~8–12MB
~203K SLoC