ApplicationState API
The API for Application is very simple, there is currently no constructor everything is implemented statically:
Methods
static get(name)
Argument | Type | Description |
---|---|---|
name | String | The name of the desired node within the state tree. |
Return the value at the given path.
static set(name, value)
Argument | Type | Description |
---|---|---|
name | String | The name of the desired node within the state tree. |
value | Object|Array|Scalar | The value to place at the specified node within the state tree. |
Set the value at the specified path.
static listen(name, callback)
Argument | Type | Description |
---|---|---|
name | String | The name of the desired node to center the listener on. |
callback | Function | The function to execute when a node within the |
Listen for changes at the specified path, invoking the callback with the new and old values. Callback should be of the form:
1 | (new_value, old_value) => { ... } |
A listener key will be returned, it can be used later to remove the listener, if needed.
static removeListener(name, key)
Argument | Type | Description |
---|---|---|
name | String | The name of the desired node where the listener was set. |
key | String | The listener key that was returned when the listener was first set. |
Remove the listener at the specified path with the given key
static ln(target, link_path)
Argument | Type | Description |
---|---|---|
target | String | The existing node to be linked. |
link_path | String | The path to create as a link. |
This is similar the the unix "ln" symlink functionality. It is used to link a node to another area in the graph. The linked node can be used interchangably with the original. Listeners will be notified on both the original path and the symlinked path.
static rm(name)
Argument | Type | Description |
---|---|---|
name | String | The name of the node to fully remove from the state tree. |
Delete the specified path. If the path refers to an object or array, everything with that object or array is also removed. If the target is a symlink, only the symlink will be removed. If a node pointed to by a symlink is deleted, the symlink will also be deleted.
static notify(name, explicit, options)
Argument | Type | Description |
---|---|---|
name | String | The name of the node to center the notification on. |
explicit | Boolean | Do not notify up or down the state tree, just notify the path specified. |
options | Object | Used by plugins. |
Used to trigger a listener. If explicit is set to true, only a listener that is directly pointing at the specified node will be triggered, hierarchical listeners will not. The options parameter is reserved for use by plugin authors and carries information such as whether the changed value should be persisted.
static undo(name)
Argument | Type | Description |
---|---|---|
name | String | The name of the node to be reverted to the previous value. |
Revert changes to state for the specific name. Note: this honors the hierarchy, so it will navigate through all child names and undo any changes below it. So, for example, if you were to call undo('app') and 'app' was the top level key in your application, any changes to any child of app will be rewound, 'app.login', 'app.user.role' etc...
If there is no previous state for the specified value, it will be set to undefined.