
Security News
Crates.io Implements Trusted Publishing Support
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
combine-section-selectors
Advanced tools
Combine selectors from state to one set of selectors. Useful with redux and combineReducer or combine-section-reducer
Combines selectors into one object with proper path handling.
Every selector should have get
prefix in name! E.g. getMyValue
.
Also names of all selectors should be uniq.
(modules: {[string]: {[string]: Function}}) =>
({[string]: Function})
Name of module should be exact same as key on where state is stored.
So if you have state.users.userId
, you should combine selectors for users
on "users"
key:
const fromState = combineSelectors({
users: {
getUser: (users, userId) => users[userId],
},
});
fromState.getUser({users: {myId: {}}}, `myId`)
Selector implementation gets substate as first argument, and rest args just compied.
Selector from combine gets entire state as first argument, and any rest args.
Also selector implementation gets entire state as last argument. It's same as in combine-section-reducer
module.
const counter = (state = 0, action) => {
switch (action.type) {
case `ADD`:
return state + action.payload;
default:
return state;
}
}
export default counter;
export const getCount = (state, minusCount) => state - minusCount;
import {combineReducers} from 'redux';
import combineSelectors from 'combine-section-selectors';
import counter from './counter';
import * as fromCounter from './counter.selectors';
const reducer = combineReducers({
counter,
});
const fromState = combineSelectors({
counter: fromCounter,
});
const store = createStore(reducer);
store.dispatch({type: `ADD`, payload: 5});
fromState.getCount(store.getState(), 3); // returns 2 (5 in state minus 3 from argument)
Without such module you should always set path to entity in selector:
const getUser = (state, userId) => state.data.users.entities[userId];
which is awkward, because it makes this selector depending on where substate is connected to entire state.
Or even worse, pass path to substate on every usage of selector:
fromState.getUser(state.data.users, userId);
FAQs
Combine selectors from state to one set of selectors. Useful with redux and combineReducer or combine-section-reducer
The npm package combine-section-selectors receives a total of 1 weekly downloads. As such, combine-section-selectors popularity was classified as not popular.
We found that combine-section-selectors demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.