I’m working with ngrx and this is my initialState:
JavaScript
x
41
41
1
export interface Bonus110State {
2
agent: Agent;
3
isEdited: boolean;
4
isResetted: boolean;
5
steps: Step[];
6
response: ResponseReport;
7
customer: any | null;
8
address: Address | null;
9
error: boolean | null;
10
}
11
12
export const initialState: Bonus110State = {
13
agent: {
14
name: null,
15
eta: null
16
},
17
customer: null,
18
response: {
19
responseCode: null,
20
responseMessage: null
21
},
22
address: {
23
isset: false,
24
id: null,
25
street: null,
26
streetNumber: null,
27
city: null,
28
cap: null,
29
province: null,
30
firstname: null,
31
lastname: null,
32
vat: null,
33
taxid: null,
34
business_name: null
35
},
36
isEdited: false,
37
isResetted: false,
38
steps: [environment.initialStateMap],
39
error: null
40
};
41
i need reinitialize the state feature. This is my reducer’s case:
JavaScript
1
7
1
case Bonus110ActionTypes.CLEAR_BONUS110_STATE: {
2
const newState = Object.assign({}, initialState);
3
newState.isResetted = true;
4
console.log('NEWSTATE', newState);
5
6
return newState;
7
I’m expecting that this reducer, clean my feature state, returning it equal to the initialState.
But the state dosen’t change. If i log the initialState, it is equal to the actual state
The only way I can reset it is doing this before the reducer inizialization
JavaScript
1
3
1
const initialStateCloned: Bonus110State = _cloneDeep(initialState);
2
3
and then
JavaScript
1
7
1
case Bonus110ActionTypes.CLEAR_BONUS110_STATE: {
2
const newState = Object.assign({}, initialStateCloned);
3
newState.isResetted = true;
4
console.log('NEWSTATE', newState);
5
6
return newState;
7
I’m using the metareducer to clear all the state, and it is working well. but in this case i need to clear only this slice of state. i’m struggling on this from a while.