1
votes

Hello I have effect which after clicking button dispatch new Action to create something,

@Effect({dispatch: false})
createSomething$ = this._actions$.pipe(
    ofType(
        clientsActions.Create),
    mergeMap((action) => this._service.add(action.payload)
        .pipe(
            tap(() => this._router.navigate(['somewhere'])),
            catchError(error => of())
        ))
);

And this is working well, effect send a request and redirect but now I would like to add, action from other class which is in root module however, when I try to do something like that

@Effect({dispatch: false})
createSomething$ = this._actions$.pipe(
    ofType(
        clientsActions.Create),
    mergeMap((action) => this._service.add(action.payload)
        .pipe(.map(() => ({type: this.otherActions.doAction),
            tap(() => this._router.navigate(['somewhere'])),
            catchError(error => of())
        ))
);

This doesn't work and other actions do nothing, even not displaying in dev tools and now I'm confused what happened. I tried also concatMap etc.

1

1 Answers

0
votes

Use MergeMap and return Array [{type:actionType}]

@Effect({dispatch: false})
createSomething$ = this._actions$.ofType(clientsActions.Create)
.pipe(
    mergeMap((action) => this._service.add(action.payload).pipe(
        mergeMap(() => ([{type: this.otherActions.doAction}]),
        tap(() => this._router.navigate(['somewhere'])),
        catchError(error => of())
        ))
);