updux/src/initialState.ts
2024-08-08 09:28:44 -04:00

17 lines
418 B
TypeScript

import u from '@yanick/updeep-remeda';
import { D } from '@mobily/ts-belt';
export function buildInitialState(localInitialState, subduxes) {
let state = localInitialState ?? {};
if (subduxes) {
if (typeof state !== 'object') {
throw new Error('root initial state is not an object');
}
state = u(state, D.map(subduxes, D.prop('initialState')));
}
return state;
}