About EntryFunction
The EntryFunction is introduced to add Logic after Action dispatch, and before Service and Reducer. The EntryFunction should be defined as:
const entrySample = (store, action) => {
// Access Data from: store.getState(), action
// Send new Actions by: store.dispatch(action)
// return true // if true, the Action is Blocked
}
// set the targeted Action Type
reduxService.setEntry('entry:sample', entrySample)
Unlike Service, which appears to be 'waiting' for an Action. The Entry gets called Every time the matched-typed Action gets dispatched.
Action Process Order and Action Block
If an Action Type is used for an EntryFunction and a Service, the Order of processing will be like:
- some Redux Middleware
- Redux Middleware: Redux-Service
- EntryFunction
- ServiceGenerator
- other Redux Middleware
- Redux Reducer
- Reducer
- Redux State Update
Also, the EntryFunction can Block the follow-up Action processing by return true
, or value evaluates to true
.
Note this means the other Redux Middleware && Redux Reducer && Reducer
will not receive the Action.
Usage
For an EntryFunction to work, two condition should be met:
- set the EntryFunction to ReduxService instance
- set the ReduxService instance as Redux Store MiddleWare
Check ReduxService API
Here are some possible usage:
- Sequenced-Action: dispatch Actions in Order
- Redirect: dispatch Action(s) for other Entry(s), Service(s) and Reducer(s)
- Filter: Block this Type of Actions on condition