https://github.com/woolyang/woox
轻量便捷数据流管理封装库,基于react+redux-saga
https://github.com/woolyang/woox
Last synced: 12 months ago
JSON representation
轻量便捷数据流管理封装库,基于react+redux-saga
- Host: GitHub
- URL: https://github.com/woolyang/woox
- Owner: WoolYang
- License: mit
- Created: 2018-05-07T14:05:17.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-06-28T12:39:44.000Z (almost 8 years ago)
- Last Synced: 2025-06-25T22:17:30.800Z (12 months ago)
- Language: JavaScript
- Homepage:
- Size: 28.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# woox
轻量便捷数据流封装管理库,基于react+redux-saga
## 1.安装
npm install woox --save
## 2.使用
```js
//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挂载组件即可。
```js
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原汁原味的开发体验。