我正在使用 ngrx 并且有一个场景,我需要同时调度 2 个动作。我的状态具有用于更新和更新的属性,如下所示。
//from reducer
const defaultCardState: CardState = {
ids: [],
entities: {},
loaded: false,
loading: false,
adding: false,
added: false,
updating: false,
updated: false,
deleting: false,
deleted: false
};
Run Code Online (Sandbox Code Playgroud)
这些是我从我的组件分派的动作
this.store.dispatch(fromCard.updateCard({id: id1, changes: {name: name1}}))
this.store.dispatch(fromCard.updateCard({id: id2, changes: {name: name2}}))
Run Code Online (Sandbox Code Playgroud)
下面是我的动作,减速器和效果
//Update Card Actions
export const updateCard = createAction('[Cards] Update Card', props<{id: string, changes: any}>())
export const updateCardSuccess = createAction('[Cards] Update Card Success', props<{changes: any}>());
export const updateCardFail = createAction('[Cards] Update Card Fail')
//Reducer
on(fromCards.updateCard, (state) …Run Code Online (Sandbox Code Playgroud)