1.0.0 • Published 8 years ago
bo-selecta v1.0.0
bo-selecta
Wanted to put some 😍😍😍 into my mapStateToProps
and came up with this.
const mapStateToProps = (state, {userId}} => {
user: select('users').from(state).byId(userId),
};
It should integrate okay with your existing selectors if you've been structuring your Redux work in a reasonably standard way, like writing your selectors in the same file as the reducers whose state they read from.
Documentation
createSelect
const { createSelect } = require('bo-selecta');
exports.select = createSelect({
users: {
byId: (state, id) {
return state[id];
}
}
});
stateAccessor
It assumes you're doing a very typical redux setup where the store is a plain
JS object and each selector only reads from its reducer's section of the overall
state. If the above don't apply, e.g. maybe you use Immutable.js, you can pass a
custom stateAccessor to get the correct state
param to your selectors.
const { createSelect } = require('bo-selecta');
const { * as userSelectors } = require('./reducers/users');
exports.select = createSelect({ users: userSelectors }, {
stateAccessor(s, entity) {
// Use the Immutable.js Map API to pass the correct subproperty of the store
// to the selector functions
return s.get(entity);
}
});
Contributing
Contributors are subject to v1.4 of the Contributor Covenant.
License
bo-selecta is released under the MIT License.