Skip to content

Commit bb886e2

Browse files
author
Your Name
committed
NgRx - The Complete Guide
1 parent 32515fd commit bb886e2

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/app/auth/auth.effects.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
import {Injectable} from '@angular/core';
2-
import {Actions, createEffect} from '@ngrx/effects';
2+
import {Actions, createEffect, ofType} from '@ngrx/effects';
3+
import {AuthActions} from './action-types';
4+
import {tap} from 'rxjs/operators';
35

46

57
@Injectable()
68
export class AuthEffects {
79

8-
constructor(private actions$: Actions) {
9-
10-
actions$.subscribe(action => {
11-
12-
if (action.type == '[Login Page] User Login') {
10+
login$ = createEffect(() =>
11+
this.actions$
12+
.pipe(
13+
ofType(AuthActions.login),
14+
tap(action => localStorage.setItem('user',
15+
JSON.stringify(action.user))
16+
)
17+
)
18+
,
19+
{dispatch: false});
1320

14-
localStorage.setItem('user',
15-
JSON.stringify(action["user"]));
16-
}
1721

18-
19-
});
22+
constructor(private actions$: Actions) {
2023

2124
}
2225

0 commit comments

Comments
 (0)