redux.js 27 KB

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