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

    Interface OwnedReactiveSet<V>

    OwnedReactiveSet extends the standard Set interface with reactive capabilities.

    interface OwnedReactiveSet<V> {
        onDisposeValue: <V>(
            this: { onDisposeValue_?: OnDisposeValue<V> | null },
            fn: (value: V) => void,
        ) => RemoveListener;
        get $(): Readable<ReadonlyReactiveSet<V>>;
        add(value: V): this;
        clear(): void;
        delete(value: V): boolean;
        dispose(): void;
        onChanged(fn: (changed: ReactiveSetChanged<V>) => void): RemoveListener;
        replace(values: Iterable<V>): this;
    }

    Type Parameters

    • V

    Hierarchy

    • Set<V>
      • OwnedReactiveSet

    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 set.
    • it is replaced by another value (the old value is removed).
    • it is cleared from the set.
    • the set is disposed.

    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 { reactiveSet } from "@embra/reactivity";

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

      Parameters

      Returns RemoveListener

      A disposer function to unsubscribe from the event.

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

      const set = reactiveSet<number>();
      const disposer = set.onChanged((changed) => {
      console.log("Set changed:", changed);
      });

    Methods

    • Appends a new element with a specified value to the end of the Set.

      Parameters

      • value: V

      Returns this

    • Removes a specified value from the Set.

      Parameters

      • value: V

      Returns boolean

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

    • Replace the contents of the set with the given values.

      Parameters

      • values: Iterable<V>

        The new values to replace the set with.

      Returns this

      The set itself.