context
Import from bear/engine/context.
Interfaces
BearContext
Defined in: bear/engine/context.ts:10
A typed context key created via createContext<T>().
The object is the lookup key; the generic carries the value type.
Type Parameters
Properties
Functions
createContext()
function createContext<T>(label): BearContext<T>;Defined in: bear/engine/context.ts:20
Create a typed context key. Each call produces a unique key.
Type Parameters
Parameters
| Parameter | Type |
|---|---|
label | string |
Returns
BearContext<T>
ctx()
Call Signature
function ctx<T>(context, value): ContextMap;Defined in: bear/engine/context.ts:29
Build a ContextMap from a single typed context-value pair.
Type Parameters
Parameters
| Parameter | Type |
|---|---|
context | BearContext<T> |
value | T |
Returns
Call Signature
function ctx(...maps): ContextMap;Defined in: bear/engine/context.ts:31
Merge multiple ContextMaps into one.
Parameters
| Parameter | Type |
|---|---|
...maps | ContextMap[] |
Returns
getContext()
function getContext<T>(node, context): T | undefined;Defined in: bear/engine/context.ts:63
Walk the ancestor chain from node upward, returning the first
value found for the given context in any ancestor's context map.
The node itself is checked first, then its parent, grandparent, etc.
Returns undefined if no ancestor provides the context.
Type Parameters
Parameters
| Parameter | Type |
|---|---|
node | AncestorNode |
context | BearContext<T> |
Returns
T | undefined
getContextWithProvider()
function getContextWithProvider<T>(node, context):
| {
provider: AncestorNode;
value: T;
}
| undefined;Defined in: bear/engine/context.ts:75
Like getContext, but also returns the node that provided the value,
for consumers that need the provider's coordinate frame (e.g. gridline
planes live in the grid provider's frame).
Type Parameters
Parameters
| Parameter | Type |
|---|---|
node | AncestorNode |
context | BearContext<T> |
Returns
| {
provider: AncestorNode;
value: T;
}
| undefined