Apply payload validation to initial object state
This commit is contained in:
parent
128c55bc52
commit
6ff5c56a2a
|
@ -82,7 +82,7 @@ function calculateDefaults(reducerStructure) {
|
||||||
|
|
||||||
|
|
||||||
function createReducer(objectStructure: StructureType, behaviors: ObjectReducerBehaviors): ObjectReducer {
|
function createReducer(objectStructure: StructureType, behaviors: ObjectReducerBehaviors): ObjectReducer {
|
||||||
const initialState = calculateDefaults(objectStructure().structure);
|
const initialState = validateObject(objectStructure, calculateDefaults(objectStructure().structure));
|
||||||
return (state = initialState, { type, payload }: ObjectReducerAction) => {
|
return (state = initialState, { type, payload }: ObjectReducerAction) => {
|
||||||
//If the action type does not match any of the specified behaviors, just return the current state.
|
//If the action type does not match any of the specified behaviors, just return the current state.
|
||||||
if (!behaviors[type]) return state;
|
if (!behaviors[type]) return state;
|
||||||
|
|
Loading…
Reference in New Issue