Lime Web Components API Documentation - v6.24.0
    Preparing search index...

    Interface ContextScope<TReads>Alpha

    A host-bound, typed view over ContextMap. Resolves each key its own way: by walking the DOM, by consulting a session-wide default, or by reading from a fixed value bag. The caller picks which strategy when they build the scope with ContextRegistry.scope.

    One method, get(key). A consumer that needs more than one key calls get multiple times.

    Each key resolves in order from most specific to least: a per-call override on ContextRegistry.scope wins first, then the closest DOM ancestor that registered a value through ContextRegistry.provide, then a session-wide default registered through ContextRegistry.register. If none of those answer, get returns undefined.

    Resolution is pull-based, not reactive: a ContextScope answers the current value on each get call but does not notify when a value changes. Re-evaluating against a scope when its inputs change is the caller's responsibility. For reactive consumption of context values, use ContextRegistry.subscribe directly.

    Rules are one consumer of this contract, but not the only one. Command guards, filter predicates, and any other code that wants a "bind a host plus overrides once, then read keys repeatedly" helper builds a ContextScope and reads from it.

    Building and reading from a scope

    const registry = platform.get(PlatformServiceName.ContextRegistry);
    const scope = registry.scope({ host: this.host });
    const user = scope.get('user');
    interface ContextScope<TReads extends keyof ContextMap = keyof ContextMap> {
        get<K extends keyof ContextMap>(key: K): ContextMap[K];
    }

    Type Parameters

    Index

    Methods

    Methods

    • Alpha

      Look up the current value of a context key.

      Type Parameters

      Parameters

      • key: K

        The context id. Must be one of the keys the scope's consumer declared upfront (e.g. a primitive's reads), or any ContextMap key when the scope is used through the wide default.

      Returns ContextMap[K]

      The value if any provider answered, otherwise undefined.