mirror of
https://github.com/reduxjs/redux-devtools.git
synced 2025-02-07 15:10:45 +03:00
Merge pull request #235 from zalmoxisus/master
Check instrumentation store enhancer's reducer and not to be included twice
This commit is contained in:
commit
a7e1221f1d
|
@ -336,10 +336,17 @@ function unliftStore(liftedStore, liftReducer) {
|
||||||
export default function instrument(monitorReducer = () => null) {
|
export default function instrument(monitorReducer = () => null) {
|
||||||
return createStore => (reducer, initialState, enhancer) => {
|
return createStore => (reducer, initialState, enhancer) => {
|
||||||
function liftReducer(r) {
|
function liftReducer(r) {
|
||||||
|
if (typeof r !== 'function') {
|
||||||
|
throw new Error('Expected the nextReducer to be a function.');
|
||||||
|
}
|
||||||
return liftReducerWith(r, initialState, monitorReducer);
|
return liftReducerWith(r, initialState, monitorReducer);
|
||||||
}
|
}
|
||||||
|
|
||||||
const liftedStore = createStore(liftReducer(reducer), undefined, enhancer);
|
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);
|
return unliftStore(liftedStore, liftReducer);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import expect, { spyOn } from 'expect';
|
import expect, { spyOn } from 'expect';
|
||||||
import { createStore } from 'redux';
|
import { createStore, compose } from 'redux';
|
||||||
import instrument, { ActionCreators } from '../src/instrument';
|
import instrument, { ActionCreators } from '../src/instrument';
|
||||||
|
|
||||||
function counter(state = 0, action) {
|
function counter(state = 0, action) {
|
||||||
|
@ -322,4 +322,15 @@ describe('instrument', () => {
|
||||||
expect(importMonitoredLiftedStore.getState()).toEqual(exportedState);
|
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.');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user