Change Stream Channel
What is a change stream channel?
Where an Eagle Eye store is the client's portal into the context's underlying state, an Eagle Eye channel is a direct observable real-time store dedicated to monitoring a specific subset of the state.
Obtaining a channel
Obtain a channel by joining a stream. See how to do this here.
A channel exposes 3 properties for interacting with the state manager. Namely:
1.data: which is an object holding resolved state slices as declared in the selector map. See selector map to channel data example here
2.resetState: (propertyPaths?: Array<string>) => void // resets slices of state referenced by the property paths to their initial values.
3.setState: (changes: Changes<State>) => void // merges only new/changed state slices.
A channel also exposes 3 properties for channel related communication. Namely:
1.addListener: for subscribing to data-changed and stream-ending events of a stream channel.
('data-changed', () => void) => void // to be called whenever channel.data changes.('stream-ending', (reason : string) => void) => void // to to be called before closing this channel.
2.removeListener: for unsubscribing from data-changed and stream-ending events of a stream channel.
('data-changed', <subscribed fn>) => void('stream-ending', <subscribed fn>) => void
3.endStream: () => void // terminates this channel's ability to continue participating in the stream.
A channel also exposes 4 properties for communicating its own internal state. Namely:
1.streaming: a read-only property communicating is currently connected to the stream.
2.closed:
- a read-only property communicating that this channel has been formally removed from the stream.
- once a channel is in this phase, it remains permanently closed.
3.phase: a read-only property communicating any of the various phases currently inhabited by this channel at any given time.
- a writeable property through which a channel's observed slices of state can be updated.
- updating this property automatically updates the contents of the
channel.dataproperty and issuing this channel'sdata-changedevent.
