带有两个不同动作的异化器的和数

时间:2019-02-27 16:06:02

标签: angular ngrx-store

我在我的项目中使用ngrx-store。我得到了一个类似belom的减速器,可以处理两个不同的动作。动作的有效负载是任务数。我想总结一下值发出时两个动作的数量。

在组件中,我分别分派了动作。因此,发出的值将被异步记录。

如何将两个发射值的结果相加?

export function countTaskReducer(state = {},
                                        action: CountAssignedSuccessAction | CountPooledSuccessAction) {
    switch (action.type) {
        case COUNT_ASSIGNED_REQUISITIONS_SUCCESS:
            return {...state, ...action.payload};
        case COUNT_POOLED_REQUISITIONS_SUCCESS:
            return {...state, ...action.payload};
        default: {
            return state;
        }
    }
}


export class CountAssignedSuccessAction implements Action {
    readonly type: string = COUNT_ASSIGNED_SUCCESS;

    constructor(public payload: {count:number}) {
    }
}

export class CountPooledSuccessAction implements Action {
    readonly type: string = COUNT_POOLED_SUCCESS;

    constructor(public payload: {count:number}) {
    }
}

1 个答案:

答案 0 :(得分:0)

这是你想要的吗?

{...state, count: state.count+ action.payload.count}