Created
February 13, 2019 21:33
-
-
Save whisher/2e98682709cddf4e2255a906a181f84d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@angular/core'; | |
import { select, Store } from '@ngrx/store'; | |
import { Credentials } from '../../models'; | |
import { State } from '../reducers'; | |
import { | |
selectError, | |
selectLoading, | |
selectIsAuthenticated, | |
selectToken | |
} from '../selectors'; | |
import { Login, Logout } from '../actions'; | |
@Injectable({ | |
providedIn: 'root' | |
}) | |
export class AuthFacade { | |
error$ = this.store.pipe(select(selectError)); | |
loading$ = this.store.pipe(select(selectLoading)); | |
isAuthenticated$ = this.store.pipe(select(selectIsAuthenticated)); | |
token$ = this.store.pipe(select(selectToken)); | |
constructor(private store: Store<State>) {} | |
login(credentials: Credentials): void { | |
this.store.dispatch(new Login({ credentials })); | |
} | |
logout(): void { | |
this.store.dispatch(new Logout()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment