signalStateStore()
Creates a reactive state store backed by Angular Signals that implements the StateStore interface from @json-render/core.
Import
Signature
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
initialState | StateModel | {} | Initial state object. StateModel is Record<string, unknown>. |
Returns
A StateStore object with the following interface:
Methods
get(path)
Reads a value from the store at the given JSON Pointer path.
| Parameter | Type | Description |
|---|---|---|
path | string | A JSON Pointer path (e.g., /user/name) |
Returns: The value at the path, or undefined if the path does not exist.
set(path, value)
Sets a single value at the given path. Performs an immutable update -- the path to the target is cloned, preserving unchanged branches. If the new value is referentially equal (===) to the current value, the update is skipped and no subscribers are notified.
| Parameter | Type | Description |
|---|---|---|
path | string | A JSON Pointer path |
value | unknown | The new value to set |
update(updates)
Batch-sets multiple values in a single operation. Only triggers one subscriber notification, regardless of how many values change. If no values actually change, no notification is triggered.
| Parameter | Type | Description |
|---|---|---|
updates | Record<string, unknown> | A map of JSON Pointer paths to new values |
getSnapshot()
Returns the entire state object.
Returns: StateModel -- the current state object.
subscribe(listener)
Registers a callback that is invoked after every state mutation. Returns an unsubscribe function.
| Parameter | Type | Description |
|---|---|---|
listener | () => void | Callback invoked after state changes |
Returns: () => void -- an unsubscribe function.
JSON Pointer Format
Paths follow the RFC 6901 JSON Pointer specification:
- Paths start with
/ - Each
/-separated segment traverses one level - Array elements are accessed by numeric index
- Escape sequences:
~0for~,~1for/
| Path | Description |
|---|---|
/name | Top-level name property |
/user/email | Nested property |
/items/0 | First array element |
/items/2/name | name property of third array element |
/a~1b | Property named a/b |
Reactive Behavior
The store wraps state in an Angular signal(). This means:
- Reading state via
get()accesses the signal, creating a reactive dependency in anycomputed()or template that calls it - Writing state via
set()orupdate()triggers the signal, which propagates through Angular's change detection RenderSpecComponentandRenderElementComponentusecomputed()signals that depend on the store, ensuring the UI updates automatically
Array Handling
The store preserves array types when updating elements by index:
Immutable Updates
Every set() and update() call produces a new state object. Unchanged branches of the state tree are shared (structural sharing):
Related
- State Store Guide -- usage patterns, providing stores, and working with arrays
- Specs Guide -- how
$stateexpressions connect to the store - provideRender() -- providing a global store