Created
January 11, 2020 07:48
-
-
Save fireflysemantics/465c1dd13ea7e541bab4625536cb650f 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 { Injectable, OnDestroy } from '@angular/core' | |
import { OStore} from '@fireflysemantics/slice' | |
import { Observable } from 'rxjs' | |
import { MenuItems} from './model' | |
import { untilDestroyed } from 'ngx-take-until-destroy' | |
export const ACTIVE_MENU = "ACTIVE_MENU" | |
export const AUTHENTICATED = "AUTHENTICATED" | |
export const SAVED = "SAVED" | |
@Injectable({providedIn: 'root'}) | |
export class AppStateService implements OnDestroy { | |
public authenticated = false | |
public os:OStore = new OStore() | |
public activeMenu$:Observable<string> | |
public authenticated$:Observable<boolean> | |
public saved$:Observable<boolean> | |
constructor() { | |
this.os.post(ACTIVE_MENU, MenuItems.NONE) | |
this.os.post(AUTHENTICATED, false) | |
this.os.post(SAVED, false) | |
this.activeMenu$ = this.os.observe(ACTIVE_MENU) | |
this.authenticated$ = this.os.observe(AUTHENTICATED) | |
this.saved$ = this.os.observe(SAVED) | |
//this.activeMenu$.pipe(untilDestroyed(this)).subscribe(m=>console.log(m)) | |
//this.authenticated$.pipe(untilDestroyed(this)).subscribe(auth=>console.log(`Authenticated: ${auth}`)) | |
} | |
login() { | |
this.authenticated = true; | |
this.os.put(AUTHENTICATED,this.authenticated) | |
} | |
logout() { | |
this.authenticated = false; | |
this.os.put(AUTHENTICATED,this.authenticated) | |
} | |
save() { | |
this.os.put(SAVED, true) | |
} | |
ngOnDestroy() {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment