Created
December 3, 2019 19:47
-
-
Save reed-lawrence/17e0f22bbe9c428cc9d6cdfb22a97736 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 { User, IUser } from '../classes/user' | |
import { Subject } from 'rxjs'; | |
export interface IGlobalComponentState { | |
user: IUser; | |
} | |
export class GlobalComponentState implements IGlobalComponentState { | |
private _user: User = new User(); | |
onUserChanges = new Subject<User>(); | |
get user() { | |
return this._user; | |
} | |
set user(val: User) { | |
console.log('new user emitted'); | |
this._user = val; | |
this.onUserChanges.next(this._user); | |
} | |
constructor(init?: Partial<IGlobalComponentState>) { | |
if (init) { | |
if (init.user) { this.user = new User(init.user); } | |
} | |
} | |
} | |
export const GLOBAL_COMPONENT_STATE = new GlobalComponentState(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment