import invariant from 'invariant' ; import checkStore from './checkStore' ; import createReducer from '../reducers' ; import { Reducer } from 'redux' ; import { IStore } from 'Interfaces/store' ; export function injectReducerFactory ( store , isValid = false ) { return ( key , reducer ) => { if ( ! isValid ) { checkStore ( store ) ; } invariant ( typeof key === 'string' && ! ! key && typeof reducer === 'function' , '(app/utils...) injectReducer: Expected `reducer` to be a reducer function' ) ; if ( Reflect . has ( store . injectedReducers , key ) && store . injectedReducers [ key ] === reducer ) { return ; } store . injectedReducers [ key ] = reducer ; store . replaceReducer ( createReducer ( store . injectedReducers ) ) ; } ; } export default function getInjectors ( store ) { checkStore ( store ) ; return { injectReducer : injectReducerFactory ( store , true ) } ; }