Skip to content
This repository has been archived by the owner on Feb 8, 2022. It is now read-only.

robinvdvleuten/observable-fetch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

observable-fetch

RxJS Observable wrapped around the WHATWG Fetch API.

NPM version Build Status

Installation

$ yarn add observable-fetch

Alternatively using npm:

$ npm i observable-fetch --save

Usage

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

import fetch from 'observable-fetch';

// action creators
const fetchUser = username => ({ type: FETCH_USER, payload: username });
const fetchUserFulfilled = payload => ({ type: FETCH_USER_FULFILLED, payload });

// epic
const fetchUserEpic = action$ =>
  action$.ofType(FETCH_USER)
    .mergeMap(action =>
      fetch(`https://api.github.com/users/${action.payload}`)
        .map(response => fetchUserFulfilled(response))
    );

// later...
dispatch(fetchUser('torvalds'));

License

MIT © Robin van der Vleuten