YArray.YArray()

A shared Array implementation.

new YArray()

Implements:
  • IterableIterator.<T>

Extends

Methods

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.

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>