Events
ESPRMNeoUser carries a small event API (subscribe, unsubscribe, trigger and removeAllCallbacks) for the process-wide stream an app usually wants: parameter updates from any node. Subscribing also starts the machinery behind the event, and unsubscribing stops it.
The built-in event is defined by the ESPRMNeoEventType enum:
| Event | Delivers |
|---|---|
ESPRMNeoEventType.nodeUpdates | ESPNodeUpdateData per parameter change |
subscribe() replaces any existing callback for that event rather than adding to it; it calls unsubscribe() on the event first. If two parts of your app both need the stream, subscribe once and fan out yourself.
Observe parameter updates from every node
user.subscribe(ESPRMNeoEventType.nodeUpdates, (update) => {
console.log(update.nodeId, update.source, update.payload);
});
This is the single entry point for "tell me whenever any node's parameters change". Each node feeds every update it receives into a process-wide bus, whichever channel delivered it, and this event forwards that bus to your callback.
ESPNodeUpdateData carries the nodeId, the source channel that served it ("mqtt" today), an eventType, the payload as a { deviceName: { paramId: value } } map, and channel-specific metadata. A listener that throws is isolated; it cannot break delivery to other subscribers.
The node objects have already applied the update to their own params by the time your callback runs, so use this to trigger a re-render rather than to compute state.
Stop listening
user.unsubscribe(ESPRMNeoEventType.nodeUpdates);
user.removeAllCallbacks(ESPRMNeoEventType.nodeUpdates);
user.removeAllCallbacks();
unsubscribe(event) removes the callback and detaches the bus listener behind it. removeAllCallbacks(event?) unsubscribes one event, or every event when called with no argument. Call the no-argument form when tearing down.
trigger(event, arg) invokes the registered callback directly with whatever you pass. It exists because the SDK itself uses it to deliver events, and is occasionally useful for testing your handler; it does not reach the device or the network.
Method summary
| Method | Effect |
|---|---|
subscribe(event, callback) | Replaces the callback, starts the source |
unsubscribe(event) | Removes the callback, detaches the source |
trigger(event, arg) | Invokes the callback directly |
removeAllCallbacks(event?) | Clears one event, or all |
Related
- Live updates — the channels behind
nodeUpdates - Adaptors — the MQTT adaptor behind node updates
- Types —
ESPNodeUpdateDatain full - Device control — confirming a write from an update