在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);
}