action``reducer``saga
。分層解耦
,不耐煩的建立一個又一個模板文件。action``reducer``saga
。action
和reducer
。saga
,又不破壞原有的耦合特性,故採用約定大於配置,在action的方法名前加_
的方式。action``reducer``saga
的功能集中於一處,不須要任何的附加api學習成本。建立配置html
@注: 使用ts及class是爲了代碼提示方便,若是不須要可參考js版npm
import {creator, BaseConfig} from "./reduxFactory";
class Test extends BaseConfig {
namespace = 'test';
initState = {
num: 1
};
add = (payload: {
number: number
}, state?: any) => {
return {
num: state.num + payload.number
}
};
_add = function *() {
yield console.log('啦啦啦');
};
}
export default creator<Test>(new Test());
複製代碼
使用配置編程
// reducer
import { combineReducers } from 'redux'
import Test from "../Test";
export default combineReducers({
test: Test.reducer
})
// saga
import {all} from "redux-saga/effects";
import Test from '../Test';
export default function* () {
yield all([
Test.saga()
]);
};
複製代碼