Ngrx 8 - 如果条件具有多个有效的操作,则分派多个 else

Ngrx 8 - dispatch multiple else if conditions with multiple actions in effect

我正在寻找以下情况的解决方案:

 startMultpileActionDepensOnType$ = createEffect(() => this.actions$.pipe(
        ofType(startMultpileActionDepensOnType),
        withLatestFrom(this.store$.select(selectTypeActions)),
        map(([action, select]) => {
                const actionType = select.type.toLowerCase();

                if (actionType === ActionTypeEnum.TYPE_FIRST.toLowerCase()) {
                    return [getInitialDataStatus({statusType: 'disabled'}),
                        fetchImportantDataFirst()];
                } else if (actionType === ActionTypeEnum.TYPE_SECOND.toLowerCase()) {
                    return [getInitialDataStatus({}),
                        fetchImportantDataSecond());
                } else if (actionType === ActionTypeEnum.TYPE_THIRD.toLowerCase()] {
                    return [getInitialDataStatus({}),
                        fetchImportantDataThidr()];
                }
            }
        )
    ));

所以: - 我想 运行 数组中的多个动作, - 并使用多个 else if case

我尝试通过字典修复它...但也许有更好的解决方案。

下面是如何使用object来切割if/else,另外也许这里的枚举比较也可以改进一些东西,它看起来有点尴尬

const functionMap={
[ActionTypeEnum.TYPE_FIRST.toLowerCase()]:[getInitialDataStatus({statusType: 'disabled'}),fetchImportantDataFirst()],
[ActionTypeEnum.TYPE_SECOND.toLowerCase()]:[getInitialDataStatus({}),
                        fetchImportantDataSecond()],
[ActionTypeEnum.TYPE_THIRD.toLowerCase()]:[getInitialDataStatus({}),
                        fetchImportantDataThidr()]
}

 startMultpileActionDepensOnType$ = createEffect(() => this.actions$.pipe(
        ofType(startMultpileActionDepensOnType),
        withLatestFrom(this.store$.select(selectTypeActions)),
        map(([action, select]) => {
                const actionType = select.type.toLowerCase();
                return functionMap[actionType]

            }
        )
    ));