View Source Yex (y_ex v0.5.1)

Yex is wrapper library for the Yjs CRDT library.

Summary

Functions

Apply a document update on the shared document.

Encode 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.

Computes the state vector and encodes it into an Binary. A state vector describes the state of the local client. The remote client can use this to exchange only the missing differences.

@see encode_state_vector/1

Functions

Link to this function

apply_update(doc, update)

View Source
@spec apply_update(Yex.Doc.t(), binary()) :: :ok | {:error, term()}

Apply a document update on the shared document.

Examples Sync two clients by exchanging the complete document structure

iex> doc1 = Yex.Doc.new()
iex> doc2 = Yex.Doc.new()
iex> {:ok, state1} = Yex.encode_state_as_update(doc1)
iex> {:ok, state2} = Yex.encode_state_as_update(doc2)
iex> Yex.apply_update(doc1, state2)
:ok
iex> Yex.apply_update(doc2, state1)
:ok
Link to this function

apply_update_v1(doc, update)

View Source
@spec apply_update_v1(Yex.Doc.t(), binary()) :: :ok | {:error, term()}
Link to this function

apply_update_v2(doc, update)

View Source
@spec apply_update_v2(Yex.Doc.t(), binary()) :: :ok | {:error, term()}
Link to this function

encode_state_as_update(doc, encoded_state_vector \\ nil)

View Source
@spec encode_state_as_update(Yex.Doc.t(), binary() | nil) ::
  {:ok, binary()} | {:error, term()}

Encode 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.

Examples

iex> doc = Yex.Doc.new()
iex> {:ok, _binary} = Yex.encode_state_as_update(doc)
Link to this function

encode_state_as_update!(doc, encoded_state_vector \\ nil)

View Source
@spec encode_state_as_update!(Yex.Doc.t(), binary() | nil) :: binary()

@see encode_state_as_update/2

Link to this function

encode_state_as_update_v1(doc, encoded_state_vector \\ nil)

View Source
Link to this function

encode_state_as_update_v2(doc, encoded_state_vector \\ nil)

View Source
Link to this function

encode_state_vector(doc)

View Source
@spec encode_state_vector(Yex.Doc.t()) :: {:ok, binary()} | {:error, term()}

Computes the state vector and encodes it into an Binary. A state vector describes the state of the local client. The remote client can use this to exchange only the missing differences.

Examples

iex> doc = Yex.Doc.new()
iex> {:ok, _binary} = Yex.encode_state_vector(doc)
Link to this function

encode_state_vector!(doc)

View Source
@spec encode_state_vector!(Yex.Doc.t()) :: binary()

@see encode_state_vector/1

Link to this function

encode_state_vector_v1(doc)

View Source
Link to this function

encode_state_vector_v2(doc)

View Source