MCPcopy
hub / github.com/react-boilerplate/react-boilerplate / injectReducerFactory

Function injectReducerFactory

app/utils/reducerInjectors.js:7–26  ·  view source on GitHub ↗
(store, isValid)

Source from the content-addressed store, hash-verified

5import createReducer from '../reducers';
6
7export function injectReducerFactory(store, isValid) {
8 return function injectReducer(key, reducer) {
9 if (!isValid) checkStore(store);
10
11 invariant(
12 isString(key) && !isEmpty(key) && isFunction(reducer),
13 '(app/utils...) injectReducer: Expected `reducer` to be a reducer function',
14 );
15
16 // Check `store.injectedReducers[key] === reducer` for hot reloading when a key is the same but a reducer is different
17 if (
18 Reflect.has(store.injectedReducers, key) &&
19 store.injectedReducers[key] === reducer
20 )
21 return;
22
23 store.injectedReducers[key] = reducer; // eslint-disable-line no-param-reassign
24 store.replaceReducer(createReducer(store.injectedReducers));
25 };
26}
27
28export default function getInjectors(store) {
29 checkStore(store);

Callers 2

getInjectorsFunction · 0.70

Calls 2

checkStoreFunction · 0.70
createReducerFunction · 0.50

Tested by

no test coverage detected