redux.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735
  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. * Creates a Redux store that holds the state tree.
  87. * The only way to change the data in the store is to call `dispatch()` on it.
  88. *
  89. * There should only be a single store in your app. To specify how different
  90. * parts of the state tree respond to actions, you may combine several reducers
  91. * into a single reducer function by using `combineReducers`.
  92. *
  93. * @param {Function} reducer A function that returns the next state tree, given
  94. * the current state tree and the action to handle.
  95. *
  96. * @param {any} [preloadedState] The initial state. You may optionally specify it
  97. * to hydrate the state from the server in universal apps, or to restore a
  98. * previously serialized user session.
  99. * If you use `combineReducers` to produce the root reducer function, this must be
  100. * an object with the same shape as `combineReducers` keys.
  101. *
  102. * @param {Function} [enhancer] The store enhancer. You may optionally specify it
  103. * to enhance the store with third-party capabilities such as middleware,
  104. * time travel, persistence, etc. The only store enhancer that ships with Redux
  105. * is `applyMiddleware()`.
  106. *
  107. * @returns {Store} A Redux store that lets you read the state, dispatch actions
  108. * and subscribe to changes.
  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. * Prints a warning in the console if it exists.
  324. *
  325. * @param {String} message The warning message.
  326. * @returns {void}
  327. */
  328. function warning(message) {
  329. /* eslint-disable no-console */
  330. if (typeof console !== 'undefined' && typeof console.error === 'function') {
  331. console.error(message);
  332. }
  333. /* eslint-enable no-console */
  334. try {
  335. // This error was thrown as a convenience so that if you enable
  336. // "break on all exceptions" in your console,
  337. // it would pause the execution at this line.
  338. throw new Error(message);
  339. } catch (e) {} // eslint-disable-line no-empty
  340. }
  341. function getUnexpectedStateShapeWarningMessage(inputState, reducers, action, unexpectedKeyCache) {
  342. var reducerKeys = Object.keys(reducers);
  343. var argumentName = action && action.type === ActionTypes.INIT ? 'preloadedState argument passed to createStore' : 'previous state received by the reducer';
  344. if (reducerKeys.length === 0) {
  345. return 'Store does not have a valid reducer. Make sure the argument passed ' + 'to combineReducers is an object whose values are reducers.';
  346. }
  347. if (!isPlainObject(inputState)) {
  348. return "The " + argumentName + " has unexpected type of \"" + kindOf(inputState) + "\". Expected argument to be an object with the following " + ("keys: \"" + reducerKeys.join('", "') + "\"");
  349. }
  350. var unexpectedKeys = Object.keys(inputState).filter(function (key) {
  351. return !reducers.hasOwnProperty(key) && !unexpectedKeyCache[key];
  352. });
  353. unexpectedKeys.forEach(function (key) {
  354. unexpectedKeyCache[key] = true;
  355. });
  356. if (action && action.type === ActionTypes.REPLACE) return;
  357. if (unexpectedKeys.length > 0) {
  358. 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.");
  359. }
  360. }
  361. function assertReducerShape(reducers) {
  362. Object.keys(reducers).forEach(function (key) {
  363. var reducer = reducers[key];
  364. var initialState = reducer(undefined, {
  365. type: ActionTypes.INIT
  366. });
  367. if (typeof initialState === 'undefined') {
  368. 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.");
  369. }
  370. if (typeof reducer(undefined, {
  371. type: ActionTypes.PROBE_UNKNOWN_ACTION()
  372. }) === 'undefined') {
  373. 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.");
  374. }
  375. });
  376. }
  377. /**
  378. * Turns an object whose values are different reducer functions, into a single
  379. * reducer function. It will call every child reducer, and gather their results
  380. * into a single state object, whose keys correspond to the keys of the passed
  381. * reducer functions.
  382. *
  383. * @param {Object} reducers An object whose values correspond to different
  384. * reducer functions that need to be combined into one. One handy way to obtain
  385. * it is to use ES6 `import * as reducers` syntax. The reducers may never return
  386. * undefined for any action. Instead, they should return their initial state
  387. * if the state passed to them was undefined, and the current state for any
  388. * unrecognized action.
  389. *
  390. * @returns {Function} A reducer function that invokes every reducer inside the
  391. * passed object, and builds a state object with the same shape.
  392. */
  393. function combineReducers(reducers) {
  394. var reducerKeys = Object.keys(reducers);
  395. var finalReducers = {};
  396. for (var i = 0; i < reducerKeys.length; i++) {
  397. var key = reducerKeys[i];
  398. {
  399. if (typeof reducers[key] === 'undefined') {
  400. warning("No reducer provided for key \"" + key + "\"");
  401. }
  402. }
  403. if (typeof reducers[key] === 'function') {
  404. finalReducers[key] = reducers[key];
  405. }
  406. }
  407. var finalReducerKeys = Object.keys(finalReducers); // This is used to make sure we don't warn about the same
  408. // keys multiple times.
  409. var unexpectedKeyCache;
  410. {
  411. unexpectedKeyCache = {};
  412. }
  413. var shapeAssertionError;
  414. try {
  415. assertReducerShape(finalReducers);
  416. } catch (e) {
  417. shapeAssertionError = e;
  418. }
  419. return function combination(state, action) {
  420. if (state === void 0) {
  421. state = {};
  422. }
  423. if (shapeAssertionError) {
  424. throw shapeAssertionError;
  425. }
  426. {
  427. var warningMessage = getUnexpectedStateShapeWarningMessage(state, finalReducers, action, unexpectedKeyCache);
  428. if (warningMessage) {
  429. warning(warningMessage);
  430. }
  431. }
  432. var hasChanged = false;
  433. var nextState = {};
  434. for (var _i = 0; _i < finalReducerKeys.length; _i++) {
  435. var _key = finalReducerKeys[_i];
  436. var reducer = finalReducers[_key];
  437. var previousStateForKey = state[_key];
  438. var nextStateForKey = reducer(previousStateForKey, action);
  439. if (typeof nextStateForKey === 'undefined') {
  440. var actionType = action && action.type;
  441. 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.");
  442. }
  443. nextState[_key] = nextStateForKey;
  444. hasChanged = hasChanged || nextStateForKey !== previousStateForKey;
  445. }
  446. hasChanged = hasChanged || finalReducerKeys.length !== Object.keys(state).length;
  447. return hasChanged ? nextState : state;
  448. };
  449. }
  450. function bindActionCreator(actionCreator, dispatch) {
  451. return function () {
  452. return dispatch(actionCreator.apply(this, arguments));
  453. };
  454. }
  455. /**
  456. * Turns an object whose values are action creators, into an object with the
  457. * same keys, but with every function wrapped into a `dispatch` call so they
  458. * may be invoked directly. This is just a convenience method, as you can call
  459. * `store.dispatch(MyActionCreators.doSomething())` yourself just fine.
  460. *
  461. * For convenience, you can also pass an action creator as the first argument,
  462. * and get a dispatch wrapped function in return.
  463. *
  464. * @param {Function|Object} actionCreators An object whose values are action
  465. * creator functions. One handy way to obtain it is to use ES6 `import * as`
  466. * syntax. You may also pass a single function.
  467. *
  468. * @param {Function} dispatch The `dispatch` function available on your Redux
  469. * store.
  470. *
  471. * @returns {Function|Object} The object mimicking the original object, but with
  472. * every action creator wrapped into the `dispatch` call. If you passed a
  473. * function as `actionCreators`, the return value will also be a single
  474. * function.
  475. */
  476. function bindActionCreators(actionCreators, dispatch) {
  477. if (typeof actionCreators === 'function') {
  478. return bindActionCreator(actionCreators, dispatch);
  479. }
  480. if (typeof actionCreators !== 'object' || actionCreators === null) {
  481. 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\"?");
  482. }
  483. var boundActionCreators = {};
  484. for (var key in actionCreators) {
  485. var actionCreator = actionCreators[key];
  486. if (typeof actionCreator === 'function') {
  487. boundActionCreators[key] = bindActionCreator(actionCreator, dispatch);
  488. }
  489. }
  490. return boundActionCreators;
  491. }
  492. function _defineProperty(obj, key, value) {
  493. if (key in obj) {
  494. Object.defineProperty(obj, key, {
  495. value: value,
  496. enumerable: true,
  497. configurable: true,
  498. writable: true
  499. });
  500. } else {
  501. obj[key] = value;
  502. }
  503. return obj;
  504. }
  505. function ownKeys(object, enumerableOnly) {
  506. var keys = Object.keys(object);
  507. if (Object.getOwnPropertySymbols) {
  508. var symbols = Object.getOwnPropertySymbols(object);
  509. if (enumerableOnly) symbols = symbols.filter(function (sym) {
  510. return Object.getOwnPropertyDescriptor(object, sym).enumerable;
  511. });
  512. keys.push.apply(keys, symbols);
  513. }
  514. return keys;
  515. }
  516. function _objectSpread2(target) {
  517. for (var i = 1; i < arguments.length; i++) {
  518. var source = arguments[i] != null ? arguments[i] : {};
  519. if (i % 2) {
  520. ownKeys(Object(source), true).forEach(function (key) {
  521. _defineProperty(target, key, source[key]);
  522. });
  523. } else if (Object.getOwnPropertyDescriptors) {
  524. Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
  525. } else {
  526. ownKeys(Object(source)).forEach(function (key) {
  527. Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
  528. });
  529. }
  530. }
  531. return target;
  532. }
  533. /**
  534. * Composes single-argument functions from right to left. The rightmost
  535. * function can take multiple arguments as it provides the signature for
  536. * the resulting composite function.
  537. *
  538. * @param {...Function} funcs The functions to compose.
  539. * @returns {Function} A function obtained by composing the argument functions
  540. * from right to left. For example, compose(f, g, h) is identical to doing
  541. * (...args) => f(g(h(...args))).
  542. */
  543. function compose() {
  544. for (var _len = arguments.length, funcs = new Array(_len), _key = 0; _key < _len; _key++) {
  545. funcs[_key] = arguments[_key];
  546. }
  547. if (funcs.length === 0) {
  548. return function (arg) {
  549. return arg;
  550. };
  551. }
  552. if (funcs.length === 1) {
  553. return funcs[0];
  554. }
  555. return funcs.reduce(function (a, b) {
  556. return function () {
  557. return a(b.apply(void 0, arguments));
  558. };
  559. });
  560. }
  561. /**
  562. * Creates a store enhancer that applies middleware to the dispatch method
  563. * of the Redux store. This is handy for a variety of tasks, such as expressing
  564. * asynchronous actions in a concise manner, or logging every action payload.
  565. *
  566. * See `redux-thunk` package as an example of the Redux middleware.
  567. *
  568. * Because middleware is potentially asynchronous, this should be the first
  569. * store enhancer in the composition chain.
  570. *
  571. * Note that each middleware will be given the `dispatch` and `getState` functions
  572. * as named arguments.
  573. *
  574. * @param {...Function} middlewares The middleware chain to be applied.
  575. * @returns {Function} A store enhancer applying the middleware.
  576. */
  577. function applyMiddleware() {
  578. for (var _len = arguments.length, middlewares = new Array(_len), _key = 0; _key < _len; _key++) {
  579. middlewares[_key] = arguments[_key];
  580. }
  581. return function (createStore) {
  582. return function () {
  583. var store = createStore.apply(void 0, arguments);
  584. var _dispatch = function dispatch() {
  585. throw new Error('Dispatching while constructing your middleware is not allowed. ' + 'Other middleware would not be applied to this dispatch.');
  586. };
  587. var middlewareAPI = {
  588. getState: store.getState,
  589. dispatch: function dispatch() {
  590. return _dispatch.apply(void 0, arguments);
  591. }
  592. };
  593. var chain = middlewares.map(function (middleware) {
  594. return middleware(middlewareAPI);
  595. });
  596. _dispatch = compose.apply(void 0, chain)(store.dispatch);
  597. return _objectSpread2(_objectSpread2({}, store), {}, {
  598. dispatch: _dispatch
  599. });
  600. };
  601. };
  602. }
  603. /*
  604. * This is a dummy function to check if the function name has been altered by minification.
  605. * If the function has been minified and NODE_ENV !== 'production', warn the user.
  606. */
  607. function isCrushed() {}
  608. if (typeof isCrushed.name === 'string' && isCrushed.name !== 'isCrushed') {
  609. 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.');
  610. }
  611. exports.__DO_NOT_USE__ActionTypes = ActionTypes;
  612. exports.applyMiddleware = applyMiddleware;
  613. exports.bindActionCreators = bindActionCreators;
  614. exports.combineReducers = combineReducers;
  615. exports.compose = compose;
  616. exports.createStore = createStore;
  617. Object.defineProperty(exports, '__esModule', { value: true });
  618. })));