Class: ComponentScope

lib/core/runtime/ComponentScope.ComponentScope(owner)

The evaluation scope of one component.

Constructor

new ComponentScope(owner)

Parameters:
Name Type Description
owner object

The component this scope belongs to.

Source:

Members

base :object|null

The base scope, built on first use and reused until invalidated.

Type:
  • object | null
Source:

methods :object|null

The method map the cached base scope was built against.

A component's actions are established once, but createMethodMap hands the scope builder the map it is still filling, so the first scopes are built against an object that is not yet complete. Recording which map the cache belongs to is what stops a stale one being reused.

Type:
  • object | null
Source:

owner :object

Type:
  • object
Source:

stateKeys :Array:.<string:>|null

The names the state layer binds, cached because computing them is Object.keys() over the whole state object and a scope used to be built per expression evaluated.

Type:
  • Array:.<string:> | null
Source:

Methods

() → {Array:.<string:>}

The names provide/inject makes visible.

The names are a property of the component's inject declaration and do not change; the values behind them do, because a provider higher up the tree can update one at any time. So the names are resolved once and the values are read live -- caching the values is what made a child keep rendering the theme its ancestor no longer provides.

Source:
Returns:

The injected names.

Type
Array:.<string:>

(methods) → {object}

Builds the layered scope.

Parameters:
Name Type Description
methods object

The component's executable actions.

Source:
Returns:

The scope proxy.

Type
object

invalidate()

Discards the cached scope.

Called when something changes what a name would resolve to. Cheap enough to call speculatively: the cost is one scope rebuild on the next evaluation.

Source:

invalidateKeys()

Discards only the cached state-key list.

A key being added to or removed from state changes what the state layer binds but not the shape of the scope, so the layers themselves survive.

Source:

keys() → {Array:.<string:>}

The names state and computed values bind.

Read from the raw target and the compiler's computed list rather than by enumerating the proxy, so building a scope registers no dependency and evaluates no computed value.

Source:
Returns:

The bound names.

Type
Array:.<string:>

resolve(methodsopt, extrasopt) → {object}

The scope an expression should be evaluated against.

Parameters:
Name Type Attributes Default Description
methods object <optional>

The action map to expose. Defaults to the owner's.

extras object <optional>
null

Per-call bindings layered on top.

Source:
Returns:

The scope.

Type
object