Red Live
Simple and lightweight middleware for binding to Redux actions.
Installation:
npm i red-live --save
Usage:
applyMiddleware()
1) Apply in Redux import { redLiveMiddleware } from 'red-live'
createStore(
rootReducer,
applyMiddleware(
redLiveMiddleware,
)
)
2) Use before/after hook-subscribers
import { redLiveSubBefore, redLiveSubAfter } from 'red-live'
Accept two arguments:
- Action name(s) (String or Array of strings)
- Callable function on action (Function)
Example:
import { createStore, combineReducers, applyMiddleware } from 'redux'
import { redLiveMiddleware, redLiveSubBefore, redLiveSubAfter } from 'red-live'
const rootReducer = combineReducers({
...
})
const store = createStore(
rootReducer,
applyMiddleware(
redLiveMiddleware,
)
)
function appInitBeforeEvent(action) {
console.log(`Event before APP_INIT apply to dispatch`)
}
function appRunAfterEvent(action) {
console.log(`Event after APP_INIT or APP_RUN applied to dispatch`)
}
redLiveSubBefore('APP_INIT', appInitBeforeEvent)
redLiveSubAfter(['APP_INIT', 'APP_RUN'], appRunAfterEvent)