redux-select-when-matched
v2.0.6
Published
resolves a promise with your chosen selection from state when the state allows your predicate to return true
Downloads
111
Readme
redux-select-when-matched
resolves a promise with your chosen selection from state when the state allows your predicate to return true
Table of Contents generated with DocToc
Usage
Installation
$ npm install redux-select-when-matched --prod
Subscribing to state changes
import selectWhenMatched from 'redux-select-when-matched';
import {createStore} from 'redux';
import {isLoaded, getResource} from 'duck';
const store = createStore(reducer);
const predicate = state => isLoaded(state, 'foo-type', id);
const selector = state => getResource(state, 'foo-type', id);
selectWhenMatched(store, predicate, selector).then(selectedDetailsFromState => {
// do what you need to with the details that are now available from state
});
API
subscribe
requires the raw redux store
, predicate
and selector
for the subscription
store
(required)
your redux store object
predicate
(required)
accepts the new state as input, allowing you to inspect and return a boolean informing whether or not the promise for this subscription should be resolved
selector
(required)
accepted the new state as input, allowing you to select within it to return the subset of state that your subscriber desires
Contributing
Dependencies
$ nvm install
$ npm install
Verification
$ npm test