GitHub package.json versionTypeScriptNPM
GitHub package.json versionTypeScriptNPM
Latest

Global Access

The Eagle Eye store manager is equipped with a store property which is accessible globally.

How do I access this global store?

This is done by simply utilizing the Eagle Eye store manager instance store property.
For global access to the Eagle Eye store manager's data, the store property exposes 4 methods. Namely:
  1. getState: Provides a static snapshot of the current state. May accept a list of property paths to target properties within the state to fetch and return
  2. resetState: Please see descriptions in the channel.resetState page. May accept a parameterless invocation resulting in a noop.
  3. setState: Please see descriptions in the channel.setState page.
  4. subscribe
    Provides the API for manual subscription to the Eagle Eye's state change and close events.
    Returns a parameterless void function - the unsubcriber.
    Accepts a "closing" event type and an observer function to be called before the Eagle Eye instance deactivation.
    Accepts a "data-updated" event type and an observer function for state changes.
    Context close event subscription
    stateManager.store.subscribe(
        'closing', ( shutDownReason : string ) => void
    ); // => VoidFunction
    Data change event subscription
    stateManager.store.subscribe(
        'data-updated', (
            changes : Changes<State>,
            changedPaths : Array<Array<string>>,
            netChanges : Partial<State>,
            mayHaveChangesAt : (tokenizedPath : string[]) => boolean
        ) => void
    ); // => VoidFunction
    More on "data-updated" event listener params
    1. changes: an object or array holding the original change request payload(s).
    2. changedPaths: an array of tokenized property paths belonging to state properties changed during this request.
    3. netChanges: an object of the final state of all properties in state changed.
    4. mayHaveChangesAt: a function to confirm that a given property path is among the new changes. This path is to be supplied as a tokenized string (i.e. supply ['a', 'b', 'c', '0', 'r'] for 'a.b.c[0].r').
Pro Tips
State references are always snapshots of the state at the time of access. In essence, the state returned by stateManager.store.getState(...) are not affected by subsequent updates to the store's state. Any updates to this acquired state never affects the Eagle Eye's state. So therefore, the 4 considerations:
use only the stateManager.store.setState(...) to update the Eagle Eye state manager's internal store.
stateManager.store.getState(...) must be used to obtain the current state value. Please remember to join this storeManager's change stream instead if real-time change monitoring is what you need.
use your stateManager.store.subscribe(...) to manually subscribe to state changes and refresh your current state value in real-time.
use the unsubscriber returned by your Eagle Eye instance store's subscribe(...) to unsubscribe from the store when needed.