项目作者: robinvdvleuten

项目描述 :
🔋 RxJS Observable wrapped around the WHATWG Fetch API.
高级语言: JavaScript
项目地址: git://github.com/robinvdvleuten/observable-fetch.git
创建时间: 2017-05-11T11:58:54Z
项目社区:https://github.com/robinvdvleuten/observable-fetch

开源协议:MIT License

下载


observable-fetch

RxJS Observable wrapped around the WHATWG Fetch API.

NPM version
Build Status

Installation

  1. $ yarn add observable-fetch

Alternatively using npm:

  1. $ npm i observable-fetch --save

Usage

This library is especially built to be complementary to redux-observable;

  1. import fetch from 'observable-fetch';
  2. // action creators
  3. const fetchUser = username => ({ type: FETCH_USER, payload: username });
  4. const fetchUserFulfilled = payload => ({ type: FETCH_USER_FULFILLED, payload });
  5. // epic
  6. const fetchUserEpic = action$ =>
  7. action$.ofType(FETCH_USER)
  8. .mergeMap(action =>
  9. fetch(`https://api.github.com/users/${action.payload}`)
  10. .map(response => fetchUserFulfilled(response))
  11. );
  12. // later...
  13. dispatch(fetchUser('torvalds'));

License

MIT © Robin van der Vleuten