Is there a way to create a compound selector in NgRx?
Example:
export const paramSelector = (id) => createSelector(
someState,
state => state[id]
);
export const selectedId = createSelector(
someOtherState,
state => state.id
);
export const compoundSelector = createSelector(
selectedId,
id => paramSelector(id),
state => state
);
Obviously above code doesn't work. Is there any way to get the desired result (last snipped)?
The idea is to have specialized parametrized selectors, and some higher level selectors consuming them. Imagine paramSelector
is more complex. Sometimes you want to use paramSelector
with specific parameters. Sometimes you don't want to provide params yourself, you want to get it somewhere from the store (eg. router state).
Now, you never want to repeat the same code, thus need for a compound selector.
Edit
Feature request was created. It can be found here.