const createStore = (reducer) => {
let state;
let listeners = [];
const getState = () => state;//这里的箭头函数转换成一般的函数是这样的吗?const getState=function(){return state;}
const dispatch = (action) => {
state = reducer(state, action);
listeners.forEach(listener => listener());//这部分代码是什么意思,箭头函数怎么转换?
};
const subscribe = (listener) => {
listeners.push(listener);
return () => {
listeners = listeners.filter(l => l !== listener);//想问下这里的箭头函数转换成一般的函数是什么样的?listeners.filter是什么意思
}
};
dispatch({});
return { getState, dispatch, subscribe };};
目前暂无任何回答
- 0 回答
- 0 关注
- 2596 浏览
添加回答
举报
0/150
提交
取消