Skip to content

Instantly share code, notes, and snippets.

@whisher
Created December 9, 2018 20:07
Show Gist options
  • Save whisher/2baba3e1798533bb0c0efe1d089503e2 to your computer and use it in GitHub Desktop.
Save whisher/2baba3e1798533bb0c0efe1d089503e2 to your computer and use it in GitHub Desktop.
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