【发布时间】:2018-08-19 21:18:29
【问题描述】:
我的 Angular 5 应用程序基于 NgRx,这是一个类似于 Redux 但基于 RxJS 的状态管理库。
我经常需要根据当前操作的有效负载从存储中获取最新值。
在 RxJS 术语中,这意味着我的主流不断产生项目,并且对于每个新项目,我需要根据项目的值创建一个侧流,从该流中获取最新值,并将其与主流。
目前,我正在做这样的事情:
@Effect()
public moveCursor$: Observable<Action> = this.actions$.pipe(
ofType<TableAction.MoveCursor>(TableActionType.MOVE_CURSOR),
switchMap(action => this.store$.select(selectTableById(action.payload.cursor.tableId)).pipe(
first(),
map(table => ({action, table}))
)),
map(({action, table}) => {
...
})
)
我知道这可能不是最好的解决方案,我正在寻找这样的东西(withLatestFrom 运算符不可能):
@Effect()
public moveCursor$: Observable<Action> = this.actions$.pipe(
ofType<TableAction.MoveCursor>(TableActionType.MOVE_CURSOR),
withLatestFrom(action => this.store$.select(selectTableById(action.payload.cursor.tableId))),
map(([action, table]) => {
...
})
)
所以我的问题是:是否有任何类似于withLatestFrom 的 RxJS 运算符可以将第一个流产生的值作为参数?
【问题讨论】: