Created
February 2, 2018 09:24
-
-
Save ValentinFunk/670578d2ea2941a01b545952721f174c to your computer and use it in GitHub Desktop.
Firebase Universal Example
This file contains hidden or 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
| @Injectable() | |
| export class UserService { | |
| constructor(private db: AngularFireDatabase, private zone: NgZone) {} | |
| getUser(id: string | number): Observable<User> { | |
| const user$ = this.database.object('profiles/' + id); | |
| this.universalBlockUntilFirst(user$); | |
| return user$; | |
| } | |
| private universalBlockUntilFirst(obs: Observable<any>) { | |
| if (SERVER) { | |
| const task = Zone.current.scheduleMacroTask('universalBlockUntilFirst', () => { }, {}, () => { }, () => { }); | |
| obs.first().subscribe(() => this.zone.runOutsideAngular(() => task.invoke())); | |
| } | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment