on
Listens for changes to the data at the end of a chain, from this device or any other. Use get() and next() to choose the data, and off() to stop listening.
Parameter | Description |
|---|---|
| Optional lex query to only listen to some of the node's properties. |
| Function called with the new data each time it changes. Required. |
| Optional. When |
| Optional object, see Options. |
The callback can be called many times, so on() always needs one and can't be awaited. Keep a reference to the callback if you want to remove it later with off().
Examples
// Wait for "key" to change.
holster.get("key").on(console.log)
// Also receive the current data straight away.
holster.get("item").next("property").on(console.log, true)
// Also be notified when any child node changes.
holster.get("item").next("hasChildren").on(console.log, true, {nested: true})
// Only listen to properties starting with "prop".
holster.get("item").on({".": {"*": "prop"}}, console.log)Options
Both options default to false.
Option | Description |
|---|---|
| Also listen for changes inside child nodes. Without it, changing a value in a nested object doesn't notify a listener on its parent, since each object is its own node. |
| Only return data that's already in memory, without reading from storage or the relay. Faster, but a node that has only been partly loaded is returned as it is. |
With nested, the callback receives the full node each time, including the updated child.