Last active
May 9, 2020 15:15
-
-
Save splincode/980c4f4c25ea631a1a9480980b836e97 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 { BehaviorSubject, Observable } from 'rxjs'; | |
import { Injectable } from '@angular/core'; | |
@Injectable() | |
export abstract class Store<T> { | |
private _state$: BehaviorSubject<T>; | |
protected constructor(defaults: T) { | |
this.state$ = new BehaviorSubject(defaults); | |
} | |
public get state$(): Observable<T> { | |
return this._state$.asObservable(); | |
} | |
public getState(): T { | |
return this._state$.getValue(); | |
} | |
public setState(nextState: T): void { | |
this._state$.next(nextState); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment