Redux底层源码
- 底层就是发布与订阅模式
const creareStore = (reducer)=> {
let list = [];
let state = reducer()
const subscribe = (callback)=> {
list.push(callback)
}
const dispatch = (action)=> {
state = reducer(state, action)
list.forEach((itemCallback)=> {
itemCallback()
})
}
const getState = ()=> {
return state;
}
return {
subscribe,
dispatch,
getState
}
}
标签:const,reducer,list,state,源码,Redux,底层
From: https://www.cnblogs.com/bingquan1/p/16965039.html