I'm trying out NgRx (redux) in Angular and the ...state
in the example below, I can not fully understand. I searched for it and generally understood it as spread, but not sure why the data attributes in the Interface State
are repeated in the return{}
block of the reducer's switch
, as the ... would spread them anyway? Can anyone help me understand this please?
export interface State {
sessionData: Map<string, string>;
requesting: boolean;
hasError: boolean;
status: StatusModel;
}
export function sessionReducer(state: State = INITIAL_STATE, action: Session.Actions): State {
switch (action.type) {
case Session.REQUEST_SESSION_DATA:
return {
...state,
requesting: true,
hasError: false,
status: undefined,
};
}
}
PS: I've looked at the thread here and generally get that spread does exactly that, spread out. But here in the context of Redux/NgRx, trying to understand why the return{}
has ...state
and the three additional properties.