@bodil/signal
    Preparing search index...

    Class Array<A>

    An array which behaves like a signal.

    Any read operation on the array, like Signal.Array.get, Signal.Array.size, or iteration, acts like a Signal.State.get, registering the array as a dependency in any computed signals or effects it's used in. Correspondingly, any write operation to the array will cause all of these dependencies to update as with a Signal.State.set.

    Note that the API of this array is different from the built-in Array. This is intentional. Additionally, many operations you'd expect to find on an array, like Array.map or predicates like Array.every, are missing from the array itself. It's recommended that you access these through Iterators instead.

    Note also that array access doesn't come with any granularity: if you read only a single index from the array inside a computed signal, any change to the array causes the signal to recompute, regardless of whether the value at the index you read changed.

    Type Parameters

    • A

    Hierarchy (View Summary)

    Constructors

    • Construct a new array, optionally filling it with the contents of the provided iterable.

      Type Parameters

      • A

      Parameters

      Returns Array<A>

    Methods

    • Discard all values in the array, leaving an empty array.

      Returns this

    • Find the first index in the array for which the predicate function returns true for the value at that index, or -1 if it never does.

      Parameters

      • predicate: (value: A, index: number, obj: A[]) => boolean
      • OptionalthisArg: any

      Returns number

    • Find the index at which the given value first occurs in the array, optionally starting at fromIndex. If the value doesn't occur in the array, return -1.

      Parameters

      • value: A
      • OptionalfromIndex: number

      Returns number

    • Insert the given values starting at the given index, shifting the remainder of the array to higher indices accordingly.

      Parameters

      • index: number
      • ...values: A[]

      Returns this

      TypeError if index is not an integer

    • Append the provided values to the end of the array.

      Parameters

      • ...values: A[]

      Returns number

      the number of values that were inserted.

    • Remove the first occurrence of the given value from the array, if it exists in the array.

      Parameters

      • value: A

      Returns Option<A>

    • Remove the first value from the array that matches the given predicate function, if any.

      Parameters

      • predicate: (value: A, index: number, obj: A[]) => boolean

      Returns Option<A>

    • Remove the value at the given index and return it. If there's no value at the given index, return None.

      Parameters

      • index: number

      Returns Option<A>

      TypeError if index is not an integer

    • Replace the contents of this array with the values contained in iterable.

      Parameters

      Returns this

    • Write the given value to the given index of the array, overwriting anything that may have been there before.

      Parameters

      • index: number
      • value: A

      Returns this

      TypeError if index is negative or not an integer

    • Parameters

      • start: number
      • OptionaldeleteCount: number
      • ...values: A[]

      Returns A[]

    • Prepend the provided values to the start of the array.

      Parameters

      • ...values: A[]

      Returns number

      the number of values that were inserted.