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 applyUpdateV2(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 decodeStateVectorV2(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 encodeStateAsUpdateV2(doc, encodedTargetStateVectoropt, encoderopt) → {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

encoder AbstractUpdateEncoder <optional>
Returns:
Uint8Array

static encodeStateVector(doc) → {Uint8Array}

Encode State as Uint8Array.

Parameters:
Name Type Description
doc Doc
Returns:
Uint8Array

static encodeStateVectorV2(doc, encoderopt) → {Uint8Array}

Encode State as Uint8Array.

Parameters:
Name Type Attributes Description
doc Doc
encoder AbstractDSEncoder <optional>
Returns:
Uint8Array

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

Read state vector from Decoder and return as Map

Parameters:
Name Type Description
decoder AbstractDSDecoder
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 readUpdateV2(decoder, ydoc, transactionOriginopt, structDecoderopt)

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))

structDecoder AbstractUpdateDecoder <optional>

static writeDocumentStateVector(encoder, doc)

Parameters:
Name Type Description
encoder AbstractDSEncoder
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 AbstractUpdateEncoder
doc Doc
targetStateVector Map.<number, number> <optional>

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

static writeStateVector(encoder, sv)

Parameters:
Name Type Description
encoder AbstractDSEncoder
sv Map.<number, number>

inner cleanupPendingStructs(pendingClientsStructRefs)

Parameters:
Name Type Description
pendingClientsStructRefs Map.<number, {refs:Array.<(GC|Item)>, i:number}>

inner writeStructs(encoder, structs, client, clock)

Parameters:
Name Type Description
encoder AbstractUpdateEncoder
structs Array.<(GC|Item)>

All structs by client

client number
clock number

write structs starting with ID(client,clock)