Typescript 在rxjs效果中将数据从状态传递到新操作

Typescript 在rxjs效果中将数据从状态传递到新操作,typescript,rxjs,ngrx,Typescript,Rxjs,Ngrx,我想访问状态数据以将结果作为新操作的属性传递。我设法在效果触发后从状态中提取所需的数据,但使用数据调度新操作的最后部分不起作用。我无法将两个参数activeUser和activeTask传递给最后一行代码中的(GetInstances({activeUser,activeTask}))部分 @Effect() updateInstanceLabelSuccess$ = this._actions$.pipe( ofType<Action>(EInstanceActions.Upd

我想访问状态数据以将结果作为新操作的属性传递。我设法在效果触发后从状态中提取所需的数据,但使用数据调度新操作的最后部分不起作用。我无法将两个参数
activeUser
activeTask
传递给最后一行代码中的
(GetInstances({activeUser,activeTask}))
部分

@Effect()
updateInstanceLabelSuccess$ = this._actions$.pipe(
  ofType<Action>(EInstanceActions.UpdateInstanceLabelSuccess),
  concatMap(action => of(action).pipe(
    withLatestFrom(combineLatest(
      [this._userStore.pipe(select(selectActiveUser)),
        this._userStore.pipe(select(selectActiveTask))]
    ))
  )),
  tap(([action, [activeUser, activeTask]]: [Action, [User, Task]]) => {
    console.log(activeUser, activeTask);
    // activeUer and activeTask successfully loaded
    // pass activeUser + activeTask to props of Action GetInstances
  }),
  // activeUser and activeTask can´t be passed to new GetInstances Action
  switchMap(([action, [activeUser, activeTask]]: [Action, [User, Task]]) => of(GetInstances({activeUser, activeTask})))
);

这段代码看起来很棒,是一种非常有效的方法

除非我遗漏了什么,否则我想你可以清理一下,比如:

@Effect()
updateInstanceLabelSuccess$ = this._actions$.pipe(
    ofType<Action>(EInstanceActions.UpdateInstanceLabelSuccess),
    withLatestFrom(
        this._userStore.pipe(select(selectActiveUser)),
        this._userStore.pipe(select(selectActiveTask)),
        (action, activeUser, activeTask) => [activeUser, activeTask]
    ),
    map(([activeUser, activeTask]): [User, Task]) => GetInstances({userID: activeUser.id, taskID: activeTask.id}))
);
@Effect()
updateInstanceLabelSuccess$=this.\u actions$.pipe(
类型,包括一个最终投影函数,我发现它在不想执行无关操作的情况下很有用

另一个建议是创建一个新的选择器,将您现有的两个选择器组合在一起。我知道这听起来有些过分,但这样做会给您带来一点性能优势,因为选择器结果内置了缓存


无论如何,我希望这能有所帮助。在解决这个问题上做得很好。

您是遇到了错误还是操作没有任何有效负载?对于更新的问题:您的实现对我来说似乎很好,很好,现在可以工作了:)您的代码看起来非常干净,工作正常,谢谢您的提示
@Effect()
updateInstanceLabelSuccess$ = this._actions$.pipe(
    ofType<Action>(EInstanceActions.UpdateInstanceLabelSuccess),
    withLatestFrom(
        this._userStore.pipe(select(selectActiveUser)),
        this._userStore.pipe(select(selectActiveTask)),
        (action, activeUser, activeTask) => [activeUser, activeTask]
    ),
    map(([activeUser, activeTask]): [User, Task]) => GetInstances({userID: activeUser.id, taskID: activeTask.id}))
);