Class ReadonlyArraySignal<T>

Readonly wrapper for an array signal.

Type Parameters

  • T

Hierarchy (View Summary)

Implements

  • RelativeIndexable<T>

Constructors

Methods

  • Returns the element at the given index.

    Parameters

    • index: number

      The array index.

    Returns undefined | T

    The element at the given index, or undefined if none.

  • Returns ArrayIterator<[number, T]>

    An iterable of key/value pairs for every entry in the array.

  • Type Parameters

    • S

    Parameters

    • predicate: (value: T, index: number, array: readonly T[]) => value is S
    • OptionalthisArg: unknown

    Returns this is readonly S[]

  • Parameters

    • predicate: (value: T, index: number, array: readonly T[]) => unknown
    • OptionalthisArg: unknown

    Returns boolean

  • Type Parameters

    • S

    Parameters

    • predicate: (value: T, index: number, array: readonly T[]) => value is S
    • OptionalthisArg: unknown

    Returns S[]

  • Parameters

    • predicate: (value: T, index: number, array: readonly T[]) => unknown
    • OptionalthisArg: unknown

    Returns T[]

  • Type Parameters

    • S

    Parameters

    • predicate: (value: T, index: number, obj: readonly T[]) => value is S
    • OptionalthisArg: unknown

    Returns undefined | S

  • Parameters

    • predicate: (value: T, index: number, obj: readonly T[]) => boolean
    • OptionalthisArg: unknown

    Returns undefined | T

  • Returns the index of the first element in the array where predicate is true, and -1 otherwise.

    Parameters

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

      Called once for each element of the array, in ascending order, until it finds one where predicate returns true. If such an element is found, findIndex immediately returns that element index. Otherwise, findIndex returns -1.

    • OptionalthisArg: unknown

      Optional object to which the this keyword can refer in the predicate function. Defaults to undefined.

    Returns number

    The index of the first found element or -1 if none.

  • Calls the given callback function on each element of the array to map the array element to something different. Then flattens the result into a new array. This is identical to a map followed by flat with depth 1.

    Type Parameters

    • U
    • This = undefined

    Parameters

    • callback: (this: This, value: T, index: number, array: T[]) => U | readonly U[]

      A function that accepts up to three arguments (value, index, array). Called one time for each element in the array. Must return the mapped value.

    • OptionalthisArg: This

      Optional object to which the this keyword can refer in the callback function. Defaults to undefined.

    Returns U[]

    New array with mapped and flattened valued.

  • Performs the specified action for each element in the array.

    Parameters

    • callback: (value: T, index: number, array: readonly T[]) => void

      A function that accepts up to three arguments (value, index and the array itself). Called one time for each element in the array.

    • OptionalthisArg: unknown

      Optional object to which the this keyword can refer in the callback function. Defaults to undefined.

    Returns void

  • Returns the current signal value version. This value is used to determine if a dependency has changed. The most simple implementation would be a number which is incremented every time the signal value really has changed. The version type doesn't matter but must be comparable with ===.

    Returns unknown

    The current signal value version.

  • Determines whether an array includes a certain element, returning true or false as appropriate.

    Parameters

    • searchElement: T

      The element to search for.

    • OptionalfromIndex: number

      Optional position in this array at which to begin searching. Defaults to 0.

    Returns boolean

    True if array includes the element, false if not.

  • Returns the index of the first occurrence of an element in the array.

    Parameters

    • searchElement: T

      The element to locate in the array.

    • OptionalfromIndex: number

      The array index at which to begin the search. If omitted, the search starts at index 0.

    Returns number

    The index of the first occurrence of the given element, or -1 if not found.

  • Checks if signal value is still valid. When signal has no dependencies then this method can always return true. If signal has dependencies then it must check if any dependency has changed or became invalid. If yes, then this method must return false and the signal will be re-validated by calling (). If all dependency are valid/unchanged then this method must return true to indicate that the signal value is still valid.

    Returns boolean

    True if signal value is valid, false if it must be re-validated.

  • Adds all the elements of the array separated by the specified separator string.

    Parameters

    • Optionalseparator: string

      A string used to separate one element of an array from the next in the resulting string. If omitted, the array elements are separated with a comma.

    Returns string

    The joined string.

  • Returns the index of the last occurrence of an element in the array.

    Parameters

    • searchElement: T

      The element to locate in the array.

    • fromIndex: number = -1

      The array index at which to begin the search. If omitted, the search starts at the last index in the array.

    Returns number

    The index of the last occurrence of the given element, or -1 if not found.

  • Calls a defined callback function on each element of the array and returns an array that contains the results.

    Type Parameters

    • U

    Parameters

    • callback: (value: T, index: number, array: readonly T[]) => U

      A function that accepts up to three arguments (value, index and the array itself) and returns the mapped value for the array element. Called one time for each element in the array.

    • OptionalthisArg: unknown

      Optional object to which the this keyword can refer in the callback function. Defaults to undefined.

    Returns U[]

    A new array with the mapped elements.

  • Type Parameters

    • U

    Parameters

    • callback: (
          previousValue: U,
          currentValue: T,
          currentIndex: number,
          array: readonly T[],
      ) => U
    • initialValue: U

    Returns U

  • Parameters

    • callback: (
          previousValue: T,
          currentValue: T,
          currentIndex: number,
          array: readonly T[],
      ) => T
    • OptionalinitialValue: T

    Returns T

  • Type Parameters

    • U

    Parameters

    • callback: (
          previousValue: U,
          currentValue: T,
          currentIndex: number,
          array: readonly T[],
      ) => U
    • initialValue: U

    Returns U

  • Parameters

    • callback: (
          previousValue: T,
          currentValue: T,
          currentIndex: number,
          array: readonly T[],
      ) => T
    • OptionalinitialValue: T

    Returns T

  • Returns a section of the array.

    Parameters

    • Optionalstart: number

      The beginning of the specified portion of the array.

    • Optionalend: number

      Optional end of the specified portion of the array. This is exclusive of the element at the index 'end'. Defaults to the array length if not specified.

    Returns T[]

    The sliced section of the array.

  • Determines whether the specified callback function returns true for any element of the array.

    Parameters

    • predicate: (value: T, index: number, array: readonly T[]) => boolean

      A function that accepts up to three arguments (value, index and the array itself). Called for each element in the array until the predicate returns a value which is coercible to the Boolean value true, or until the end of the array.

    • OptionalthisArg: unknown

      Optional object to which the this keyword can refer in the predicate function. Defaults to undefined.

    Returns boolean

    True if at least one element satisfies the specified test, false if none does.

  • Subscribes the given observer to this object.

    Parameters

    • observer: Observer<readonly T[]> | (next: readonly T[]) => void

      The observer to subscribe.

    Returns Unsubscribable

    Object which can be used to unsubscribe the observer.

  • Called when () returned false and the current value of this signal is needed. Must compute/fetch and cache the new value so the next call to () returns a valid value. When signal has no dependencies and () is implemented to always return true then this method can stay empty as it has nothing to validate/update.

    Returns void