UNPKG

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