GitHub package.json versionTypeScriptNPM
GitHub package.json versionTypeScriptNPM
Latest

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.

  1. ('data-changed', () => void) => void // to be called whenever channel.data changes.
  2. ('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.

  1. ('data-changed', <subscribed fn>) => void
  2. ('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:

  1. a read-only property communicating that this channel has been formally removed from the stream.
  2. 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.

4.selectorMap:

  1. a writeable property through which a channel's observed slices of state can be updated.
  2. updating this property automatically updates the contents of the channel.data property and issuing this channel's data-changed event.