Function ywasm::encode_state_vector[][src]

pub fn encode_state_vector(doc: &mut YDoc) -> Uint8Array
Expand description

Encodes a state vector of a given ywasm document into its binary representation using lib0 v1 encoding. State vector is a compact representation of updates performed on a given document and can be used by encode_state_as_update on remote peer to generate a delta update payload to synchronize changes between peers.

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 = encodeStateAsUpdate(remoteDoc, localSV)

applyUpdate(localDoc, remoteDelta)