0.1.1 • Published 7 years ago

redux-rxjs v0.1.1

Weekly downloads
5
License
MIT
Repository
github
Last release
7 years ago

redux-rxjs

  • RxJS 5-based middleware for Redux. Compose and cancel async actions to create side effects and handle promise more.
  • if you need redux-observable and redux-promise-middleware in redux , the redux-rxjs is a better choice, you only need this one in redux porject,you can solve the problem.
  • the source code of redux-rxjs is added some features on the basis of the source code of redux-observable,the new feature is handling of promise.
  • redux-rxjs is fully compatible with redux-observable, you can replace the use of redux-rxjs.
  • redux-rxjs API is the same as redux-observable API,please read https://redux-observable.js.org for some detail
  • The following is only for new features

Install

$ npm install --save-dev redux-rxjs

simply replace

import { createEpicMiddleware,combineEpics,ActionsObservable } from 'redux-observable';

// replace

import { createEpicMiddleware,combineEpics,ActionsObservable } from 'redux-rxjs';

Usage

incomplete code is as follows :

      const reducer = (state = [], action) => state.concat(action);
      const epic = (action$, store) =>
        mergeStatic(
          action$.ofType('FIRE_1')::mapTo({ type: 'ACTION_1' }),
          action$.ofType('FIRE_2')::mapTo({ type: 'ACTION_2' })
        );
       
      const middleware = createEpicMiddleware(epic);
      const store = createStore(reducer, applyMiddleware(middleware));
      
      let data={
        type: 'FIRE_1' ,
        payload : Promise.reject('promise fail') ,
        handleReject : error =>{
            store.getState();
            throw error;
        },
        handleFulfill : response=>{
      // document.getElementById(id).innerHTML=response.payload;
      // console.log(response)
        },
        website :"www.github.com",
        id :"001-001"
      };

      store.dispatch(data);

the action need these :

payload : need to handle promise

handleFulfill : success callback, you can get arguments, the arguments is a action ,the action.payload already handled

handleReject : fail callback, you can get arguments, the arguments is error object

if the action.payload is not a promise object , the program running is same as redux-observable. the promise object reject , throw error , if you set handleReject , the error is catched, or the error appear in console, but program still running

learn more , please read github

UMD

publish a UMD build inside npm package.

License

MIT © hwep