View Source Yex.Array (y_ex v0.3.5)

A shareable Array-like type that supports efficient insert/delete of elements at any position.

Summary

Types

@type t() :: %Yex.Array{reference: any()}

Functions

Link to this function

delete_range(array, index, length)

View Source
Link to this function

insert(array, index, content)

View Source

Returns the length of the array

Examples Sync two clients by exchanging the complete document structure

iex> doc = Yex.Doc.new()
iex> array = Yex.Doc.get_array(doc, "array")
iex> Yex.Array.push(array, "Hello")
iex> Yex.Array.push(array, "World")
iex> Yex.Array.length(array)
2
@spec to_json(t()) :: term()

Convert to json-compatible format.

Examples Sync two clients by exchanging the complete document structure

iex> doc = Yex.Doc.new()
iex> array = Yex.Doc.get_array(doc, "array")
iex> Yex.Array.push(array, "Hello")
iex> Yex.Array.push(array, "World")
iex> Yex.Array.to_json(array)
["Hello", "World"]

Returns as list

Examples Sync two clients by exchanging the complete document structure

iex> doc = Yex.Doc.new()
iex> array = Yex.Doc.get_array(doc, "array")
iex> Yex.Array.push(array, "Hello")
iex> Yex.Array.push(array, "World")
iex> Yex.Array.push(array, Yex.ArrayPrelim.from([1, 2]))
iex> ["Hello", "World", %Yex.Array{}] = Yex.Array.to_list(array)