Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/ReduxInjector.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function injectReducer(key, reducer) {
var force = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;

// If already set, do nothing.
if ((0, _lodash.has)(store.injectedReducers, key) || force) return;
if ((0, _lodash.has)(store.injectedReducers, key) && (!force)) return;

(0, _lodash.set)(store.injectedReducers, key, reducer);
store.replaceReducer(combineReducersRecurse(store.injectedReducers));
Expand Down
20 changes: 11 additions & 9 deletions src/ReduxInjector.js → src/ReduxInjector.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { createStore, combineReducers } from 'redux';
import { set, has } from 'lodash';

let store = {};
let combine = combineReducers;
var store:any = {};
var combine = combineReducers;

function combineReducersRecurse(reducers) {
// If this is a leaf or already combined.
Expand All @@ -12,18 +12,20 @@ function combineReducersRecurse(reducers) {

// If this is an object of functions, combine reducers.
if (typeof reducers === 'object') {
let combinedReducers = {};
for (let key of Object.keys(reducers)) {
combinedReducers[key] = combineReducersRecurse(reducers[key]);
}
return combine(combinedReducers);
var combinedReducers = {};

Object.keys(reducers).forEach(function (key) {
combinedReducers[key] = combineReducersRecurse(reducers[key]);
});

return combine(combinedReducers);
}

// If we get here we have an invalid item in the reducer path.
throw new Error({
message: 'Invalid item in reducer tree',
item: reducers
});
} as any);
}

export function createInjectStore(initialReducers, ...args) {
Expand All @@ -48,7 +50,7 @@ export function createInjectStore(initialReducers, ...args) {

export function injectReducer(key, reducer, force = false) {
// If already set, do nothing.
if (has(store.injectedReducers, key) || force) return;
if (has(store.injectedReducers, key) && (!force)) return;

set(store.injectedReducers, key, reducer);
store.replaceReducer(combineReducersRecurse(store.injectedReducers));
Expand Down