@embra/reactivity - v0.0.7
    Preparing search index...

    Interface OwnedReactiveArray<V>

    OwnedReactiveArray extends the standard Array interface with reactive capabilities.

    interface OwnedReactiveArray<V> {
        length: number;
        onDisposeValue: (fn: (value: V) => void) => RemoveListener;
        get $(): Readable<ReadonlyReactiveArray<V>>;
        copyWithin(target: number, start: number, end?: number): this;
        dispose(): void;
        fill(value: V, start?: number, end?: number): this;
        pop(): V | undefined;
        push(...items: V[]): number;
        replace(items: Iterable<V>): this;
        reverse(): this;
        set(index: number, value: V): this;
        setLength(value: number): void;
        shift(): V | undefined;
        sort(compareFn?: (a: V, b: V) => number): this;
        splice(start: number, deleteCount?: number): V[];
        splice(start: number, deleteCount: number, ...items: V[]): V[];
        unshift(...items: V[]): number;
        readonly [n: number]: V;
    }

    Type Parameters

    • V

    Hierarchy

    • Array<V>
      • OwnedReactiveArray

    Implements

    Indexable

    • readonly [n: number]: V
    Index

    Readable

    Events

    onDisposeValue: (fn: (value: V) => void) => RemoveListener = onDisposeValue

    Subscribe to events when a value is needed to be disposed.

    A value is considered for disposal when:

    • it is deleted from the array.
    • it is replaced by another value (the old value is removed).
    • it is cleared from the array.
    • the array is disposed.

    Type Declaration

      • (fn: (value: V) => void): RemoveListener
      • Parameters

        • fn: (value: V) => void

          The function to call when a value is needed to be disposed.

        Returns RemoveListener

        A disposer function to unsubscribe from the event.

    import { reactiveArray } from "@embra/reactivity";

    const arr = reactiveArray<number>();
    const disposer = arr.onDisposeValue((value) => {
    console.log("Value disposed:", value);
    });

    Properties

    length: number

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

    Use .setLength(length) to change the length of the array.

    Methods

    • Returns the this object after copying a section of the array identified by start and end to the same array starting at position target

      Parameters

      • target: number

        If target is negative, it is treated as length+target where length is the length of the array.

      • start: number

        If start is negative, it is treated as length+start. If end is negative, it is treated as length+end.

      • Optionalend: number

        If not specified, length of the this object is used as its default value.

      Returns this

    • Changes all array elements from start to end index to a static value and returns the modified array

      Parameters

      • value: V

        value to fill array section with

      • Optionalstart: number

        index to start filling the array at. If start is negative, it is treated as length+start where length is the length of the array.

      • Optionalend: number

        index to stop filling the array at. If end is negative, it is treated as length+end.

      Returns this

    • Removes the last element from an array and returns it. If the array is empty, undefined is returned and the array is not modified.

      Returns V | undefined

    • Appends new elements to the end of an array, and returns the new length of the array.

      Parameters

      • ...items: V[]

        New elements to add to the array.

      Returns number

    • Replaces the contents of the array with the provided items.

      Parameters

      • items: Iterable<V>

        The new items to replace the contents of the array with.

      Returns this

      The array itself.

    • Reverses the elements in an array in place. This method mutates the array and returns a reference to the same array.

      Returns this

    • Overwrites the value at the provided index with the given value. If the index is negative, then it replaces from the end of the array.

      Parameters

      • index: number

        The index of the value to overwrite. If the index is negative, then it replaces from the end of the array.

      • value: V

        The value to write into the array.

      Returns this

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

      Returns V | undefined

    • Sorts an array in place. This method mutates the array and returns a reference to the same array.

      Parameters

      • OptionalcompareFn: (a: V, b: V) => 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, UTF-16 code unit order.

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

      Returns this

    • 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.

      • OptionaldeleteCount: number

        The number of elements to remove. Omitting this argument will remove all elements from the start paramater location to end of the array. If value of this argument is either a negative number, zero, undefined, or a type that cannot be converted to an integer, the function will evaluate the argument as zero and not remove any elements.

      Returns V[]

      An array containing the elements that were deleted.

    • 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.

      • deleteCount: number

        The number of elements to remove. If value of this argument is either a negative number, zero, undefined, or a type that cannot be converted to an integer, the function will evaluate the argument as zero and not remove any elements.

      • ...items: V[]

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

      Returns V[]

      An array containing the elements that were deleted.

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

      Parameters

      • ...items: V[]

        Elements to insert at the start of the array.

      Returns number