Skip to content
/ woox Public

轻量便捷数据流管理封装库,基于react+redux-saga

License

Notifications You must be signed in to change notification settings

WoolYang/woox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

woox

Travis CI Status Version

轻量便捷数据流封装管理库,基于react+redux-saga

1.安装

npm install woox --save

2.使用

 //index.js
  import { App } from 'woox';
  import * as Models from './models/index';
  App.model(Models);
  
  App.run(Routes,document.getElementById('app'), true);

woox集成react+redux-sagas完成大量配置工作,运行woox仅需引入App,调用model API加载models,run挂载组件即可。

import { getCheckLogin } from '../../api/api';
export default {
   namespace:'login',
   state:  {
       data: null,     
       fetching: false,
       fetched: false,
       error: null
   },
   reducer: {
       loginStart(state) {
           return { ...state, fetching: true };
       },
       loginSuccess(state, { payload }) {
           return { ...state, fetching: false, fetched: true, data: payload };
       },
       loginFailure(state, { payload }) {
           return { ...state, fetching: false, error: payload };
       }
   },
   effects: {
       *loginRequest({ call, put }, { payload }) {
           try {
               yield put({ type: 'loginStart' });
               const data = yield call(getCheckLogin, { ...payload });
               yield put({ type: 'loginSuccess', payload: data });
           } catch (e) {
               yield put({ type: 'loginFailure', payload:e });
           }
       }
   }
};

model文件整合了reducer和effects,减少胶水代码的同时保证了redux原汁原味的开发体验。

About

轻量便捷数据流管理封装库,基于react+redux-saga

Resources

License

Stars

Watchers

Forks

Packages

No packages published