Created
July 9, 2018 19:38
-
-
Save whisher/97d211e54b290d255ee14482459585ad to your computer and use it in GitHub Desktop.
This file contains hidden or 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 { Observable, BehaviorSubject } from 'rxjs'; | |
| import { distinctUntilChanged, pluck } from 'rxjs/operators'; | |
| import { Profile } from './admin/features/profile/models/profile'; | |
| export interface State { | |
| profile: Profile | |
| } | |
| const state: State = { | |
| profile: undefined | |
| }; | |
| @Injectable({ | |
| providedIn: 'root' | |
| }) | |
| export class AppStore { | |
| private subject = new BehaviorSubject<State>(state); | |
| private store = this.subject.asObservable() | |
| .pipe(distinctUntilChanged()); | |
| get value() { | |
| return this.subject.value; | |
| } | |
| select<T>(name: string): Observable<T> { | |
| return this.store | |
| .pipe(pluck(name)); | |
| } | |
| set(name: string, state: any) { | |
| this.subject.next({ ...this.value, [name]: state }); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment