反应样板:injectReducerFactory返回关闭?为什么?

时间:2019-03-12 00:03:26

标签: javascript reactjs react-redux react-boilerplate

在React Boilerplate项目(reducerInjects.js)中,reducerInjectors.js中的injectReducerFactory方法返回一个在jectReducer HOC中执行的闭包。为什么不只在Factory方法中更新商店,而在componentDidMount生命周期方法中执行商店呢?有什么优势?像这样:

export function injectReducerFactory(store, key, reducer) {
    store.injectedReducers[key] = reducer; 
    store.replaceReducer(createReducer(store.injectedReducers));
}

以及在HOC(injectReducer.js)中,类似:

componentWillMount() {
    injectReducer(this.context.store, key, reducer);
}

0 个答案:

没有答案