Y.applyUpdate(Y.Doc, update:Uint8Array, [transactionOrigin:any])Apply a document update on the shared document. Optionally you can specify
transactionOriginthat will be stored on
ydoc.on('update', (update, origin) => ..).
Y.encodeStateAsUpdate(Y.Doc, [encodedTargetStateVector:Uint8Array]): Uint8ArrayEncode the document state as a single update message that can be applied on the remote document. Optionally, specify the target state vector to only write the missing differences to the update message.
Y.encodeStateVector(Y.Doc): Uint8ArrayComputes the state vector and encodes it into an Uint8Array. A state vector describes the state of the local client. The remote client can use this to exchange only the missing differences.
ydoc.on('update', eventHandler: function(update: Uint8Array, origin: any, doc: Y.Doc))Listen to incremental updates on the Yjs document. This is part of the Y.Doc API. Send the computed incremental update to all connected clients, or store it in a database.
Y.logUpdate(Uint8Array)(experimental) Log the contents of a document update to the console. This utility function is only meant for debugging and understanding the Yjs document format. It is marked as experimental because it might be changed or removed at any time.
Y.mergeUpdates(Array<Uint8Array>): Uint8ArrayMerge several document updates into a single document update while removing duplicate information. The merged document update is always smaller than the separate updates because of the compressed encoding.
Y.encodeStateVectorFromUpdate(Uint8Array): Uint8ArrayComputes the state vector from a document update and encodes it into an Uint8Array.
Y.diffUpdate(update: Uint8Array, stateVector: Uint8Array): Uint8ArrayEncode the missing differences to another update message. This function works similarly to
Y.encodeStateAsUpdate(ydoc, stateVector)but works on updates instead.
Uint8Arrayrepresents binary data similarly to a NodeJS' Buffer . The difference is that
JSON.parsethe data because there is no JSON representation for binary data. However, most communication protocols support binary data. If you still need to transform the data into a string, you can use Base64 encoding. For example, by using the
isLocalflag or use a lib0/mutex. However, it is recommended that all providers set the transaction origin which makes it easier for developers to debug where an update comes from.