Fires a callback whenever a store subtree turns to a desired value
npm install redux-wheneverSubscribe to a state subtree (or leaf) and run callbacks whenever it evaluates to a given value.
``js
const whenever = require('redux-whenever')
const redux = require('redux')
// Pass whenever as an enhancer
const store = redux.createStore(reducer, whenever)
// Pass the state selector you are interested in as a string.
// callback will execute only when player.isReady becames true`
store.whenever('player.isReady', true, (curState, prevState) => {
// Your magic here
})
js
const unsubscribe = store.whenever('player.isReady', true, callback)
unsubscribe() // Removes previously added listener
`API
$3
Returns a function that, if called, removes the added subscriber.####
selector
- type: String|FunctionShould return a piece of the state tree
####
assertion
- type: String|Number|Object|FunctionIf a function, it will be executed. If not, it's equality will be compared against current state.
####
callback
- type: FunctionInstallation
`
npm install --save redux-whenever
``---
caiogondim.com ·
GitHub @caiogondim ·
Twitter @caio_gondim