updux/src/selectors.ts

11 lines
360 B
TypeScript
Raw Normal View History

2024-08-08 13:28:44 +00:00
import { D } from '@mobily/ts-belt';
2023-09-06 19:09:45 +00:00
export function buildSelectors(localSelectors = {}, subduxes = {}) {
const subSelectors = (Object.entries(subduxes) as any).map(
([slice, { selectors }]) =>
2024-08-08 13:28:44 +00:00
D.map(selectors, (subSelect) => (state) => subSelect(state[slice])),
2023-09-06 19:09:45 +00:00
);
2024-08-08 13:28:44 +00:00
return [localSelectors, ...subSelectors].reduce(D.merge);
2023-09-06 19:09:45 +00:00
}