redux.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
  4. var $$observable = _interopDefault(require('symbol-observable'));
  5. /**
  6. * These are private action types reserved by Redux.
  7. * For any unknown actions, you must return the current state.
  8. * If the current state is undefined, you must return the initial state.
  9. * Do not reference these action types directly in your code.
  10. */
  11. var randomString = function randomString() {
  12. return Math.random().toString(36).substring(7).split('').join('.');
  13. };
  14. var ActionTypes = {
  15. INIT: "@@redux/INIT" + randomString(),
  16. REPLACE: "@@redux/REPLACE" + randomString(),
  17. PROBE_UNKNOWN_ACTION: function PROBE_UNKNOWN_ACTION() {
  18. return "@@redux/PROBE_UNKNOWN_ACTION" + randomString();
  19. }
  20. };
  21. /**
  22. * @param {any} obj The object to inspect.
  23. * @returns {boolean} True if the argument appears to be a plain object.
  24. */
  25. function isPlainObject(obj) {
  26. if (typeof obj !== 'object' || obj === null) return false;
  27. var proto = obj;
  28. while (Object.getPrototypeOf(proto) !== null) {
  29. proto = Object.getPrototypeOf(proto);
  30. }
  31. return Object.getPrototypeOf(obj) === proto;
  32. }
  33. /**
  34. * Creates a Redux store that holds the state tree.
  35. * The only way to change the data in the store is to call `dispatch()` on it.
  36. *
  37. * There should only be a single store in your app. To specify how different
  38. * parts of the state tree respond to actions, you may combine several reducers
  39. * into a single reducer function by using `combineReducers`.
  40. *
  41. * @param {Function} reducer A function that returns the next state tree, given
  42. * the current state tree and the action to handle.
  43. *
  44. * @param {any} [preloadedState] The initial state. You may optionally specify it
  45. * to hydrate the state from the server in universal apps, or to restore a
  46. * previously serialized user session.
  47. * If you use `combineReducers` to produce the root reducer function, this must be
  48. * an object with the same shape as `combineReducers` keys.
  49. *
  50. * @param {Function} [enhancer] The store enhancer. You may optionally specify it
  51. * to enhance the store with third-party capabilities such as middleware,
  52. * time travel, persistence, etc. The only store enhancer that ships with Redux
  53. * is `applyMiddleware()`.
  54. *
  55. * @returns {Store} A Redux store that lets you read the state, dispatch actions
  56. * and subscribe to changes.
  57. */
  58. function createStore(reducer, preloadedState, enhancer) {
  59. var _ref2;
  60. if (typeof preloadedState === 'function' && typeof enhancer === 'function' || typeof enhancer === 'function' && typeof arguments[3] === 'function') {
  61. throw new Error('It looks like you are passing several store enhancers to ' + 'createStore(). This is not supported. Instead, compose them ' + 'together to a single function.');
  62. }
  63. if (typeof preloadedState === 'function' && typeof enhancer === 'undefined') {
  64. enhancer = preloadedState;
  65. preloadedState = undefined;
  66. }
  67. if (typeof enhancer !== 'undefined') {
  68. if (typeof enhancer !== 'function') {
  69. throw new Error('Expected the enhancer to be a function.');
  70. }
  71. return enhancer(createStore)(reducer, preloadedState);
  72. }
  73. if (typeof reducer !== 'function') {
  74. throw new Error('Expected the reducer to be a function.');
  75. }
  76. var currentReducer = reducer;
  77. var currentState = preloadedState;
  78. var currentListeners = [];
  79. var nextListeners = currentListeners;
  80. var isDispatching = false;
  81. /**
  82. * This makes a shallow copy of currentListeners so we can use
  83. * nextListeners as a temporary list while dispatching.
  84. *
  85. * This prevents any bugs around consumers calling
  86. * subscribe/unsubscribe in the middle of a dispatch.
  87. */
  88. function ensureCanMutateNextListeners() {
  89. if (nextListeners === currentListeners) {
  90. nextListeners = currentListeners.slice();
  91. }
  92. }
  93. /**
  94. * Reads the state tree managed by the store.
  95. *
  96. * @returns {any} The current state tree of your application.
  97. */
  98. function getState() {
  99. if (isDispatching) {
  100. throw new Error('You may not call store.getState() while the reducer is executing. ' + 'The reducer has already received the state as an argument. ' + 'Pass it down from the top reducer instead of reading it from the store.');
  101. }
  102. return currentState;
  103. }
  104. /**
  105. * Adds a change listener. It will be called any time an action is dispatched,
  106. * and some part of the state tree may potentially have changed. You may then
  107. * call `getState()` to read the current state tree inside the callback.
  108. *
  109. * You may call `dispatch()` from a change listener, with the following
  110. * caveats:
  111. *
  112. * 1. The subscriptions are snapshotted just before every `dispatch()` call.
  113. * If you subscribe or unsubscribe while the listeners are being invoked, this
  114. * will not have any effect on the `dispatch()` that is currently in progress.
  115. * However, the next `dispatch()` call, whether nested or not, will use a more
  116. * recent snapshot of the subscription list.
  117. *
  118. * 2. The listener should not expect to see all state changes, as the state
  119. * might have been updated multiple times during a nested `dispatch()` before
  120. * the listener is called. It is, however, guaranteed that all subscribers
  121. * registered before the `dispatch()` started will be called with the latest
  122. * state by the time it exits.
  123. *
  124. * @param {Function} listener A callback to be invoked on every dispatch.
  125. * @returns {Function} A function to remove this change listener.
  126. */
  127. function subscribe(listener) {
  128. if (typeof listener !== 'function') {
  129. throw new Error('Expected the listener to be a function.');
  130. }
  131. if (isDispatching) {
  132. throw new Error('You may not call store.subscribe() while the reducer is executing. ' + 'If you would like to be notified after the store has been updated, subscribe from a ' + 'component and invoke store.getState() in the callback to access the latest state. ' + 'See https://redux.js.org/api-reference/store#subscribelistener for more details.');
  133. }
  134. var isSubscribed = true;
  135. ensureCanMutateNextListeners();
  136. nextListeners.push(listener);
  137. return function unsubscribe() {
  138. if (!isSubscribed) {
  139. return;
  140. }
  141. if (isDispatching) {
  142. throw new Error('You may not unsubscribe from a store listener while the reducer is executing. ' + 'See https://redux.js.org/api-reference/store#subscribelistener for more details.');
  143. }
  144. isSubscribed = false;
  145. ensureCanMutateNextListeners();
  146. var index = nextListeners.indexOf(listener);
  147. nextListeners.splice(index, 1);
  148. currentListeners = null;
  149. };
  150. }
  151. /**
  152. * Dispatches an action. It is the only way to trigger a state change.
  153. *
  154. * The `reducer` function, used to create the store, will be called with the
  155. * current state tree and the given `action`. Its return value will
  156. * be considered the **next** state of the tree, and the change listeners
  157. * will be notified.
  158. *
  159. * The base implementation only supports plain object actions. If you want to
  160. * dispatch a Promise, an Observable, a thunk, or something else, you need to
  161. * wrap your store creating function into the corresponding middleware. For
  162. * example, see the documentation for the `redux-thunk` package. Even the
  163. * middleware will eventually dispatch plain object actions using this method.
  164. *
  165. * @param {Object} action A plain object representing “what changed”. It is
  166. * a good idea to keep actions serializable so you can record and replay user
  167. * sessions, or use the time travelling `redux-devtools`. An action must have
  168. * a `type` property which may not be `undefined`. It is a good idea to use
  169. * string constants for action types.
  170. *
  171. * @returns {Object} For convenience, the same action object you dispatched.
  172. *
  173. * Note that, if you use a custom middleware, it may wrap `dispatch()` to
  174. * return something else (for example, a Promise you can await).
  175. */
  176. function dispatch(action) {
  177. if (!isPlainObject(action)) {
  178. throw new Error('Actions must be plain objects. ' + 'Use custom middleware for async actions.');
  179. }
  180. if (typeof action.type === 'undefined') {
  181. throw new Error('Actions may not have an undefined "type" property. ' + 'Have you misspelled a constant?');
  182. }
  183. if (isDispatching) {
  184. throw new Error('Reducers may not dispatch actions.');
  185. }
  186. try {
  187. isDispatching = true;
  188. currentState = currentReducer(currentState, action);
  189. } finally {
  190. isDispatching = false;
  191. }
  192. var listeners = currentListeners = nextListeners;
  193. for (var i = 0; i < listeners.length; i++) {
  194. var listener = listeners[i];
  195. listener();
  196. }
  197. return action;
  198. }
  199. /**
  200. * Replaces the reducer currently used by the store to calculate the state.
  201. *
  202. * You might need this if your app implements code splitting and you want to
  203. * load some of the reducers dynamically. You might also need this if you
  204. * implement a hot reloading mechanism for Redux.
  205. *
  206. * @param {Function} nextReducer The reducer for the store to use instead.
  207. * @returns {void}
  208. */
  209. function replaceReducer(nextReducer) {
  210. if (typeof nextReducer !== 'function') {
  211. throw new Error('Expected the nextReducer to be a function.');
  212. }
  213. currentReducer = nextReducer; // This action has a similiar effect to ActionTypes.INIT.
  214. // Any reducers that existed in both the new and old rootReducer
  215. // will receive the previous state. This effectively populates
  216. // the new state tree with any relevant data from the old one.
  217. dispatch({
  218. type: ActionTypes.REPLACE
  219. });
  220. }
  221. /**
  222. * Interoperability point for observable/reactive libraries.
  223. * @returns {observable} A minimal observable of state changes.
  224. * For more information, see the observable proposal:
  225. * https://github.com/tc39/proposal-observable
  226. */
  227. function observable() {
  228. var _ref;
  229. var outerSubscribe = subscribe;
  230. return _ref = {
  231. /**
  232. * The minimal observable subscription method.
  233. * @param {Object} observer Any object that can be used as an observer.
  234. * The observer object should have a `next` method.
  235. * @returns {subscription} An object with an `unsubscribe` method that can
  236. * be used to unsubscribe the observable from the store, and prevent further
  237. * emission of values from the observable.
  238. */
  239. subscribe: function subscribe(observer) {
  240. if (typeof observer !== 'object' || observer === null) {
  241. throw new TypeError('Expected the observer to be an object.');
  242. }
  243. function observeState() {
  244. if (observer.next) {
  245. observer.next(getState());
  246. }
  247. }
  248. observeState();
  249. var unsubscribe = outerSubscribe(observeState);
  250. return {
  251. unsubscribe: unsubscribe
  252. };
  253. }
  254. }, _ref[$$observable] = function () {
  255. return this;
  256. }, _ref;
  257. } // When a store is created, an "INIT" action is dispatched so that every
  258. // reducer returns their initial state. This effectively populates
  259. // the initial state tree.
  260. dispatch({
  261. type: ActionTypes.INIT
  262. });
  263. return _ref2 = {
  264. dispatch: dispatch,
  265. subscribe: subscribe,
  266. getState: getState,
  267. replaceReducer: replaceReducer
  268. }, _ref2[$$observable] = observable, _ref2;
  269. }
  270. /**
  271. * Prints a warning in the console if it exists.
  272. *
  273. * @param {String} message The warning message.
  274. * @returns {void}
  275. */
  276. function warning(message) {
  277. /* eslint-disable no-console */
  278. if (typeof console !== 'undefined' && typeof console.error === 'function') {
  279. console.error(message);
  280. }
  281. /* eslint-enable no-console */
  282. try {
  283. // This error was thrown as a convenience so that if you enable
  284. // "break on all exceptions" in your console,
  285. // it would pause the execution at this line.
  286. throw new Error(message);
  287. } catch (e) {} // eslint-disable-line no-empty
  288. }
  289. function getUndefinedStateErrorMessage(key, action) {
  290. var actionType = action && action.type;
  291. var actionDescription = actionType && "action \"" + String(actionType) + "\"" || 'an action';
  292. return "Given " + actionDescription + ", reducer \"" + key + "\" returned undefined. " + "To ignore an action, you must explicitly return the previous state. " + "If you want this reducer to hold no value, you can return null instead of undefined.";
  293. }
  294. function getUnexpectedStateShapeWarningMessage(inputState, reducers, action, unexpectedKeyCache) {
  295. var reducerKeys = Object.keys(reducers);
  296. var argumentName = action && action.type === ActionTypes.INIT ? 'preloadedState argument passed to createStore' : 'previous state received by the reducer';
  297. if (reducerKeys.length === 0) {
  298. return 'Store does not have a valid reducer. Make sure the argument passed ' + 'to combineReducers is an object whose values are reducers.';
  299. }
  300. if (!isPlainObject(inputState)) {
  301. return "The " + argumentName + " has unexpected type of \"" + {}.toString.call(inputState).match(/\s([a-z|A-Z]+)/)[1] + "\". Expected argument to be an object with the following " + ("keys: \"" + reducerKeys.join('", "') + "\"");
  302. }
  303. var unexpectedKeys = Object.keys(inputState).filter(function (key) {
  304. return !reducers.hasOwnProperty(key) && !unexpectedKeyCache[key];
  305. });
  306. unexpectedKeys.forEach(function (key) {
  307. unexpectedKeyCache[key] = true;
  308. });
  309. if (action && action.type === ActionTypes.REPLACE) return;
  310. if (unexpectedKeys.length > 0) {
  311. return "Unexpected " + (unexpectedKeys.length > 1 ? 'keys' : 'key') + " " + ("\"" + unexpectedKeys.join('", "') + "\" found in " + argumentName + ". ") + "Expected to find one of the known reducer keys instead: " + ("\"" + reducerKeys.join('", "') + "\". Unexpected keys will be ignored.");
  312. }
  313. }
  314. function assertReducerShape(reducers) {
  315. Object.keys(reducers).forEach(function (key) {
  316. var reducer = reducers[key];
  317. var initialState = reducer(undefined, {
  318. type: ActionTypes.INIT
  319. });
  320. if (typeof initialState === 'undefined') {
  321. throw new Error("Reducer \"" + key + "\" returned undefined during initialization. " + "If the state passed to the reducer is undefined, you must " + "explicitly return the initial state. The initial state may " + "not be undefined. If you don't want to set a value for this reducer, " + "you can use null instead of undefined.");
  322. }
  323. if (typeof reducer(undefined, {
  324. type: ActionTypes.PROBE_UNKNOWN_ACTION()
  325. }) === 'undefined') {
  326. throw new Error("Reducer \"" + key + "\" returned undefined when probed with a random type. " + ("Don't try to handle " + ActionTypes.INIT + " or other actions in \"redux/*\" ") + "namespace. They are considered private. Instead, you must return the " + "current state for any unknown actions, unless it is undefined, " + "in which case you must return the initial state, regardless of the " + "action type. The initial state may not be undefined, but can be null.");
  327. }
  328. });
  329. }
  330. /**
  331. * Turns an object whose values are different reducer functions, into a single
  332. * reducer function. It will call every child reducer, and gather their results
  333. * into a single state object, whose keys correspond to the keys of the passed
  334. * reducer functions.
  335. *
  336. * @param {Object} reducers An object whose values correspond to different
  337. * reducer functions that need to be combined into one. One handy way to obtain
  338. * it is to use ES6 `import * as reducers` syntax. The reducers may never return
  339. * undefined for any action. Instead, they should return their initial state
  340. * if the state passed to them was undefined, and the current state for any
  341. * unrecognized action.
  342. *
  343. * @returns {Function} A reducer function that invokes every reducer inside the
  344. * passed object, and builds a state object with the same shape.
  345. */
  346. function combineReducers(reducers) {
  347. var reducerKeys = Object.keys(reducers);
  348. var finalReducers = {};
  349. for (var i = 0; i < reducerKeys.length; i++) {
  350. var key = reducerKeys[i];
  351. if (process.env.NODE_ENV !== 'production') {
  352. if (typeof reducers[key] === 'undefined') {
  353. warning("No reducer provided for key \"" + key + "\"");
  354. }
  355. }
  356. if (typeof reducers[key] === 'function') {
  357. finalReducers[key] = reducers[key];
  358. }
  359. }
  360. var finalReducerKeys = Object.keys(finalReducers); // This is used to make sure we don't warn about the same
  361. // keys multiple times.
  362. var unexpectedKeyCache;
  363. if (process.env.NODE_ENV !== 'production') {
  364. unexpectedKeyCache = {};
  365. }
  366. var shapeAssertionError;
  367. try {
  368. assertReducerShape(finalReducers);
  369. } catch (e) {
  370. shapeAssertionError = e;
  371. }
  372. return function combination(state, action) {
  373. if (state === void 0) {
  374. state = {};
  375. }
  376. if (shapeAssertionError) {
  377. throw shapeAssertionError;
  378. }
  379. if (process.env.NODE_ENV !== 'production') {
  380. var warningMessage = getUnexpectedStateShapeWarningMessage(state, finalReducers, action, unexpectedKeyCache);
  381. if (warningMessage) {
  382. warning(warningMessage);
  383. }
  384. }
  385. var hasChanged = false;
  386. var nextState = {};
  387. for (var _i = 0; _i < finalReducerKeys.length; _i++) {
  388. var _key = finalReducerKeys[_i];
  389. var reducer = finalReducers[_key];
  390. var previousStateForKey = state[_key];
  391. var nextStateForKey = reducer(previousStateForKey, action);
  392. if (typeof nextStateForKey === 'undefined') {
  393. var errorMessage = getUndefinedStateErrorMessage(_key, action);
  394. throw new Error(errorMessage);
  395. }
  396. nextState[_key] = nextStateForKey;
  397. hasChanged = hasChanged || nextStateForKey !== previousStateForKey;
  398. }
  399. hasChanged = hasChanged || finalReducerKeys.length !== Object.keys(state).length;
  400. return hasChanged ? nextState : state;
  401. };
  402. }
  403. function bindActionCreator(actionCreator, dispatch) {
  404. return function () {
  405. return dispatch(actionCreator.apply(this, arguments));
  406. };
  407. }
  408. /**
  409. * Turns an object whose values are action creators, into an object with the
  410. * same keys, but with every function wrapped into a `dispatch` call so they
  411. * may be invoked directly. This is just a convenience method, as you can call
  412. * `store.dispatch(MyActionCreators.doSomething())` yourself just fine.
  413. *
  414. * For convenience, you can also pass an action creator as the first argument,
  415. * and get a dispatch wrapped function in return.
  416. *
  417. * @param {Function|Object} actionCreators An object whose values are action
  418. * creator functions. One handy way to obtain it is to use ES6 `import * as`
  419. * syntax. You may also pass a single function.
  420. *
  421. * @param {Function} dispatch The `dispatch` function available on your Redux
  422. * store.
  423. *
  424. * @returns {Function|Object} The object mimicking the original object, but with
  425. * every action creator wrapped into the `dispatch` call. If you passed a
  426. * function as `actionCreators`, the return value will also be a single
  427. * function.
  428. */
  429. function bindActionCreators(actionCreators, dispatch) {
  430. if (typeof actionCreators === 'function') {
  431. return bindActionCreator(actionCreators, dispatch);
  432. }
  433. if (typeof actionCreators !== 'object' || actionCreators === null) {
  434. throw new Error("bindActionCreators expected an object or a function, instead received " + (actionCreators === null ? 'null' : typeof actionCreators) + ". " + "Did you write \"import ActionCreators from\" instead of \"import * as ActionCreators from\"?");
  435. }
  436. var boundActionCreators = {};
  437. for (var key in actionCreators) {
  438. var actionCreator = actionCreators[key];
  439. if (typeof actionCreator === 'function') {
  440. boundActionCreators[key] = bindActionCreator(actionCreator, dispatch);
  441. }
  442. }
  443. return boundActionCreators;
  444. }
  445. function _defineProperty(obj, key, value) {
  446. if (key in obj) {
  447. Object.defineProperty(obj, key, {
  448. value: value,
  449. enumerable: true,
  450. configurable: true,
  451. writable: true
  452. });
  453. } else {
  454. obj[key] = value;
  455. }
  456. return obj;
  457. }
  458. function ownKeys(object, enumerableOnly) {
  459. var keys = Object.keys(object);
  460. if (Object.getOwnPropertySymbols) {
  461. keys.push.apply(keys, Object.getOwnPropertySymbols(object));
  462. }
  463. if (enumerableOnly) keys = keys.filter(function (sym) {
  464. return Object.getOwnPropertyDescriptor(object, sym).enumerable;
  465. });
  466. return keys;
  467. }
  468. function _objectSpread2(target) {
  469. for (var i = 1; i < arguments.length; i++) {
  470. var source = arguments[i] != null ? arguments[i] : {};
  471. if (i % 2) {
  472. ownKeys(source, true).forEach(function (key) {
  473. _defineProperty(target, key, source[key]);
  474. });
  475. } else if (Object.getOwnPropertyDescriptors) {
  476. Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
  477. } else {
  478. ownKeys(source).forEach(function (key) {
  479. Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
  480. });
  481. }
  482. }
  483. return target;
  484. }
  485. /**
  486. * Composes single-argument functions from right to left. The rightmost
  487. * function can take multiple arguments as it provides the signature for
  488. * the resulting composite function.
  489. *
  490. * @param {...Function} funcs The functions to compose.
  491. * @returns {Function} A function obtained by composing the argument functions
  492. * from right to left. For example, compose(f, g, h) is identical to doing
  493. * (...args) => f(g(h(...args))).
  494. */
  495. function compose() {
  496. for (var _len = arguments.length, funcs = new Array(_len), _key = 0; _key < _len; _key++) {
  497. funcs[_key] = arguments[_key];
  498. }
  499. if (funcs.length === 0) {
  500. return function (arg) {
  501. return arg;
  502. };
  503. }
  504. if (funcs.length === 1) {
  505. return funcs[0];
  506. }
  507. return funcs.reduce(function (a, b) {
  508. return function () {
  509. return a(b.apply(void 0, arguments));
  510. };
  511. });
  512. }
  513. /**
  514. * Creates a store enhancer that applies middleware to the dispatch method
  515. * of the Redux store. This is handy for a variety of tasks, such as expressing
  516. * asynchronous actions in a concise manner, or logging every action payload.
  517. *
  518. * See `redux-thunk` package as an example of the Redux middleware.
  519. *
  520. * Because middleware is potentially asynchronous, this should be the first
  521. * store enhancer in the composition chain.
  522. *
  523. * Note that each middleware will be given the `dispatch` and `getState` functions
  524. * as named arguments.
  525. *
  526. * @param {...Function} middlewares The middleware chain to be applied.
  527. * @returns {Function} A store enhancer applying the middleware.
  528. */
  529. function applyMiddleware() {
  530. for (var _len = arguments.length, middlewares = new Array(_len), _key = 0; _key < _len; _key++) {
  531. middlewares[_key] = arguments[_key];
  532. }
  533. return function (createStore) {
  534. return function () {
  535. var store = createStore.apply(void 0, arguments);
  536. var _dispatch = function dispatch() {
  537. throw new Error('Dispatching while constructing your middleware is not allowed. ' + 'Other middleware would not be applied to this dispatch.');
  538. };
  539. var middlewareAPI = {
  540. getState: store.getState,
  541. dispatch: function dispatch() {
  542. return _dispatch.apply(void 0, arguments);
  543. }
  544. };
  545. var chain = middlewares.map(function (middleware) {
  546. return middleware(middlewareAPI);
  547. });
  548. _dispatch = compose.apply(void 0, chain)(store.dispatch);
  549. return _objectSpread2({}, store, {
  550. dispatch: _dispatch
  551. });
  552. };
  553. };
  554. }
  555. /*
  556. * This is a dummy function to check if the function name has been altered by minification.
  557. * If the function has been minified and NODE_ENV !== 'production', warn the user.
  558. */
  559. function isCrushed() {}
  560. if (process.env.NODE_ENV !== 'production' && typeof isCrushed.name === 'string' && isCrushed.name !== 'isCrushed') {
  561. warning('You are currently using minified code outside of NODE_ENV === "production". ' + 'This means that you are running a slower development build of Redux. ' + 'You can use loose-envify (https://github.com/zertosh/loose-envify) for browserify ' + 'or setting mode to production in webpack (https://webpack.js.org/concepts/mode/) ' + 'to ensure you have the correct code for your production build.');
  562. }
  563. exports.__DO_NOT_USE__ActionTypes = ActionTypes;
  564. exports.applyMiddleware = applyMiddleware;
  565. exports.bindActionCreators = bindActionCreators;
  566. exports.combineReducers = combineReducers;
  567. exports.compose = compose;
  568. exports.createStore = createStore;