Class ObservableMap<TKey, TVal>

A Map where the state and values can be observed

Type Parameters

  • TKey
  • TVal

Implements

Constructors

Properties

empty$: Observable<boolean>

An observable emitting true if the collection is empty

itemAdded$: Observable<ObservableMapItem<TKey, TVal>>

Emits for every item that is added to the map

itemDelta$: Observable<ObservableMapItemChange<TKey, TVal>>

Emits for every item that is added/removed in the list, including the changes from an empty map to the current state

itemRemoved$: Observable<ObservableMapItem<TKey, TVal>>

Emits for every item that is removed from the map

itemUpdates$: Observable<ObservableMapItemChange<TKey, TVal>>

Emits for every item that is added/removed in the map

size$: Observable<number>

An observable emitting the number of items in the collection

updates$: Observable<ReadonlyMap<TKey, TVal>>

Emits all updates to the map

value$: Observable<ReadonlyMap<TKey, TVal>>

An observable emitting the inner non-observable map

Accessors

Methods

  • Add a value to the collection if the key is not in use

    Parameters

    • key: TKey

      The key to use

    • value: TVal

      The value to add

    Returns boolean

    added - Returns true if the value was added

  • Remove a key from the collection

    Parameters

    • key: TKey

      The key to remove

    Returns boolean

    removed - True if an item was removed

  • Remove keys from the collection

    Parameters

    • values: TKey[]

      The keys to remove

    Returns boolean

    removed - True if items were removed

  • Remove all keys not in the whitelist

    Parameters

    • whitelist: undefined | readonly TKey[] | ReadonlySet<TKey>

      The keys to keep

    Returns boolean

  • Add a value to the collection

    Parameters

    • key: TKey

      The key to use

    • value: TVal

      The value to add

    Returns boolean

    added - Returns true if the value was added or changed

  • Toggle a value in the map

    Parameters

    • key: TKey

      The key to toggle

    • value: TVal

      The value to insert if applicable

    • Optionalstate: boolean

      A forced state (true = always add, false = always delete)

    Returns undefined | boolean

    The applied change (true = item added, false = item removed, undefined = nothing changed)