Interface ReactiveList<TValue>

A reactive list. Similar to an Array except bracket-notation(e.g. arr[0]) is not allowed to get/set elements. Changes to the list will be notified to subscribers of list.$.

interface ReactiveList<TValue> {
    $: ReadonlyVal<readonly TValue[]>;
    array: readonly TValue[];
    length: number;
    [iterator](): IterableIterator<TValue>;
    batchSet(entries): this;
    clear(): this;
    delete(index, count?): void;
    dispose(): void;
    entries(): IterableIterator<[number, TValue]>;
    first(): undefined | TValue;
    get(index): undefined | TValue;
    insert(index, ...items): void;
    keys(): IterableIterator<number>;
    last(): undefined | TValue;
    pop(): undefined | TValue;
    popHead(): undefined | TValue;
    push(...items): void;
    pushHead(...items): void;
    replace(items): Iterable<TValue>;
    reverse(): this;
    set(index, item): this;
    setLength(len): void;
    sort(compareFn?): this;
    splice(start, deleteCount?): TValue[];
    splice(start, deleteCount, ...items): TValue[];
    toJSON(): readonly TValue[];
    toLocaleString(): string;
    toString(): string;
    values(): IterableIterator<TValue>;
}

Type Parameters

  • TValue

Properties

$: ReadonlyVal<readonly TValue[]>

A readonly val with value of the internal readonly array.

To update the entire array in place, use list.replace().

array: readonly TValue[]

Get the internal array. Use it as a read-only array. Should not modify the array in place directly. Use methods on the list instead.

length: number

Gets the length of the array. This is a number one higher than the highest index in the array.

Methods

  • Sets new items to the list at specific index in place of the existing items.

    Parameters

    • entries: Iterable<readonly [number, TValue]>

      An iterable object that contains key-value pairs.

    Returns this

    this

  • Removes elements from the list starting from the specified index.

    Parameters

    • index: number

      The zero-based location in the list from which to start deleting elements. A negative index will be ignored.

    • Optional count: number

      The number of elements to remove. Default 1.

    Returns void

  • Returns IterableIterator<[number, TValue]>

    See

    Array#entries Returns an iterable of key, value pairs for every entry in the list.

  • Same as array[index]. Returns the item located at the specified index.

    Parameters

    • index: number

      The zero-based index of the desired code unit. A negative index will be ignored.

    Returns undefined | TValue

  • Inserts new elements to the list. Pushes existing elements to the right.

    Parameters

    • index: number

      The zero-based location in the list from which to start inserting elements. A negative index will be ignored.

    • Rest ...items: TValue[]

      Elements to insert into the list.

    Returns void

  • Returns IterableIterator<number>

    See

    Array#keys Returns an iterable of keys in the list.

  • Returns undefined | TValue

    See

    Array#pop Removes the last element from the list and returns it. If the list is empty, undefined is returned and the list is not modified.

  • Removes the first element from the list and returns it. If the list is empty, undefined is returned and the list is not modified.

    Returns undefined | TValue

    See

    Array#shift

  • Parameters

    • Rest ...items: TValue[]

      New elements to add to the list.

    Returns void

    See

    Array#push Appends new elements to the end of the list, and returns the new length of the list.

  • Inserts new elements at the start of the list, and returns the new length of the list.

    Parameters

    • Rest ...items: TValue[]

      Elements to insert at the start of the list.

    Returns void

    See

    Array#unshift

  • Sets new item to the list at specific index in place of the existing item.

    Parameters

    • index: number

      The zero-based location in the list at which to insert item. A negative index will be ignored.

    • item: TValue

      Item to set to the list.

    Returns this

    this

  • Sets the length of the array.

    Parameters

    • len: number

      A number one higher than the highest index in the array.

    Returns void

  • Parameters

    • Optional compareFn: ((a, b) => number)

      Function used to determine the order of the elements. It is expected to return a negative value if the first argument is less than the second argument, zero if they're equal, and a positive value otherwise. If omitted, the elements are sorted in ascending, ASCII character order.

      [11,2,22,1].sort((a, b) => a - b)
      

    Returns this

    See

    Array#sort Sorts the list in place.

  • Same as Array.prototype.splice. Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.

    Parameters

    • start: number

      The zero-based location in the array from which to start removing elements. A negative index will be ignored.

    • Optional deleteCount: number

      The number of elements to remove.

    Returns TValue[]

    An array containing the elements that were deleted.

  • Same as Array.prototype.splice. Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.

    Parameters

    • start: number

      The zero-based location in the array from which to start removing elements. A negative index will be ignored.

    • deleteCount: number

      The number of elements to remove.

    • Rest ...items: TValue[]

      Elements to insert into the array in place of the deleted elements.

    Returns TValue[]

    An array containing the elements that were deleted.

  • Returns string

    See

    Array#toLocaleString Returns a string representation of the list. The elements are converted to string using their toLocaleString methods.