Last active
March 2, 2017 22:23
-
-
Save timsuchanek/4db1c5beb55a51f7f659be66bad0c8a4 to your computer and use it in GitHub Desktop.
Observe Subscriptions
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 { Observable } from 'rxjs/Observable' | |
import { SubscriptionClient } from 'subscriptions-transport-ws' | |
const ws = new SubscriptionClient("endpointurl") | |
const observable = Observable.create(observer => { | |
const id = this.ws.subscribe(graphQLParams, (err, res) => { | |
if (err) { | |
observer.next(res) | |
observer.unsubscribe() | |
} | |
observer.next(res) | |
}) | |
return () => { | |
ws.unsubscribe(id) | |
} | |
}) | |
const subscription = observable.subscribe({ | |
next: data => { | |
console.log('data', data) | |
}, | |
error: error => { | |
console.error(error) | |
}, | |
complete: () => { | |
console.log('subscription complete') | |
}, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment