redux-on
Store enhancer for redux which support accurately subscribe.
Install
npm i --save redux-on
Usage
const enhancer = const store = // exampleconst off = store
Api
on([type], [predicate], handler, [once])
Adds a change handler. It will be called any time an action with specified type dispatched or successful predication.
Arguments
type
(String): The type of action.predicate
(Function): The logic of predication. It will be called with two parameters:prevState
,state
. Need to returns a boolean value.handler
(Function): The change handler. It will be called with two parameters:prevState
,state
.once
(Boolean): Whether to handle change only once. Defaultfalse
.
Returns
(Function): A function that drop the change handler.
Examples
// listen customer change by action type.const off = store// listen customer change by predication.const off1 = store// listen customer change by action type and predication.const off2 = store// cancel listen
once([type], [predicate], handler)
Adds a change handler. It will be called only once an action with specified type dispatched or successful predication.
Arguments
type
(String): The type of action.predicate
(Function): The logic of predication. It will be called with two parameters:prevState
,state
. Need to returns a boolean value.handler
(Function): The change handler. It will be called with two parameters:prevState
,state
.
Returns
(Function): A function that drop the change handler.
Examples
store// orstore
License
MIT