AlphaAlphaSnapshot read of a context value.
Resolves key against the DOM ancestors of host first, then
the session-wide fallback. Returns undefined when no provider
answers.
The context id.
The context to resolve.
Optionalhost: HTMLElementElement to start the ancestor walk from. When omitted, only the session-wide fallback is consulted.
The resolved value, or undefined when no provider
answers.
AlphaAttach a value source for a context key to a host element. Typically called during a component's lifetime.
When something later resolves key against a host that is a
descendant of this element, the closest ancestor that registered
a provider wins.
Reactive providers call notify() on the returned handle when
their underlying value changes. Non-reactive providers ignore
notify and only call teardown() on disconnect.
The context id. Pinning it to a known key makes
getter's return type match the key's value type.
The context this provider answers.
Element to attach the provider to.
Returns the current value. Called every time a
walk hits this provider, so keep it cheap. May return undefined
when no value is currently available; the walk then continues to
the next provider.
A handle exposing teardown and notify. Call
teardown from disconnectedCallback (or equivalent) to detach
the provider.
AlphaDeclare that a context key exists. Called once per key at bootstrap.
The optional fallback is a session-wide value source, used when
no DOM ancestor has supplied a value. Good for keys that are the
same for the whole session, like the current user or device.
Compare with provide, which supplies a value scoped to a specific host element.
The context id. Tying it to a known key makes the fallback's return type match the key's value type.
Metadata for the key (id, label, description).
Optionalfallback: () => ContextMap[K]Optional session-wide value source. May return
undefined when no value is currently available; treated the
same as no fallback being registered.
AlphaBuild a ContextScope, a host-bound typed view that resolves ContextMap keys on demand. The only supported way to construct one.
host to walk the DOM from there. Typical for components.with to hand in fixed values. Typical for tests and
headless code.get returns
undefined.Rules are one consumer of ContextScope (a rule predicate reads
from one), but command guards, filter predicates, and anything
else that wants "bind a host plus overrides once, then read keys
repeatedly" builds a scope the same way.
Optionaloptions: ContextScopeOptionsOptional construction options.
A new scope.
AlphaSubscribe to changes of a context value.
The listener fires immediately with the current value and again
whenever the resolved value changes. The immediate fire is
synchronous, the listener is invoked before subscribe returns.
Returns a teardown function to stop the subscription.
Reactive providers signal changes through notify. A subscription also re-evaluates when providers are added or removed along the ancestor chain.
The context id.
The context to observe.
Element to anchor the subscription to. Pass
undefined to only consult the session-wide fallback.
Called immediately with the current value and again on every change.
Teardown function to stop the subscription.
Central place for ambient context: registration, DOM-walked provider lookup, direct key lookup, reactive subscription, and scope construction.
This package only describes the contract; the actual behavior is supplied by an implementation, reached through the platform service
contextRegistry.What the API does, by area:
get(key)repeatedly. Used by rule evaluation, command guards, filter predicates, and anything else that wants a pre-bound view of ContextMap.Each key resolves in order from most specific to least: the closest DOM ancestor that registered a value through provide wins first, then a session-wide fallback registered through register. If neither answers, the resolved value is
undefined.Example
Snapshot read
Example
Reactive subscription
Example
Building a scope