Class: ProxyHandlerFactory

ProxyHandlerFactory(optionsopt)

Factory for creating and managing Proxy handlers for reactive state objects.

Constructor

new ProxyHandlerFactory(optionsopt)

Parameters:
Name Type Attributes Description
options object <optional>

Configuration options.

Properties
Name Type Attributes Description
computedKeys Array:.<string:> <optional>

List of keys that should be treated as computed properties.

onChange function <optional>

Callback triggered when a property is set.

onKeysChanged function | null <optional>

Callback triggered when the root target gains or loses a key, for consumers that cache its key set.

onlyNotifyObserved boolean | function <optional>

When true, onChange is suppressed for writes that no watcher depends on, at any level of the property path. Off by default so the standalone reactive primitive keeps notifying for every mutation.

getComputedValue function <optional>

Function to evaluate a computed property.

instance object <optional>

The component instance for fallback property lookups.

bypassSymbol boolean <optional>

Bypasses Symbol check during lookup.

persist Array:.<string:> <optional>

List of state keys to persist in localStorage.

Source:

Classes

ProxyHandlerFactory

Members

bypassSymbol :boolean

Type:
  • boolean
Source:

computedKeys :Set:.<string:>

Type:
  • Set:.<string:>
Source:

computedWatchers :Map:.<string:, AvenxWatcher:>

Type:
Source:

getComputedValueReal :function

Type:
  • function
Source:

instance :object|null

Type:
  • object | null
Source:

onChange :function

Type:
  • function
Source:

onKeysChanged :function|null

Called when the root target gains or loses a key.

Distinct from onChange, which fires for a value change. A consumer that caches the set of names state binds -- the template scope does -- needs to know when that set changed, and cannot tell from a value notification. Without it the cache has to be rebuilt on every read, which is Object.keys() over the whole state object per expression evaluated.

Type:
  • function | null
Source:

onlyNotifyObserved :boolean|function

Whether onChange is suppressed for writes nothing depends on.

Off by default: the standalone reactive primitive promises a notification for every mutation. Components turn it on so that a write to a key no expression reads does not schedule a render. May be a predicate, so a consumer can enable filtering only once it has actually collected dependencies.

Type:
  • boolean | function
Source:

persistKeys :Set:.<string:>

Type:
  • Set:.<string:>
Source:

proxyCache :WeakMap:.<object:, Proxy:>

Type:
  • WeakMap:.<object:, Proxy:>
Source:

rootTarget :object|null

Type:
  • object | null
Source:

Methods

create() → {ProxyHandler:.<object:>}

Creates the proxy handler object.

Source:
Returns:
Type
ProxyHandler:.<object:>

deleteProperty(target, key) → {boolean}

Proxy 'deleteProperty' trap.

Parameters:
Name Type Description
target object

The target object.

key string | symbol

The property key.

Source:
Returns:
Type
boolean

evaluateComputedWatcher(key, receiver) → {any}

Evaluates and caches a computed property using an internal AvenxWatcher.

Parameters:
Name Type Description
key string

The computed key.

receiver object

The proxy receiver.

Source:
Returns:
Type
any

get(target, key, receiver) → {any}

Proxy 'get' trap. Redirects to evaluateComputedWatcher if the key is a computed property.

Parameters:
Name Type Description
target object

The target object.

key string | symbol

The property key.

receiver object

The proxy or object inheriting from the proxy.

Source:
Returns:
Type
any

getMapMethod(target, key, receiver) → {any}

Returns a custom implementation of a Map method.

Parameters:
Name Type Description
target Map

The raw Map.

key string | symbol

The property/method key.

receiver Proxy

The Map proxy.

Source:
Returns:
Type
any

getOwnPropertyDescriptor(target, key) → {PropertyDescriptor|undefined}

Proxy 'getOwnPropertyDescriptor' trap. Ensures computed properties appear as own properties.

Parameters:
Name Type Description
target object

The target object.

key string | symbol

The property key.

Source:
Returns:
Type
PropertyDescriptor | undefined

getSetMethod(target, key, receiver) → {any}

Returns a custom implementation of a Set method.

Parameters:
Name Type Description
target Set

The raw Set.

key string | symbol

The property/method key.

receiver Proxy

The Set proxy.

Source:
Returns:
Type
any

isConnected(target) → {boolean}

Checks if the target object is still connected to the root state.

Parameters:
Name Type Description
target object

The target raw object.

Source:
Returns:
Type
boolean

notifyChange(target, keyopt)

Notifies about a change if anything actually depends on it.

This used to call onChange() for every write to any connected target, which scheduled a component update whether or not a single expression read the key. The per-key dependency graph the Proxy layer maintains was therefore discarded at the last step: a component re-rendered in full when a state key nothing referenced changed.

trigger() alone is not a sufficient replacement. It wakes watchers registered for exactly one target and key, and a nested write such as items[0].qty = 3 triggers on the inner object while the template's dependency was recorded against items on the root. Walking the parent chain is what keeps deep reactivity working while still allowing a write that nothing observes -- at any level of the path -- to be skipped.

Filtering is opt-in via onlyNotifyObserved. StateFactory.create(obj, { onChange }) is a public primitive whose documented contract is that onChange fires for every mutation, watchers or not; components opt in because for them onChange means "schedule a re-render", and a re-render for a key no expression reads is exactly the waste being removed.

Parameters:
Name Type Attributes Description
target object

The target raw object.

key string | symbol | Array:.<(string:|symbol:)> <optional>

The key that changed. Omitted for structural changes whose affected keys are not known, which notify unconditionally.

Source:

ownKeys(target) → {Array:.<(string:|symbol:)>}

Proxy 'ownKeys' trap. Includes computed keys in the list of keys.

Parameters:
Name Type Description
target object

The target object.

Source:
Returns:
Type
Array:.<(string:|symbol:)>

set(target, key, value) → {boolean}

Proxy 'set' trap.

Parameters:
Name Type Description
target object

The target object.

key string | symbol

The property key.

value any

The new value.

Source:
Returns:
Type
boolean

teardown()

Cleans up all computed watchers created by this proxy handler.

Source: