【发布时间】:2020-05-12 07:26:03
【问题描述】:
我想访问状态数据以将结果作为新操作的属性传递。在触发效果后,我设法从状态中提取所需的数据,但使用数据调度新操作的最后部分不起作用。我不能将activeUser 和activeTask 这两个参数传递给最后一行代码中的of(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})))
);
如何将activeUser 和activeTask 这两个参数传递给新的GetInstances Action?
编辑:
我得到它使用以下代码。这是解决问题的有效方法吗?
@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))]
))
)),
map(([action, [activeUser, activeTask]]: [Action, [User, Task]]) => GetInstances({userID: activeUser.id, taskID: activeTask.id}))
);
【问题讨论】:
-
您收到错误消息还是该操作没有任何有效负载?
-
对于更新后的问题:您的实现对我来说似乎很好,现在很好用 :)
标签: typescript rxjs ngrx