18 lines
532 B
TypeScript
18 lines
532 B
TypeScript
import { isPlainObject, mapValues } from 'lodash';
|
|
import u from 'updeep';
|
|
|
|
export function buildInitial(initial, subduxes = {}) {
|
|
if (!isPlainObject(initial) && Object.keys(subduxes).length > 0)
|
|
throw new Error(
|
|
"can't have subduxes on a dux which state is not an object"
|
|
);
|
|
|
|
if (Object.keys(subduxes).length === 1 && subduxes['*']) return initial;
|
|
|
|
const subInitial = mapValues(subduxes, ({ initial }, key) =>
|
|
key === '*' ? [] : initial
|
|
);
|
|
|
|
return u(initial, subInitial);
|
|
}
|