My goal is to access state data and use it as properties for a new action. I successfully extracted the necessary data from the state after triggering the effect, but I am facing an issue when dispatching the new action with the data. It seems that I am unable to pass the arguments activeUser
and activeTask
to the
of(GetInstances({activeUser, activeTask}))
part in the final 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})))
);
Is there a way to effectively pass the parameters activeUser
and activeTask
to a new GetInstances
Action?
EDIT:
I managed to resolve the issue with the following code snippet. Would this be considered a valid solution to 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}))
);