redux.js 26 KB

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