UNPKG

1.83 kBJavaScriptView Raw
1'use strict';
2
3var assign = require('./utils/assign');
4var compose = require('redux').compose;
5
6function enhancer() {
7 var config = arguments[0] || {};
8 config.features = { pause: true, export: true, test: true };
9 config.type = 'redux';
10 if (config.autoPause === undefined) config.autoPause = true;
11 if (config.latency === undefined) config.latency = 500;
12
13 return function (createStore) {
14 return function (reducer, preloadedState, enhancer) {
15 var store = createStore(reducer, preloadedState, enhancer);
16 var origDispatch = store.dispatch;
17
18 var devTools = window.__REDUX_DEVTOOLS_EXTENSION__.connect(config);
19 devTools.init(store.getState());
20
21 var dispatch = function (action) {
22 var r = origDispatch(action);
23 devTools.send(action, store.getState());
24 return r;
25 };
26
27 if (Object.assign) return Object.assign(store, { dispatch: dispatch });
28 return assign(store, 'dispatch', dispatch);
29 };
30 };
31}
32
33function composeWithEnhancer(config) {
34 return function () {
35 return compose(compose.apply(null, arguments), enhancer(config));
36 };
37}
38
39exports.__esModule = true;
40exports.composeWithDevTools = function () {
41 if (typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION__) {
42 if (arguments.length === 0) return enhancer();
43 if (typeof arguments[0] === 'object')
44 return composeWithEnhancer(arguments[0]);
45 return composeWithEnhancer().apply(null, arguments);
46 }
47
48 if (arguments.length === 0) return undefined;
49 if (typeof arguments[0] === 'object') return compose;
50 return compose.apply(null, arguments);
51};
52
53exports.devToolsEnhancer =
54 typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION__
55 ? enhancer
56 : function () {
57 return function (noop) {
58 return noop;
59 };
60 };