I want to access state data to pass the results as properties of a new action. I managed to extract the required data from the state after the effect is triggered but the final part dispatching the new action using data isn´t working. I can´t pass the two arguments activeUser and activeTask to the of(GetInstances({activeUser, activeTask})) part in the last line of code.
@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})))
);
How is it possible to pass the two parameters activeUser and activeTask to a new GetInstances Action?
EDIT:
I got it working with the following code. Is this a valid solution for the problem?
@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}))
);