Merge pull request #235 from zalmoxisus/master

Check instrumentation store enhancer's reducer and not to be included twice
This commit is contained in:
Dan Abramov 2016-02-02 17:27:30 +00:00
commit a7e1221f1d
2 changed files with 19 additions and 1 deletions

View File

@ -336,10 +336,17 @@ 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);
}
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);
};
}

View File

@ -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) {
@ -322,4 +322,15 @@ 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.');
});
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.');
});
});