4

I am currently using ngrx in my app to manage state. I was looking at switching to ngrx-data for the simple CRUD operations and ran across my first question. This is my current regular ngrx effect and I want to know how to reproduce it with ngrx-data (create new action based on http response):

@Effect()
insertUser$: Observable<Action> = this.action$.pipe(
    ofType(UsersActionTypes.UserInsert),
    map((action: UserInsert) => action.payload),
    mergeMap(payload =>
        this.UserService.insert(<IUserPersistRequest>{
            user: payload.User,
            refreshToken: payload.loggedInUser.RefreshToken
        }).pipe(
            map((response: IUserPersistResponse) => {
                return !response.accessToken
                        ? new UserPersistSuccessLoginFailure()
                        : new UserInsertSuccess({
                            response: response,
                            User: payload.User
                        });
            }),
            catchError((error: string) => {
                return of(new UserInsertFailure('UserInsert Failed'));
            })
        )
    )
);

Any advice?

samneric
  • 3,038
  • 2
  • 28
  • 31

0 Answers0