根据订阅发布设计模式看了要模仿的一个功能,看着看着坑越挖越多,涉及到了redux 。顺便尝试吃了一下 redux 的几个核心函数的源码,初生涩隐有启发并作记录。
Redux 的几个核心函数源码
combineReducers
1 | function combineReducers(reducers) { |
bindActionCreators
1 | function bindActionCreator(actionCreator, dispatch) { |
compose
1 | function compose(...funcs) { |
applyMiddleware
1 | function applyMiddleware(...middlewares) { |
createStore(重点)
1 | function createStore(reducer, preloadedState, enhancer) { |