piral-core
Version:
The core library for creating a Piral instance.
19 lines • 750 B
JavaScript
import create from 'zustand';
import { createDefaultState } from '../../app.codegen';
function extend(defaultState, customState) {
for (const key of Object.keys(customState)) {
if (key === '__proto__' || key === 'constructor') {
continue;
}
const value = customState[key];
const original = defaultState[key];
const nested = typeof original === 'object' && typeof value === 'object';
defaultState[key] = nested ? extend(original, value) : value;
}
return defaultState;
}
export function createGlobalState(customState = {}) {
const defaultState = createDefaultState();
return create(() => extend(defaultState, customState));
}
//# sourceMappingURL=createGlobalState.js.map