fetchObservable()
Observable-based Fetch API that automatically refreshes data and notifies subscribers.
Features
- Uses the standard Fetch API.
- Uses Observable syntax from ES Observable proposal.
- Runs in Node and browsers. (BYO Fetch API and Promises polyfills though)
Installation
npm install --save fetch-observable
Usage
import fetchObservable from "fetch-observable";
const liveFeed = fetchObservable(
"http://example.org/live-feed.json",
{
fetch: fetch,
refreshDelay: (iteration) => iteration * 1000,
method: "POST"
}
).map((response) => response.json());
const subscription1 = liveFeed.subscribe({
next (response) {
console.dir(response.json());
},
error (error) {
console.warn(error.stack || error);
}
});
const subscription2 = liveFeed.subscribe({next () {}});
liveFeed.pause();
liveFeed.resume();
subscription1.unsubscribe();
subscription2.unsubscribe();
Let's start one together! After you ★Star this project, follow me @Rygu
on Twitter.
License
BSD 3-Clause license. Copyright © 2015, Rick Wong. All rights reserved.