Skip to content

API > @blocksuite/store > Y > Array

Class: Array<T> ​

A shared Array implementation.

Implements ​

Extends ​

Implements ​

  • Iterable< T >

Constructors ​

constructor ​

new Array<T>(): Array< T >

Type parameters ​

Parameter
T

Returns ​

Array< T >

Inherited from ​

AbstractType.constructor

Properties ​

_dEH ​

_dEH: EventHandler< YEvent< any >[], Transaction >

Deep event handlers

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/AbstractType.d.ts:46

Inherited from ​

AbstractType._dEH


_eH ​

_eH: EventHandler< YArrayEvent< T >, Transaction >

Event handlers

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/AbstractType.d.ts:41

Inherited from ​

AbstractType._eH


_item ​

_item: null | Item

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/AbstractType.d.ts:23

Inherited from ​

AbstractType._item


_length ​

_length: number

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/AbstractType.d.ts:36

Inherited from ​

AbstractType._length


_map ​

_map: Map< string, Item >

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/AbstractType.d.ts:27

Inherited from ​

AbstractType._map


_prelimContent ​

private _prelimContent: any

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/YArray.d.ts:34


_searchMarker ​

_searchMarker: ArraySearchMarker[]

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/YArray.d.ts:38

Overrides ​

AbstractType._searchMarker


_start ​

_start: null | Item

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/AbstractType.d.ts:31

Inherited from ​

AbstractType._start


doc ​

doc: null | Doc

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/AbstractType.d.ts:35

Inherited from ​

AbstractType.doc

Accessors ​

_first ​

get _first(): null | Item

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/AbstractType.d.ts:81

Inherited from ​

AbstractType._first


length ​

get length(): number

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/YArray.d.ts:58


parent ​

get parent(): null | AbstractType< any >

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/AbstractType.d.ts:54

Inherited from ​

AbstractType.parent

Methods ​

[iterator] ​

[iterator](): IterableIterator< T >

Returns ​

IterableIterator< T >

Implementation of ​

Iterable.[iterator]

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/YArray.d.ts:143


_callObserver ​

_callObserver(transaction, _parentSubs): void

Creates YEvent and calls all type observers. Must be implemented by each type.

Parameters ​

ParameterTypeDescription
transactionTransaction-
_parentSubsSet< null | string >Keys changed on this type. null if list was modified.

Returns ​

void

Inherited from ​

AbstractType._callObserver

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/AbstractType.d.ts:89


_copy ​

_copy(): Array< T >

Returns ​

Array< T >

Overrides ​

AbstractType._copy

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/YArray.d.ts:53


_integrate ​

_integrate(y, item): void

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 ​

ParameterTypeDescription
yDocThe Yjs instance
itemItem-

Returns ​

void

Overrides ​

AbstractType._integrate

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/YArray.d.ts:49


_write ​

_write(_encoder): void

Parameters ​

ParameterType
_encoderUpdateEncoderV1 | UpdateEncoderV2

Returns ​

void

Inherited from ​

AbstractType._write

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/AbstractType.d.ts:77


clone ​

clone(): Array< T >

Returns ​

Array< T >

Overrides ​

AbstractType.clone

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/YArray.d.ts:57


delete ​

delete(index, length?): void

Deletes elements starting from an index.

Parameters ​

ParameterTypeDescription
indexnumberIndex at which to start deleting elements
length?numberThe number of elements to remove. Defaults to 1.

Returns ​

void

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/YArray.d.ts:96


forEach ​

forEach(f): void

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

Parameters ​

ParameterTypeDescription
ffunctionA function to execute on every element of this YArray.

Returns ​

void

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/YArray.d.ts:139


get ​

get(index): T

Returns the i-th element from a YArray.

Parameters ​

ParameterTypeDescription
indexnumberThe index of the element to return from the YArray

Returns ​

T

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/YArray.d.ts:103


insert ​

insert(index, content): void

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 ​

ParameterTypeDescription
indexnumberThe index to insert content at.
contentT[]The array of content

Returns ​

void

Example ​

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

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/YArray.d.ts:75


map ​

map<M>(f): M[]

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

Type parameters ​

Parameter
M

Parameters ​

ParameterTypeDescription
ffunctionFunction that produces an element of the new Array

Returns ​

M[]

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

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/YArray.d.ts:133


observe ​

observe(f): void

Observe all events that are created on this type.

Parameters ​

ParameterTypeDescription
ffunctionObserver function

Returns ​

void

Inherited from ​

AbstractType.observe

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/AbstractType.d.ts:95


observeDeep ​

observeDeep(f): void

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

Parameters ​

ParameterTypeDescription
ffunctionObserver function

Returns ​

void

Inherited from ​

AbstractType.observeDeep

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/AbstractType.d.ts:101


push ​

push(content): void

Appends content to this YArray.

Parameters ​

ParameterTypeDescription
contentT[]Array of content to append.

Returns ​

void

Todo ​

Use the following implementation in all types.

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/YArray.d.ts:83


slice ​

slice(start?, end?): T[]

Transforms this YArray to a JavaScript Array.

Parameters ​

ParameterType
start?number
end?number

Returns ​

T[]

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/YArray.d.ts:117


toArray ​

toArray(): T[]

Transforms this YArray to a JavaScript Array.

Returns ​

T[]

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/YArray.d.ts:109


toJSON ​

toJSON(): any[]

Transforms this Shared Type to a JSON object.

Returns ​

any[]

Overrides ​

AbstractType.toJSON

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/YArray.d.ts:123


unobserve ​

unobserve(f): void

Unregister an observer function.

Parameters ​

ParameterTypeDescription
ffunctionObserver function

Returns ​

void

Inherited from ​

AbstractType.unobserve

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/AbstractType.d.ts:107


unobserveDeep ​

unobserveDeep(f): void

Unregister an observer function.

Parameters ​

ParameterTypeDescription
ffunctionObserver function

Returns ​

void

Inherited from ​

AbstractType.unobserveDeep

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/AbstractType.d.ts:113


unshift ​

unshift(content): void

Preppends content to this YArray.

Parameters ​

ParameterTypeDescription
contentT[]Array of content to preppend.

Returns ​

void

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/YArray.d.ts:89


from ​

static from<T_1>(items): Array< T_1 >

Construct a new YArray containing the specified items.

Type parameters ​

Parameter
T_1 extends null | string | number | any[] | Uint8Array | {}

Parameters ​

ParameterType
itemsT_1[]

Returns ​

Array< T_1 >

Defined In ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/types/YArray.d.ts:27