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

    Interface ReadonlyReactiveArray<V>

    ReadonlyReactiveArray is a readonly interface for ReactiveArray.

    interface ReadonlyReactiveArray<V> {
        $: Readable<readonly V[]>;
        length: number;
        onDisposeValue: (fn: (value: V) => void) => RemoveListener;
        set(index: number, value: V): this;
        setLength(value: number): void;
        readonly [n: number]: V;
    }

    Type Parameters

    • V

    Hierarchy

    • ReadonlyArray<V>
      • ReadonlyReactiveArray

    Indexable

    • readonly [n: number]: V
    Index

    Readable

    Events

    Properties

    Methods

    Readable

    $: Readable<readonly V[]>

    A Readable that emits the Array itself whenever it changes.

    Events

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

    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

    • 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