在 ngrx effect 中一起访问状态和有效负载数据

Access to state and payload data together inside ngrx effect

我在 ngrx 状态下保存了一些小部件实例(第三方非 angular 库),我需要通过用户操作使用新参数更新小部件。对于这种情况,我使用新的小部件参数作为有效负载来发送操作。

是否可以在同一个有效位置获取负载和状态数据而无需额外的私有字段?

@Effect({ dispatch: false })
public updateStatistics: Observable<webChatActions.Actions> = this._actions.pipe(
    ofType(Types.UPDATE_STATISTICS),
    map((action: demoActions.UpdateStatistics) => action.payload),
    tap((payload: StatisticsOptions) => console.log(payload)),
    withLatestFrom(this._store),
    map(([action, state]): DemoEffects => state['web-chat']),
    tap((state: WebChatState) => {
    // here I have my state, but also I need payload from tap above
    }),
    catchError((error: Error) => {
        this._logger.error('unable to update feedback widget', error);
        return of(new webChatActions.Service.ShowChatError(error));
    })
);

删除 map 即可。

@Effect({ dispatch: false })
public updateStatistics: Observable<webChatActions.Actions> = this._actions.pipe(
    ofType(Types.UPDATE_STATISTICS),
    map((action: demoActions.UpdateStatistics) => action.payload),
    tap((payload: StatisticsOptions) => console.log(payload)),
    withLatestFrom(this._store),
    map((): DemoEffects => state['web-chat']),
    tap(([action, state]) => {
      // action.payload 
      // tate['web-chat']
    }),
    catchError((error: Error) => {
        this._logger.error('unable to update feedback widget', error);
        return of(new webChatActions.Service.ShowChatError(error));
    })
);