56 releases

new 0.18.8 May 10, 2024
0.18.3 Apr 12, 2024
0.18.2 Mar 27, 2024
0.17.2 Dec 7, 2023
0.1.0 Oct 14, 2021

#72 in WebAssembly

Download history 15/week @ 2024-01-22 53/week @ 2024-02-26 123/week @ 2024-03-11 108/week @ 2024-03-18 99/week @ 2024-03-25 33/week @ 2024-04-01 128/week @ 2024-04-08 9/week @ 2024-04-15 839/week @ 2024-04-29 146/week @ 2024-05-06

999 downloads per month

MIT license

1.5MB
29K SLoC

Ywasm

This project is a wrapper around Yrs and targets Web Assembly bindings.

It's a library used on collaborative document editing using Conflict-free Replicated Data Types. This enables to provide a shared document editing experience on a client devices without explicit requirement for hosting a single server - CRDTs can resolve potential update conflicts on their own with no central authority - as well as provide first-class offline editing capabilities, where document replicas are modified without having connection to each other, and then synchronize automatically once such connection is enabled.

Documentation

Example

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)

Dependencies

~8–11MB
~194K SLoC