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

    Module scope

    Identity-keyed value allocation.

    Provides Scope, a counter that hands out unique sequential ids. Each id is cached against a caller-supplied key, compared by reference identity, so repeated lookups of the same key resolve to the same value without a string proxy.

    By default createScope builds a scope handing out raw numeric ids; given a mapper, each id is passed through it to produce the value returned instead.

    import { createScope } from '@metreeca/core/scope';

    const scope = createScope();
    const node = {};

    scope.resolve(node); // 0 (fresh id bound to node)
    scope.resolve(node); // 0 (cached hit on the same reference)
    scope.resolve({}); // 1 (distinct reference, fresh id)
    scope.resolve(); // 2 (anonymous, always fresh)

    Passing a mapper derives a value from each id, caching it and returning it again for repeated keys:

    const labels = createScope(id => `?v${id}`);

    labels.resolve(node); // "?v0"
    labels.resolve(node); // "?v0" (cached hit)
    labels.resolve(); // "?v1"

    Type Aliases

    Scope

    Identity-keyed value allocation scope.

    Functions

    createScope

    Creates a new Scope, optionally mapping each allocated id.