Function ywasm::encode_state_as_update_v2
source ยท pub fn encode_state_as_update_v2(
doc: &Doc,
vector: Option<Uint8Array>,
) -> Result<Uint8Array, JsValue>
Expand description
Encodes all updates that have happened since a given version vector
into a compact delta
representation using lib0 v2 encoding. If vector
parameter has not been provided, generated
delta payload will contain all changes of a current ywasm document, working effectivelly as its
state snapshot.
Example:
import {YDoc, encodeStateVector, encodeStateAsUpdate, applyUpdate} from 'ywasm'
/// document on machine A
const localDoc = new YDoc()
const localSV = encodeStateVector(localDoc)
// document on machine B
const remoteDoc = new YDoc()
const remoteDelta = encodeStateAsUpdateV2(remoteDoc, localSV)
applyUpdate(localDoc, remoteDelta)