updux/src/initialState.ts

17 lines
418 B
TypeScript
Raw Normal View History

2023-09-06 19:09:45 +00:00
import u from '@yanick/updeep-remeda';
2024-08-08 13:28:44 +00:00
import { D } from '@mobily/ts-belt';
2023-09-06 19:09:45 +00:00
export function buildInitialState(localInitialState, subduxes) {
let state = localInitialState ?? {};
if (subduxes) {
if (typeof state !== 'object') {
throw new Error('root initial state is not an object');
}
2024-08-08 13:28:44 +00:00
state = u(state, D.map(subduxes, D.prop('initialState')));
2023-09-06 19:09:45 +00:00
}
return state;
}