【发布时间】:2019-03-06 23:17:34
【问题描述】:
我正在 Angular 中尝试 NgRx (redux) 和下面示例中的 ...state,我无法完全理解。我搜索了一下,一般理解为spread,但不知道为什么Interface State中的数据属性在reducer的switch的return{}块中重复,因为...会spread em> 他们呢?谁能帮我理解一下?
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:我查看了线程here 并且通常认为传播正是这样做的,传播了。但这里在 Redux/NgRx 的上下文中,试图理解为什么 return{} 有 ...state 和三个附加属性。
【问题讨论】:
-
听起来应该只包含
sessionData,而不是...state,假设State只包含这些属性而没有其他属性
标签: javascript angular ngrx-store