react中对于redux的封装

const createStore = (reducer)=>{
//默认的state对象
let state = {}; //将所有订阅的事件存在在这个数组中
let listeners = []; //默认的action
let actionTypes = "@@redux/INIT";
let Initaction = {
type:actionTypes
} const dispatch = (action=Initaction)=>{
state = reducer(state,action);
listeners.map(cb=>{
cb();
})
}
dispatch(); const getState = ()=>state; const subscribe = (cb)=>{
listeners.push(cb);
} return {
dispatch,
getState,
subscribe
}
} const combineReducers = (reducers)=>{ const newState = {}; return function(state,action){
for(let key in reducers){
let reduce = reducers[key]; console.log(newState[key])
newState[key] = reduce(state[key],action);
}
return newState;
}
} export {createStore,combineReducers}
上一篇:让Myeclipse自动生成的get set方法 自动加上文本注释,并且注释内容包含字段中我们加的文档注释


下一篇:UITableView的编辑操作