State Store
The state store holds the reactive state that drives your rendered UI. @ngaf/render provides signalStateStore(), an Angular Signals-backed implementation of the StateStore interface from @json-render/core.
Creating a State Store
The function accepts an optional initial state object (defaults to {}). It returns a StateStore that uses Angular Signals internally, so any state changes automatically trigger Angular's change detection.
JSON Pointer Paths
All state access uses JSON Pointer paths. A JSON Pointer is a string that identifies a specific value within a JSON document.
| Path | Resolves to |
|---|---|
/user/name | 'Alice' |
/user/age | 30 |
/items/0 | 'apple' |
/items/2 | 'cherry' |
/isVisible | true |
Paths always start with /. Each segment separated by / traverses one level deeper into the object. Array elements are accessed by index.
Escaping
JSON Pointer defines two escape sequences for special characters in property names:
~0represents~~1represents/
For example, to access a property named a/b, the pointer would be /a~1b.
Reading State
Use get() to read a value at a path:
Writing State
Single Value
Use set() to write a single value. The store performs an immutable update -- it clones the path to the target and sets the new value. If the new value is referentially equal to the current value, the update is skipped.
Batch Updates
Use update() to set multiple values in a single operation. This triggers only one notification to subscribers, regardless of how many values change.
If none of the values actually change (all are referentially equal), no notification is triggered.
Snapshots
Use getSnapshot() to get the entire state object:
Subscribing to Changes
Use subscribe() to register a callback that is invoked whenever the state changes. The function returns an unsubscribe function.
Reactive Behavior with Angular Signals
Under the hood, signalStateStore() wraps the state in an Angular signal(). This means:
- Components using
OnPushchange detection automatically update when the state changes - Props resolved via
$stateexpressions in specs are re-evaluated when the underlying signal updates - The store integrates seamlessly with Angular's reactivity model -- no RxJS or manual subscription management needed
Working with Arrays
The store preserves array types when updating elements by index:
Providing the Store
You can provide a store in three ways. RenderSpecComponent resolves the store using this priority chain:
Pass a store directly to <render-spec>:
Set a store in provideRender():
If no external store is provided, RenderSpecComponent creates an internal signalStateStore() from spec.state: