Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@ngrx/operators: add mapResponse #4230

Closed
1 of 2 tasks
markostanimirovic opened this issue Feb 2, 2024 · 0 comments · Fixed by #4302
Closed
1 of 2 tasks

@ngrx/operators: add mapResponse #4230

markostanimirovic opened this issue Feb 2, 2024 · 0 comments · Fixed by #4302

Comments

@markostanimirovic
Copy link
Member

markostanimirovic commented Feb 2, 2024

Which @ngrx/* package(s) are relevant/related to the feature request?

operators

Information

Similar to tapResponse, add mapResponse operator to improve response handling in NgRx effects.

Before:

export const loadAllUsers = createEffect((
  actions$ = inject(Actions),
  usersService = inject(UsersService)
) => {
  return actions$.pipe(
    ofType(UsersPageActions.opened),
    exhaustMap(() => {
      return usersService.getAll().pipe(
        map((users) => UsersApiActions.usersLoadedSuccess({ users })),
        catchError((error) =>
          of(UsersApiActions.usersLoadedFailure({ error }))
        )
      );
    })
  );
});

After:

import { mapResponse } from '@ngrx/operators';

export const loadAllUsers = createEffect((
  actions$ = inject(Actions),
  usersService = inject(UsersService)
) => {
  return actions$.pipe(
    ofType(UsersPageActions.opened),
    exhaustMap(() => {
      return usersService.getAll().pipe(
        mapResponse({
          next: (users) => UsersApiActions.usersLoadedSuccess({ users }),
          error: (error) => UsersApiActions.usersLoadedFailure({ error }),
        })
      );
    })
  );
});

Describe any alternatives/workarounds you're currently using

No response

I would be willing to submit a PR to fix this issue

  • Yes
  • No
tom9744 added a commit to tom9744/platform that referenced this issue Apr 17, 2024
tom9744 added a commit to tom9744/platform that referenced this issue May 11, 2024
timdeschryver pushed a commit that referenced this issue May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant