gradum-kit - v0.1.0
    Preparing search index...

    Class GradumWeakSet<Type>

    GradumWeakSet

    A set that holds its members weakly, so membership never keeps an object alive. Unlike a native WeakSet, it is iterable and reports its size — collected objects simply disappear from both. Useful for tracking DOM nodes without leaking them once they are removed.

    Type Parameters

    • Type extends object = object

      The type of the held objects.

    Index
    • Type Parameters

      • Type extends object = object

        The type of the held objects.

      Returns GradumWeakSet<Type>

      Create an empty set.

    • get size(): number

      Returns number

      The number of objects still alive. Counted on each read rather than stored, so it costs a full pass over the set.

    • Parameters

      • obj: Type

        The object to add.

      Returns this

      Itself, allowing for method chaining.

      Add an object to the set, if not already present. The set does not keep it alive.

    • Parameters

      • obj: Type

        The object to look for, compared by identity.

      Returns boolean

      Whether the object is present and has not been garbage-collected.

      Check whether an object is in the set.

    • Parameters

      • obj: Type

        The object to remove, compared by identity.

      Returns boolean

      Whether a matching object was found and removed.

      Remove an object from the set.

    • Returns void

      Drop the bookkeeping left behind by objects that have been garbage-collected. Only frees the set's own references — collected objects are already absent from iteration and size without it.

    • Returns Type[]

      A new array of the live objects, in insertion order.

      Snapshot the objects that are still alive.

    • Returns void

      Remove every object from the set.

    • Parameters

      • callback: (value: Type, set: this) => void

        Called once per live object.

      • OptionalthisArg: any

        Value to bind as this inside the callback.

      Returns void

      Run a callback for each live object, in insertion order. Objects collected since the last pass are skipped.

    • Returns IterableIterator<Type>

      Iterate the live objects in insertion order, skipping any that have been collected.