Created
December 9, 2018 20:07
-
-
Save whisher/2baba3e1798533bb0c0efe1d089503e2 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 { AuthState } from '../reducers'; | |
import { | |
selectError, | |
selectLoading, | |
selectLoggedIn, | |
selectToken | |
} from '../selectors'; | |
import { Login, Logout } from '../actions'; | |
@Injectable() | |
export class AuthFacade { | |
error$ = this.store.pipe(select(selectError)); | |
loading$ = this.store.pipe(select(selectLoading)); | |
loggedIn$ = this.store.pipe(select(selectLoggedIn)); | |
token$ = this.store.pipe(select(selectToken)); | |
constructor(private store: Store<AuthState>) {} | |
login(credentials: Credentials) { | |
this.store.dispatch(new Login({ credentials })); | |
} | |
logout() { | |
this.store.dispatch(new Logout()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment