Class CellArray<TItem>

A dynamic array of mutable cells.

Type Parameters

  • TItem

Hierarchy (view full)

Constructors

Properties

_onInsert: MutEmitter<{
    index: number;
    item: Cell<TItem>;
}> = ...

Type declaration

_onRemove: MutEmitter<number> = ...
cells: MutCell<MutCell<TItem>[]> = ...
initialItems: Iterable<TItem>

The initial items of the array.

length: Cell<number> = ...

The number of items in the array.

onInsert: Emitter<{
    index: number;
    item: Cell<TItem>;
}> = ...

An emitter that emits events when items are inserted.

Type declaration

onRemove: Emitter<number> = ...

An emitter that emits events when items are removed.

Accessors

  • get indexed(): CellStream<TItem, Cell<number>>
  • Create a stream that assigns an index, starting at 0, to eachitem in this stream. The indices are cells that will update when items are removed.

    Returns CellStream<TItem, Cell<number>>

    A new stream.

Methods

  • Create a stream that only includes items from this stream for which the given predicate function returns true.

    Parameters

    • f: ((item) => boolean)

      The predicate function to apply to items.

        • (item): boolean
        • Parameters

          Returns boolean

    Returns CellStream<TItem, void>

    A new stream.

  • Find an item matching the predicate.

    Parameters

    • predicate: ((item, index) => boolean)

      A function to apply to each item.

        • (item, index): boolean
        • Parameters

          Returns boolean

    Returns undefined | MutCell<TItem>

    The mutable cell of the first item matching the predicate or undefined if not found.

  • Get the current cell value at the given index.

    Parameters

    • index: number

      The index.

    Returns undefined | TItem

    The item or undefined if out of bounds.

  • Insert an item.

    Parameters

    • index: number

      The index to insert the item at. Existing items will be moved over.

    • item: TItem

      The item to insert.

    Returns void

  • Observe this iterable. Upon attaching an observer insert is called for each item currently contained in the underlying collection.

    Parameters

    • insert: ((index, item, key) => void)

      An observer that is called whenever an item is inserted.

        • (index, item, key): void
        • Parameters

          Returns void

    • remove: ((index) => void)

      An observer that is called whenever an item is removed.

        • (index): void
        • Parameters

          • index: number

          Returns void

    Returns (() => void)

    A function that should be called to detach the observer functions.

      • (): void
      • Returns void

  • Add an item to the end of the array increasing its length by one.

    When inserting items the order of events is as follows:

    1. The item is inserted in the internal array of cells
    2. An insertion event is emitted to active iterators
    3. The length cell emits an update to observers

    Parameters

    • item: TItem

      The item to add to the end of the array

    Returns void

  • Parameters

    • predicate: ((item, index) => boolean)
        • (item, index): boolean
        • Parameters

          Returns boolean

    Returns void

  • Parameters

    • items: TItem[]
    • Optional predicate: ((existingItem, newItem) => boolean)
        • (existingItem, newItem): boolean
        • Parameters

          Returns boolean

    Returns void

  • Set the value of the cell at the given index.

    Parameters

    • index: number

      The index.

    • item: TItem

      The new cell value.

    Returns void

  • Update the value of the cell at the given index.

    Type Parameters

    • T

    Parameters

    • index: number

      The index.

    • mutator: ((value) => T)

      A function that modifies the value of the cell.

        • (value): T
        • Parameters

          Returns T

    Returns undefined | T

    If the mutator function returns a value, that value is returned by update as well.