Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save wesleygrimes/f95dc16a1793bce388f1a32bfe1f1e24 to your computer and use it in GitHub Desktop.
Save wesleygrimes/f95dc16a1793bce388f1a32bfe1f1e24 to your computer and use it in GitHub Desktop.
Standard Feature Store Module - Effects
import { Injectable } from '@angular/core';
import { Actions, Effect, ofType } from '@ngrx/effects';
import { Action } from '@ngrx/store';
import { Observable, of as observableOf } from 'rxjs';
import { catchError, map, startWith, switchMap } from 'rxjs/operators';
import { DataService } from '../../services/data.service';
import * as featureActions from './actions';
@Injectable()
export class MyFeatureStoreEffects {
constructor(private dataService: DataService, private actions$: Actions) {}
@Effect()
loginRequestEffect$: Observable<Action> = this.actions$.pipe(
ofType<featureActions.LoginRequestAction>(
featureActions.ActionTypes.LOGIN_REQUEST
),
switchMap(action =>
this.dataService
.login(action.payload.userName, action.payload.password)
.pipe(
map(
user =>
new featureActions.LoginSuccessAction({
user
})
),
catchError(error =>
observableOf(new featureActions.LoginFailureAction({ error }))
)
)
)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment