@metreeca/core - v0.9.22
    Preparing search index...

    Type Alias Scope<T>

    Unique value allocator.

    Hands out unique sequential ids, each returned as a value of type T derived from it and cached against an optional composite key whose components are matched by reference identity (SameValueZero). A keyed call returns the cached value on a repeat hit (the same reference when T is an object); an unkeyed call always allocates a fresh anonymous id. Keyed and anonymous allocations share one monotonic counter, so every id is unique within the scope.

    Important

    Keys match component-wise by reference, not structure: two equal-looking object literals are unique keys. This is what keeps values consistent across multi-pass operations: every pass that revisits the same node resolves to the same value. Callers wanting coordinated values must thread the one node object through every pass, never rebuild an equal-looking key.

    type Scope<T = number> = {
        resolve(...keys: readonly unknown[]): T;
    }

    Type Parameters

    • T = number

      The value handed out per allocation, derived from each numeric id; defaults to number

    Index

    Methods

    Methods

    • Resolves the value bound to the given key, allocating it on first lookup.

      Several arguments form a composite key: the value is shared only when every component matches by reference identity, in the same order. Omitting all arguments allocates a fresh anonymous value.

      Parameters

      • ...keys: readonly unknown[]

        Key components matched by reference identity; omit to allocate a fresh anonymous value

      Returns T

      The value cached for keys, allocated on first lookup and returned unchanged thereafter; a freshly allocated value when no components are supplied