encoding

Methods

static applyUpdate(ydoc, update, transactionOriginopt)

Apply a document update created by, for example, y.on('update', update => ..) or update = encodeStateAsUpdate().

This function has the same effect as readUpdate but accepts an Uint8Array instead of a Decoder.

Parameters:
Name Type Attributes Description
ydoc Doc
update Uint8Array
transactionOrigin any <optional>

This will be stored on transaction.origin and .on('update', (update, origin))

static decodeStateVector(decodedState) → {Map.<number, number>}

Read decodedState and return State as Map.

Parameters:
Name Type Description
decodedState Uint8Array
Returns:
Map.<number, number> -

Maps client to the number next expected clock from that client.

static encodeStateAsUpdate(doc, encodedTargetStateVectoropt) → {Uint8Array}

Write all the document as a single update message that can be applied on the remote document. If you specify the state of the remote client (targetState) it will only write the operations that are missing.

Use writeStateAsUpdate instead if you are working with lib0/encoding.js#Encoder

Parameters:
Name Type Attributes Description
doc Doc
encodedTargetStateVector Uint8Array <optional>

The state of the target that receives the update. Leave empty to write all known structs

Returns:
Uint8Array

static encodeStateVector(doc) → {Uint8Array}

Encode State as Uint8Array.

Parameters:
Name Type Description
doc Doc
Returns:
Uint8Array

static readStateVector(decoder) → {Map.<number, number>}

Read state vector from Decoder and return as Map

Parameters:
Name Type Description
decoder decoding.Decoder
Returns:
Map.<number, number> -

Maps client to the number next expected clock from that client.

static readUpdate(decoder, ydoc, transactionOriginopt)

Read and apply a document update.

This function has the same effect as applyUpdate but accepts an decoder.

Parameters:
Name Type Attributes Description
decoder decoding.Decoder
ydoc Doc
transactionOrigin any <optional>

This will be stored on transaction.origin and .on('update', (update, origin))

static writeDocumentStateVector(encoder, doc)

Write State Vector to lib0/encoding.js#Encoder.

Parameters:
Name Type Description
encoder encoding.Encoder
doc Doc

static writeStateAsUpdate(encoder, doc, targetStateVectoropt)

Write all the document as a single update message. If you specify the state of the remote client (targetStateVector) it will only write the operations that are missing.

Parameters:
Name Type Attributes Description
encoder encoding.Encoder
doc Doc
targetStateVector Map.<number, number> <optional>

The state of the target that receives the update. Leave empty to write all known structs

inner writeStructs(encoder, structs, client, clock)

Parameters:
Name Type Description
encoder encoding.Encoder
structs Array.<AbstractStruct>

All structs by client

client number
clock number

write structs starting with ID(client,clock)