Skip to content

Instantly share code, notes, and snippets.

@whisher
Created March 5, 2019 13:05
Show Gist options
  • Save whisher/ed7fad26076d40268baeea8d4fcd010e to your computer and use it in GitHub Desktop.
Save whisher/ed7fad26076d40268baeea8d4fcd010e to your computer and use it in GitHub Desktop.
export interface State {}
const state: State = {};
export class Store {
private subject = new BehaviorSubject<State>(state);
private store = this.subject.asObservable().distinctUntilChanged();
get value() {
return this.subject.value;
}
select<T>(name: string): Observable<T> {
return this.store.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