Home Reference Source
import YArray from 'yjs/src/Types/YArray/YArray.js'
public class | source

YArray

Extends:

ItemType → YArray

Direct Subclass:

YText, YXmlFragment

Indirect Subclass:

YXmlElement, YXmlText

A shared Array implementation.

Member Summary

Public Members
public get

length: *

Computes the length of this YArray.

Method Summary

Public Methods
public

[Symbol.iterator](): {"next": *, "_item": *, "_itemElement": *, "_count": *}

public

delete(index: Integer, length: Integer)

Deletes elements starting from an index.

public

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

public

get(index: Integer): *

Returns the i-th element from a YArray.

public

insert(index: Integer, content: Array)

Inserts new content at an index.

public

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

public

push(content: Array)

Appends content to this YArray.

public

Transforms this YArray to a JavaScript Array.

public

Transforms this Shared Type to a JSON object.

Inherited Summary

From class Type
public

getPathTo(type: YType): Array<string>

Compute the path from this type to the specified target.

public

Observe all events that are created on this type.

public

Observe all events that are created by this type and its children.

public

Unregister an observer function.

public

Unregister an observer function.

Public Members

public get length: * source

Computes the length of this YArray.

Public Methods

public [Symbol.iterator](): {"next": *, "_item": *, "_itemElement": *, "_count": *} source

Return:

{"next": *, "_item": *, "_itemElement": *, "_count": *}

public delete(index: Integer, length: Integer) source

Deletes elements starting from an index.

Params:

NameTypeAttributeDescription
index Integer

Index at which to start deleting elements

length Integer

The number of elements to remove. Defaults to 1.

public forEach(f: Function) source

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

Params:

NameTypeAttributeDescription
f Function

A function to execute on every element of this YArray.

public get(index: Integer): * source

Returns the i-th element from a YArray.

Params:

NameTypeAttributeDescription
index Integer

The index of the element to return from the YArray

Return:

*

public insert(index: Integer, content: Array) source

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.

Params:

NameTypeAttributeDescription
index Integer

The index to insert content at.

content Array

The array of content

Example:

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

public map(f: Function): Array source

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

Params:

NameTypeAttributeDescription
f Function

Function that produces an element of the new Array

Return:

Array

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

public push(content: Array) source

Appends content to this YArray.

Params:

NameTypeAttributeDescription
content Array

Array of content to append.

public toArray(): Array source

Transforms this YArray to a JavaScript Array.

Return:

Array

public toJSON(): Array source

Transforms this Shared Type to a JSON object.

Return:

Array