January 2019
Beginner
210 pages
4h 47m
English
It is also possible to create an observable that will iterate the arguments of a callback using the bindCallback function:
import { bindCallback } from "rxjs";import fetch from "node-fetch";function getJSON(url: string, cb: (response: unknown|null) => void) { fetch(url) .then(response => response.json()) .then(json => cb(json)) .catch(_ => cb(null));}const uri = "https://jsonplaceholder.typicode.com/todos/1";const observableFactory = bindCallback(getJSON);const observable = observableFactory(uri);const subscription = observable.subscribe( (value) => console.log(value));subscription.unsubscribe();
The preceding example uses the node-fetch module because the fetch function is not available in Node.js. You ...
Read now
Unlock full access