Skip to content

Commit a7e1221

Browse files
committed
Merge pull request #235 from zalmoxisus/master
Check instrumentation store enhancer's reducer and not to be included twice
2 parents a370d49 + e82ef7d commit a7e1221

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/instrument.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,10 +336,17 @@ function unliftStore(liftedStore, liftReducer) {
336336
export default function instrument(monitorReducer = () => null) {
337337
return createStore => (reducer, initialState, enhancer) => {
338338
function liftReducer(r) {
339+
if (typeof r !== 'function') {
340+
throw new Error('Expected the nextReducer to be a function.');
341+
}
339342
return liftReducerWith(r, initialState, monitorReducer);
340343
}
341344

342345
const liftedStore = createStore(liftReducer(reducer), undefined, enhancer);
346+
if (liftedStore.liftedStore) {
347+
throw new Error('DevTools instrument shouldn\'t be included more than once. ' +
348+
'Check your store configuration.');
349+
}
343350
return unliftStore(liftedStore, liftReducer);
344351
};
345352
}

test/instrument.spec.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import expect, { spyOn } from 'expect';
2-
import { createStore } from 'redux';
2+
import { createStore, compose } from 'redux';
33
import instrument, { ActionCreators } from '../src/instrument';
44

55
function counter(state = 0, action) {
@@ -322,4 +322,15 @@ describe('instrument', () => {
322322
expect(importMonitoredLiftedStore.getState()).toEqual(exportedState);
323323
});
324324
});
325+
326+
it('throws if reducer is not a function', () => {
327+
expect(() =>
328+
instrument()(createStore)()
329+
).toThrow('Expected the nextReducer to be a function.');
330+
});
331+
it('throws if there are more than one instrument enhancer included', () => {
332+
expect(() => {
333+
store = createStore(counter, undefined, compose(instrument(), instrument()));
334+
}).toThrow('DevTools instrument shouldn\'t be included more than once. Check your store configuration.');
335+
});
325336
});

0 commit comments

Comments
 (0)