Я получил следующий код из файла эффектов NgRx:
registerUser$: Observable<Action> = createEffect(() =>
this.actions$.pipe(
ofType(AuthStoreActions.registerUser),
switchMap(action => {
return this.authService.registerWithEmailAndPassword(action.userCredentials).pipe(
map(() => AuthStoreActions.authSuccess({ navigateTo: "authentication/restaurant" })),
catchError(error => of(AuthStoreActions.setError({ error })))
);
})
)
);
loginUser$: Observable<Action> = createEffect(() =>
this.actions$.pipe(
ofType(AuthStoreActions.loginUser),
switchMap(action => {
return this.authService.loginWithEmailAndPassword(action.userCredentials).pipe(
map(() => AuthStoreActions.authSuccess({ navigateTo: "authentication/restaurant" })),
catchError(error => of(AuthStoreActions.setError({ error })))
);
})
)
);
После вызова службы оба делают одно и то же. Как можно устранить повторение? У меня есть и другие родственные эффекты, которые делают больше после получения ответа от сервера, чем в этом примере, но кроме метода, который они вызывают, они делают то же самое.