YArray.YArray()

A shared Array implementation.

new YArray()

Implements:
  • Iterable.<T>

Extends

Members

_prelimContent :Array.<any>

_searchMarker :Array.<ArraySearchMarker>

Methods

static from(items) → {YArray.<T>}

Construct a new YArray containing the specified items.

Parameters:
Name Type Description
items Array.<T>
Returns:
YArray.<T>

_callObserver(transaction, parentSubs)

Creates YArrayEvent and calls observers.

Parameters:
Name Type Description
transaction Transaction
parentSubs Set.<(null|string)>

Keys changed on this type. null if list was modified.

_integrate(y, item)

Integrate this type into the Yjs instance.

  • Save this struct in the os
  • This type is sent to other client
  • Observer functions are fired
Parameters:
Name Type Description
y Doc

The Yjs instance

item Item

_write(encoder)

Parameters:
Name Type Description
encoder AbstractUpdateEncoder

clone() → {YArray.<T>}

Returns:
YArray.<T>

delete(index, length)

Deletes elements starting from an index.

Parameters:
Name Type Default Description
index number

Index at which to start deleting elements

length number 1

The number of elements to remove. Defaults to 1.

forEach(f)

Executes a provided function on once on overy element of this YArray.

Parameters:
Name Type Description
f function

A function to execute on every element of this YArray.

get(index) → {T}

Returns the i-th element from a YArray.

Parameters:
Name Type Description
index number

The index of the element to return from the YArray

Returns:
T

insert(index, content)

Inserts new content at an index.

Important: This function expects an array of content. Not just a content object. The reason for this "weirdness" is that inserting several elements is very efficient when it is done as a single operation.

Parameters:
Name Type Description
index number

The index to insert content at.

content Array.<T>

The array of content

Example
// Insert character 'a' at position 0
 yarray.insert(0, ['a'])
 // Insert numbers 1, 2 at position 1
 yarray.insert(1, [1, 2])

map(f) → {Array.<M>}

Returns an Array with the result of calling a provided function on every element of this YArray.

Parameters:
Name Type Description
f function

Function that produces an element of the new Array

Returns:
Array.<M> -

A new array with each element being the result of the callback function

push(content)

Appends content to this YArray.

Parameters:
Name Type Description
content Array.<T>

Array of content to append.

slice(startopt, endopt) → {Array.<T>}

Transforms this YArray to a JavaScript Array.

Parameters:
Name Type Attributes Default Description
start number <optional>
0
end number <optional>
Returns:
Array.<T>

Symbol.iterator() → {IterableIterator.<T>}

Returns:
IterableIterator.<T>

toArray() → {Array.<T>}

Transforms this YArray to a JavaScript Array.

Returns:
Array.<T>

toJSON() → {Array.<any>}

Transforms this Shared Type to a JSON object.

Returns:
Array.<any>

unshift(content)

Preppends content to this YArray.

Parameters:
Name Type Description
content Array.<T>

Array of content to preppend.