combine-section-selectors
Combines selectors into one object with proper path handling.
API
Every selector should have get
prefix in name! E.g. getMyValue
.
Also names of all selectors should be uniq.
default export:
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 = ;fromState
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.
Example
reducer for counter
const counter = { };
selectors for counter
const getCount = state - minusCount;
combine
;;;; const reducer = ; const fromState = ; const store = ;store;fromState; // returns 2 (5 in state minus 3 from argument)
Motivation and alternatives
Without such module you should always set path to entity in selector:
const getUser = statedatausersentitiesuserId;
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;