Skip to content

Instantly share code, notes, and snippets.

@hpstuff
Created February 14, 2018 09:31
Show Gist options
  • Save hpstuff/84b6ffcc6800cb990cdc2988cd2fb034 to your computer and use it in GitHub Desktop.
Save hpstuff/84b6ffcc6800cb990cdc2988cd2fb034 to your computer and use it in GitHub Desktop.
class Test {
tokens$: Observable;
message$: Observable;
constructor() {
this.tokens = Observable.create((observer) => {
this.getToken(observer);
this.messaging.onTokenRefresh(() => this.getToken(observer));
});
this.message = Objeservable.fromEvent(this.messaging, 'onMessage');
}
getToken(observer) {
this.messaging.getToken()
.then((token) => observer.next(token))
.catch((e) => throw new Error(e));
}
}
constructor(private Test) {
}
method() {
this.subrscriber = this.Test.tokens$.subscribe((token)=> /*Send token*/, (err) => /*catch error*/);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment