Module: lib/core/trace/derived

Trace hooks for derived values — computed properties and bridge getters.

Derived values are read far more often than they change. A component's template may read cart.total on every render, and a bridge getter is re-evaluated on every access because it has no cache of its own. Recording every evaluation would bury the causal graph under noise that says nothing.

So a derived value is recorded only when its result actually changed, which is the only form in which it explains anything: cart.total 24.00 → 36.00 is a step in the causal chain, while cart.total read is not.

Source:

Members

(inner, constant) lastValues :WeakMap:.<object:, Map:.<string:, any:>>

Last recorded value per derived key, so a re-evaluation that produced the same answer can be dropped.

Keyed by owner object so entries disappear with the component or bridge they belong to, and populated only while a recording is running.

Type:
  • WeakMap:.<object:, Map:.<string:, any:>>
Source:

Methods

(static) forgetDerived(owner)

Forgets the baseline values for an owner.

Called when a recording stops so a later recording of the same long-lived bridge starts from a clean baseline rather than comparing against values observed in a previous session.

Parameters:
Name Type Description
owner object

The component or bridge.

Source:

(static) traceDerived(owner, descriptor, value, knownopt)

Records that a derived value was re-evaluated and produced a new result.

Parameters:
Name Type Attributes Description
owner object

The component or bridge that owns the value.

descriptor object

What was evaluated.

Properties
Name Type Attributes Description
name string

The computed or getter name.

kind string <optional>

computed for a component, getter for a bridge.

owner string <optional>

The owning component or bridge name.

expression string <optional>

The expression source, when Avenx has it.

contracts Array:.<string:> <optional>

Compiler contracts the owner declared.

value any

The value the evaluation produced.

known object <optional>

The caller's own record of the previous value.

Properties
Name Type Description
has boolean

Whether the caller knows the previous value.

value any

The previous value.

Source:

(inner) unchanged(a, b) → {boolean}

Compares two derived results.

Deliberately reference equality with a NaN special case, not a deep compare: a deep compare on every evaluation of every computed would cost more than the tracing it serves. A computed returning a fresh object each time is therefore recorded on every evaluation, which is accurate — it did produce a new value, and that is usually worth seeing.

Parameters:
Name Type Description
a any

Previous value.

b any

Current value.

Source:
Returns:

True when the value is unchanged.

Type
boolean