1
votes

In store I have several array, string etc.

export const INITIAL_TEST_STORE: TestState = {
    one: null,
    two: null,
    three: false,
    four: {},
};

And above, you can see initial state values - all are working properly.

But when I dispatched clear action (and setting initial state):

on(clearState, state => ({
    ...INITIAL_TEST_STORE
})),

the four node has still old value, not empty {}

If I dispatch below action:

on(clearState, state => ({
    ...INITIAL_TEST_STORE,
    four: {}
})),
    

Everything is clear properly. And I am wondering why? The problem is with immutable? But... it is that same...

2

2 Answers

1
votes

Is INITIAL_TEST_STORE updated somewhere else in the codebase? You can make sure of it if you debug the reducer.

fyi, you can also just return INITIAL_TEST_STORE without the spread operator, but that won't change the outcome.

1
votes

Spread operator does the Shallow copy of the object, four is the nested level object and spread operator will not reset it.

on(clearState, state => ({
    ...INITIAL_TEST_STORE
    four: { ...INITIAL_TEST_STORE.four }
})),

snippet about should reset the state.