Constructor
new ProxyHandlerFactory(optionsopt)
Parameters:
Classes
Members
bypassSymbol :boolean
Type:
- boolean
computedKeys :Set:.<string:>
Type:
computedWatchers :Map:.<string:, AvenxWatcher:>
Type:
- Map:.<string:, AvenxWatcher:>
getComputedValueReal :function
Type:
- function
instance :object|null
Type:
- object | null
onChange :function
Type:
- function
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
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
persistKeys :Set:.<string:>
Type:
proxyCache :WeakMap:.<object:, Proxy:>
Type:
rootTarget :object|null
Type:
- object | null
Methods
create() → {ProxyHandler:.<object:>}
Creates the proxy handler object.
Returns:
deleteProperty(target, key) → {boolean}
Proxy 'deleteProperty' trap.
Parameters:
| Name | Type | Description |
|---|---|---|
target |
object | The target object. |
key |
string | symbol | The property key. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
Returns:
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. |
Returns:
- Type
- boolean
teardown()
Cleans up all computed watchers created by this proxy handler.