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

    Interface OwnedReactiveMap<K, V>

    OwnedReactiveMap extends the standard Map interface with reactive capabilities.

    interface OwnedReactiveMap<K, V> {
        onDisposeValue: <V>(
            this: { onDisposeValue_?: OnDisposeValue<V> | null },
            fn: (value: V) => void,
        ) => RemoveListener;
        get $(): Readable<ReadonlyReactiveMap<K, V>>;
        clear(): void;
        delete(key: K): boolean;
        dispose(): void;
        onChanged(fn: (changed: ReactiveMapChanged<K, V>) => void): RemoveListener;
        rename(key: K, newKey: K): void;
        replace(entries: Iterable<readonly [K, V]>): this;
        set(key: K, value: V): this;
    }

    Type Parameters

    • K
    • V

    Hierarchy

    • Map<K, V>
      • OwnedReactiveMap

    Implements

    Index

    Readable

    Events

    onDisposeValue: <V>(
        this: { onDisposeValue_?: OnDisposeValue<V> | null },
        fn: (value: V) => void,
    ) => RemoveListener = onDisposeValue

    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

      • <V>(
            this: { onDisposeValue_?: OnDisposeValue<V> | null },
            fn: (value: V) => void,
        ): RemoveListener
      • Type Parameters

        • V

        Parameters

        • this: { onDisposeValue_?: OnDisposeValue<V> | null }
        • 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);
      });

    Methods

    • Parameters

      • key: K

      Returns boolean

      true if an element in the Map existed and has been removed, or false if the element does not exist.

    • Replace the contents of the map with the given entries.

      Parameters

      • entries: Iterable<readonly [K, V]>

        The new entries to replace the map with.

      Returns this

      The map itself.

    • Adds a new element with a specified key and value to the Map. If an element with the same key already exists, the element will be updated.

      Parameters

      • key: K
      • value: V

      Returns this