@embra/reactivity - v0.0.7
    Preparing search index...

    Interface ReadonlyReactiveMap<K, V>

    ReadonlyReactiveMap is a readonly interface for ReactiveMap.

    interface ReadonlyReactiveMap<K, V> {
        $: Readable<ReadonlyMap<K, V>>;
        onDisposeValue: (fn: (value: V) => void) => RemoveListener;
        onChanged(fn: (changed: ReactiveMapChanged<K, V>) => void): RemoveListener;
    }

    Type Parameters

    • K
    • V

    Hierarchy

    • ReadonlyMap<K, V>
      • ReadonlyReactiveMap
    Index

    Readable

    $: Readable<ReadonlyMap<K, V>>

    A Readable that emits the Map itself whenever it changes.

    Events

    onDisposeValue: (fn: (value: V) => void) => RemoveListener

    Subscribe to events when a value is needed to be disposed.

    A value is considered for disposal when:

    • it is deleted from the map.
    • it is replaced by another value (the old value is removed).
    • it is cleared from the map.
    • the map is disposed.

    Note that for performance reasons, it does not handle the case where multiple keys map to the same value.

    Type Declaration

      • (fn: (value: V) => void): RemoveListener
      • Parameters

        • fn: (value: V) => void

          The function to call when a value is needed to be disposed.

        Returns RemoveListener

        A disposer function to unsubscribe from the event.

    import { reactiveMap } from "@embra/reactivity";

    const map = reactiveMap<number, string>();
    const disposer = map.onDisposeValue((value) => {
    console.log("Value disposed:", value);
    });
    • Subscribe to changes in the map.

      Parameters

      Returns RemoveListener

      A disposer function to unsubscribe from the event.

      import { reactiveMap } from "@embra/reactivity";

      const map = reactiveMap<number, string>();
      const disposer = map.onChanged((changed) => {
      console.log("Map changed:", changed);
      });