GitHub package.json versionTypeScriptNPM
GitHub package.json versionTypeScriptNPM

Prehooks

What are Prehooks?

Prehooks are user functions which are invoked by the Eagle Eye context prior to executing context state operations.

Why Prehooks?

Prehooks provide a central place for sanitizing, modifying, transforming, validating etc. all related incoming state updates. The context store obtains its prehooks via its context Provider's prehooks optional prop.
The context store 2 update operations each adhere to its own user-defined prehook when present. Otherwise, the update operation proceeds normally to completion. Thus, there are 2 prehooks named resetState and setState - after the store update methods they support.
Each prehook returns a boolean value ( true to continue AND false to abort the update operation). The prehook may modify (i.e. sanitize, transform, transpose) the argument to accurately reflect the intended update value. This is done by mutating part of the argument which holds the next nextUpdate values.

What do Prehooks look like?

  1. resetState:
    prehooks.resetState = (
        resetData: PartialState<State>, // resetData holds nextUpdate data.
        state: {
            current: State,
            original: State
        }
    ) => boolean;
  2. setState:
    prehooks.setState = (
        newChanges: PartialState<State> // newChanges holds nextUpdate data.
    ) => boolean;

How are Prehooks wired up to the context store?

Please visit the Provider concept page.