Last active
July 30, 2018 04:17
-
-
Save DingWeizhe/98cfc3784d667d9225347284b570bcde to your computer and use it in GitHub Desktop.
Rxjs
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
public company$ = this.tokenService.account$ | |
.pipe(flatMap(account => account ? this._fetchCompany(account.companyId) : null)) | |
.pipe(shareReplay()); |
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
public token$ = new BehaviorSubject<string>(""); | |
public account$ = this.token$ | |
.pipe(map(token => this._decodeToken(token))) | |
.pipe(shareReplay(1)); | |
async public login(account: string, password: string) { | |
let token = await this._fetchAccount(account, password); | |
if (!token) throw "帳號或密碼錯誤"; | |
this.token$.next(token); | |
} | |
public logout () { | |
this.token$.next(""); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment