cytoplasmic
    Preparing search index...

    Class CellArray<TItem>

    A dynamic array of mutable cells.

    Type Parameters

    • TItem

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    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.

    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

    • Find an item matching the predicate.

      Parameters

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

        A function to apply to each item.

      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: number, item: Cell<TItem>, key: void) => void

        An observer that is called whenever an item is inserted.

      • remove: (index: number) => void

        An observer that is called whenever an item is removed.

      Returns () => void

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

    • 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: TItem, index: number) => boolean

      Returns void

    • Parameters

      • items: TItem[]
      • Optionalpredicate: (existingItem: TItem, newItem: TItem) => 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: TItem) => T

        A function that modifies the value of the cell.

      Returns undefined | T

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