From d756384b6c652c29bb5f086443f37883d299f147 Mon Sep 17 00:00:00 2001 From: Mihail Diordiev Date: Sat, 30 Jan 2016 15:11:54 +0200 Subject: [PATCH 1/3] Throw if the reducer passed to `replaceReducer()` is not a function --- src/instrument.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/instrument.js b/src/instrument.js index e8c47f0f..a4abed96 100644 --- a/src/instrument.js +++ b/src/instrument.js @@ -336,6 +336,9 @@ function unliftStore(liftedStore, liftReducer) { export default function instrument(monitorReducer = () => null) { return createStore => (reducer, initialState, enhancer) => { function liftReducer(r) { + if (typeof r !== 'function') { + throw new Error('Expected the nextReducer to be a function.') + } return liftReducerWith(r, initialState, monitorReducer); } From a3d053880c1a9846f5fcacff55be9046b202e4d4 Mon Sep 17 00:00:00 2001 From: Zalmoxisus Date: Sat, 30 Jan 2016 15:52:01 +0200 Subject: [PATCH 2/3] Add a test for 'Expected the nextReducer to be a function.' and fix ESLint --- src/instrument.js | 2 +- test/instrument.spec.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/instrument.js b/src/instrument.js index a4abed96..a886b16a 100644 --- a/src/instrument.js +++ b/src/instrument.js @@ -337,7 +337,7 @@ export default function instrument(monitorReducer = () => null) { return createStore => (reducer, initialState, enhancer) => { function liftReducer(r) { if (typeof r !== 'function') { - throw new Error('Expected the nextReducer to be a function.') + throw new Error('Expected the nextReducer to be a function.'); } return liftReducerWith(r, initialState, monitorReducer); } diff --git a/test/instrument.spec.js b/test/instrument.spec.js index 9db18896..412d36db 100644 --- a/test/instrument.spec.js +++ b/test/instrument.spec.js @@ -322,4 +322,10 @@ describe('instrument', () => { expect(importMonitoredLiftedStore.getState()).toEqual(exportedState); }); }); + + it('throws if reducer is not a function', () => { + expect(() => + instrument()(createStore)() + ).toThrow('Expected the nextReducer to be a function.'); + }); }); From e82ef7de59526632117e749f7787df1515f68cd0 Mon Sep 17 00:00:00 2001 From: Zalmoxisus Date: Tue, 2 Feb 2016 18:07:58 +0200 Subject: [PATCH 3/3] Throw if there are more than one instrument enhancer included --- src/instrument.js | 4 ++++ test/instrument.spec.js | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/instrument.js b/src/instrument.js index a886b16a..00b74f05 100644 --- a/src/instrument.js +++ b/src/instrument.js @@ -343,6 +343,10 @@ export default function instrument(monitorReducer = () => null) { } const liftedStore = createStore(liftReducer(reducer), undefined, enhancer); + if (liftedStore.liftedStore) { + throw new Error('DevTools instrument shouldn\'t be included more than once. ' + + 'Check your store configuration.'); + } return unliftStore(liftedStore, liftReducer); }; } diff --git a/test/instrument.spec.js b/test/instrument.spec.js index 412d36db..735024af 100644 --- a/test/instrument.spec.js +++ b/test/instrument.spec.js @@ -1,5 +1,5 @@ import expect, { spyOn } from 'expect'; -import { createStore } from 'redux'; +import { createStore, compose } from 'redux'; import instrument, { ActionCreators } from '../src/instrument'; function counter(state = 0, action) { @@ -328,4 +328,9 @@ describe('instrument', () => { instrument()(createStore)() ).toThrow('Expected the nextReducer to be a function.'); }); + it('throws if there are more than one instrument enhancer included', () => { + expect(() => { + store = createStore(counter, undefined, compose(instrument(), instrument())); + }).toThrow('DevTools instrument shouldn\'t be included more than once. Check your store configuration.'); + }); });