Subscription Store
The SubscriptionStore manages real-time event subscriptions and automatically updates the NodeStore when events occur. It listens for transport discovery events and node update events, ensuring your UI stays synchronized with device state changes in real-time.
Overview
The SubscriptionStore provides:
- Real-time event subscriptions
- Automatic NodeStore updates on events
- Transport discovery event handling
- Node update event handling
- Reactive UI updates through store synchronization
Accessing the Store
Access the SubscriptionStore through the CDF instance:
const subscriptionStore = espCDF.subscriptionStore;
Properties
| Property | Type | Description |
|---|---|---|
| nodeUpdates | { listen: (event: any) => void } | Handler for node update events. Listens for real-time node updates and automatically updates node data in NodeStore when changes occur. |
| transport | { listen: ({ nodeId: string, transportDetails: ESPTransportConfig }) => void } | Transport module to handle transport-related operations. Listens for transport discovery events and updates the device store with transport configurations. |
Example Usage
// Access transport listener
const transportListener = subscriptionStore.transport;
// This is automatically set up when subscribeAllListeners() is called
// Access node updates listener
const nodeUpdatesListener = subscriptionStore.nodeUpdates;
// This is automatically set up when subscribeAllListeners() is called
SubscriptionStore Methods
Subscribe All Listeners
To subscribe to all available event listeners, use the subscribeAllListeners() method. This method sets up real-time subscriptions for transport discovery and node updates. It is automatically called when autoSync is enabled during login.
try {
await subscriptionStore.subscribeAllListeners();
console.log("All listeners subscribed");
} catch (error) {
console.error("Error subscribing listeners:", error);
}
What it subscribes to:
-
Local Discovery Events (
ESPRMEventType.localDiscovery)- Listens for transport discovery events
- Automatically updates node transport configurations in NodeStore
- Triggers when devices are discovered on the local network
-
Node Update Events (
ESPRMEventType.nodeUpdates)- Listens for real-time node updates
- Automatically updates node data in NodeStore when changes occur
- Includes connectivity status, device parameters, and node configuration changes
How It Works
Transport Discovery Subscription
When a transport discovery event occurs, the transport.listen handler:
- Receives the node ID and transport details
- Updates the node's transport configuration in NodeStore
- Updates available transports for the node
- UI automatically updates due to reactive store bindings
// This happens automatically when subscribeAllListeners() is called
// When a device is discovered:
// - Transport details are received
// - NodeStore.updateNodeTransport() is called
// - Node's available transports are updated
// - UI reactively updates