Y.Array
A shared type to store data in a sequence-like data structure
API
Y.Array.from(Array<JSON | Uint8Array | Y.AbstractType>): Y.Array
An alternative factory function to create a Y.Array based on existing content.
yarray.doc: Y.Doc | null
(readonly)
The Yjs document that this type is bound to. Is null
when it is not bound yet.
yarray.parent: Y.AbstractType | null
The parent that holds this type. Is null
if this yarray
is a top-level type.
yarray.length: number
The number of elements that this Y.Array holds.
yarray.insert(index: number, content: Array<JSON | Uint8Array | Y.AbstractType>)
Insert content at a specified index
. Note that - for performance reasons - content is always an array of elements. I.e. yarray.insert(0, [1])
inserts 1 at position 0.
yarray.delete(index: number, length: number)
Delete length
Y.Array elements starting from index
.
yarray.push(content: Array<JSON | Uint8Array | Y.AbstractType>)
Append content at the end of the Y.Array. Same as yarray.insert(yarray.length, content)
.
yarray.unshift(content: Array<JSON | Uint8Array | Y.AbstractType>)
Prepend content to the beginning of the Y.Array. Same as yarray.insert(0, content)
.
yarray.get(index: number): JSON | Uint8Array | Y.AbstractType
Retrieve the n-th element.
yarray.toArray(): Array<JSON | Uint8Array | Y.AbstractType>
Copies the content of the Y.Array to a new Array.
yarray.toJSON(): Array<JSON | Uint8Array>
Retrieve the JSON representation of this type. The result is a fresh Array that contains all Y.Array elements. Elements that are shared types are transformed to JSON as well, using their toJSON
method. The result may contain Uint8Arrays which are not JSON-encodable.
yarray.forEach(function(value: any, index: number, yarray: Y.Array))
Execute the provided function once on every element.
yarray.map(function(value: any, index: number, yarray: Y.Array): T): Array<T>
Creates a new Array filled with the results of calling the provided function on each element in the Y.Array.
yarray.clone(): Y.Array
Clone all values into a fresh Y.Array instance. The returned type can be included into the Yjs document.
yarray.observe(function(YArrayEvent, Transaction))
Registers a change observer that will be called synchronously every time this shared type is modified. In the case this type is modified in the observer call, the event listener will be called again after the current event listener returns.
yarray.unobserve(function)
Unregisters a change observer that has been registered with yarray.observe
.
yarray.observeDeep(function(Array<Y.Event>, Transaction))
Registers a change observer that will be called synchronously every time this type or any of its children is modified. In the case this type is modified in the event listener, the event listener will be called again after the current event listener returns. The event listener receives all Events created by itself or any of its children.
yarray.unobserveDeep(function)
Unregisters a change observer that has been registered with yarray.observeDeep
.
Observing changes: Y.ArrayEvent
Y.ArrayEvent API
Last updated
Was this helpful?