redux-api
Redux-api is a library which can easily write client to communicate with backends. It generates actions and selectors for making ajax calls to API endpoint. Also, it use saga to change ajax state and save result in redux store with few config.
Use
Config reducer
Redux-api provide two reducers: Api reducer and Entities reducer;
Api reducer store api state: result, loading, request Entities reducer store entities of normalizr
// reducer.js; ;; /** * apiReducers: {api: apiReducer, entities: entitiesReducer} * */ ...apiReducers;
Config saga
// saga.js;; { ;}
Write an endpoint function of an api
; // endpoint function param is request action payload { const query headers = req; // also can user other ajax tools, should return a promise return ;}
Register api in actions
// actions.js; const listPets = ;
Dispatch action
... { // dispatch a request action thisprops;} { // refresh action means repeat last request action thisprops;} { // clear action means clear api state in store thisprops;}...
Select api state
;;; @Component {}