>我在 ngrx 状态中保存了一些小部件实例(第三方非角度库(,我需要通过用户操作使用新参数更新小部件。在这种情况下,我使用新的小部件参数作为有效负载来调度操作。
是否可以在没有额外私有字段的情况下在同一位置获取有效载荷和状态数据?
@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));
})
);