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 |
|
7 |
|
8 | var $$observable = (function () {
|
9 | return typeof Symbol === 'function' && Symbol.observable || '@@observable';
|
10 | })();
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | var randomString = function randomString() {
|
19 | return Math.random().toString(36).substring(7).split('').join('.');
|
20 | };
|
21 |
|
22 | var ActionTypes = {
|
23 | INIT: "@@redux/INIT" + randomString(),
|
24 | REPLACE: "@@redux/REPLACE" + randomString(),
|
25 | PROBE_UNKNOWN_ACTION: function PROBE_UNKNOWN_ACTION() {
|
26 | return "@@redux/PROBE_UNKNOWN_ACTION" + randomString();
|
27 | }
|
28 | };
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 | function isPlainObject(obj) {
|
35 | if (typeof obj !== 'object' || obj === null) return false;
|
36 | var proto = obj;
|
37 |
|
38 | while (Object.getPrototypeOf(proto) !== null) {
|
39 | proto = Object.getPrototypeOf(proto);
|
40 | }
|
41 |
|
42 | return Object.getPrototypeOf(obj) === proto;
|
43 | }
|
44 |
|
45 | function kindOf(val) {
|
46 | var typeOfVal = typeof val;
|
47 |
|
48 | {
|
49 |
|
50 | function miniKindOf(val) {
|
51 | if (val === void 0) return 'undefined';
|
52 | if (val === null) return 'null';
|
53 | var type = typeof val;
|
54 |
|
55 | switch (type) {
|
56 | case 'boolean':
|
57 | case 'string':
|
58 | case 'number':
|
59 | case 'symbol':
|
60 | case 'function':
|
61 | {
|
62 | return type;
|
63 | }
|
64 | }
|
65 |
|
66 | if (Array.isArray(val)) return 'array';
|
67 | if (isDate(val)) return 'date';
|
68 | if (isError(val)) return 'error';
|
69 | var constructorName = ctorName(val);
|
70 |
|
71 | switch (constructorName) {
|
72 | case 'Symbol':
|
73 | case 'Promise':
|
74 | case 'WeakMap':
|
75 | case 'WeakSet':
|
76 | case 'Map':
|
77 | case 'Set':
|
78 | return constructorName;
|
79 | }
|
80 |
|
81 |
|
82 | return type.slice(8, -1).toLowerCase().replace(/\s/g, '');
|
83 | }
|
84 |
|
85 | function ctorName(val) {
|
86 | return typeof val.constructor === 'function' ? val.constructor.name : null;
|
87 | }
|
88 |
|
89 | function isError(val) {
|
90 | return val instanceof Error || typeof val.message === 'string' && val.constructor && typeof val.constructor.stackTraceLimit === 'number';
|
91 | }
|
92 |
|
93 | function isDate(val) {
|
94 | if (val instanceof Date) return true;
|
95 | return typeof val.toDateString === 'function' && typeof val.getDate === 'function' && typeof val.setDate === 'function';
|
96 | }
|
97 |
|
98 | typeOfVal = miniKindOf(val);
|
99 | }
|
100 |
|
101 | return typeOfVal;
|
102 | }
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 | function createStore(reducer, preloadedState, enhancer) {
|
131 | var _ref2;
|
132 |
|
133 | if (typeof preloadedState === 'function' && typeof enhancer === 'function' || typeof enhancer === 'function' && typeof arguments[3] === 'function') {
|
134 | 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.');
|
135 | }
|
136 |
|
137 | if (typeof preloadedState === 'function' && typeof enhancer === 'undefined') {
|
138 | enhancer = preloadedState;
|
139 | preloadedState = undefined;
|
140 | }
|
141 |
|
142 | if (typeof enhancer !== 'undefined') {
|
143 | if (typeof enhancer !== 'function') {
|
144 | throw new Error("Expected the enhancer to be a function. Instead, received: '" + kindOf(enhancer) + "'");
|
145 | }
|
146 |
|
147 | return enhancer(createStore)(reducer, preloadedState);
|
148 | }
|
149 |
|
150 | if (typeof reducer !== 'function') {
|
151 | throw new Error("Expected the root reducer to be a function. Instead, received: '" + kindOf(reducer) + "'");
|
152 | }
|
153 |
|
154 | var currentReducer = reducer;
|
155 | var currentState = preloadedState;
|
156 | var currentListeners = [];
|
157 | var nextListeners = currentListeners;
|
158 | var isDispatching = false;
|
159 | |
160 |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 | function ensureCanMutateNextListeners() {
|
168 | if (nextListeners === currentListeners) {
|
169 | nextListeners = currentListeners.slice();
|
170 | }
|
171 | }
|
172 | |
173 |
|
174 |
|
175 |
|
176 |
|
177 |
|
178 |
|
179 | function getState() {
|
180 | if (isDispatching) {
|
181 | 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.');
|
182 | }
|
183 |
|
184 | return currentState;
|
185 | }
|
186 | |
187 |
|
188 |
|
189 |
|
190 |
|
191 |
|
192 |
|
193 |
|
194 |
|
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 |
|
201 |
|
202 |
|
203 |
|
204 |
|
205 |
|
206 |
|
207 |
|
208 |
|
209 |
|
210 |
|
211 | function subscribe(listener) {
|
212 | if (typeof listener !== 'function') {
|
213 | throw new Error("Expected the listener to be a function. Instead, received: '" + kindOf(listener) + "'");
|
214 | }
|
215 |
|
216 | if (isDispatching) {
|
217 | 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.');
|
218 | }
|
219 |
|
220 | var isSubscribed = true;
|
221 | ensureCanMutateNextListeners();
|
222 | nextListeners.push(listener);
|
223 | return function unsubscribe() {
|
224 | if (!isSubscribed) {
|
225 | return;
|
226 | }
|
227 |
|
228 | if (isDispatching) {
|
229 | 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.');
|
230 | }
|
231 |
|
232 | isSubscribed = false;
|
233 | ensureCanMutateNextListeners();
|
234 | var index = nextListeners.indexOf(listener);
|
235 | nextListeners.splice(index, 1);
|
236 | currentListeners = null;
|
237 | };
|
238 | }
|
239 | |
240 |
|
241 |
|
242 |
|
243 |
|
244 |
|
245 |
|
246 |
|
247 |
|
248 |
|
249 |
|
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 |
|
258 |
|
259 |
|
260 |
|
261 |
|
262 |
|
263 |
|
264 |
|
265 |
|
266 | function dispatch(action) {
|
267 | if (!isPlainObject(action)) {
|
268 | 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.");
|
269 | }
|
270 |
|
271 | if (typeof action.type === 'undefined') {
|
272 | throw new Error('Actions may not have an undefined "type" property. You may have misspelled an action type string constant.');
|
273 | }
|
274 |
|
275 | if (isDispatching) {
|
276 | throw new Error('Reducers may not dispatch actions.');
|
277 | }
|
278 |
|
279 | try {
|
280 | isDispatching = true;
|
281 | currentState = currentReducer(currentState, action);
|
282 | } finally {
|
283 | isDispatching = false;
|
284 | }
|
285 |
|
286 | var listeners = currentListeners = nextListeners;
|
287 |
|
288 | for (var i = 0; i < listeners.length; i++) {
|
289 | var listener = listeners[i];
|
290 | listener();
|
291 | }
|
292 |
|
293 | return action;
|
294 | }
|
295 | |
296 |
|
297 |
|
298 |
|
299 |
|
300 |
|
301 |
|
302 |
|
303 |
|
304 |
|
305 |
|
306 |
|
307 | function replaceReducer(nextReducer) {
|
308 | if (typeof nextReducer !== 'function') {
|
309 | throw new Error("Expected the nextReducer to be a function. Instead, received: '" + kindOf(nextReducer));
|
310 | }
|
311 |
|
312 | currentReducer = nextReducer;
|
313 |
|
314 |
|
315 |
|
316 |
|
317 | dispatch({
|
318 | type: ActionTypes.REPLACE
|
319 | });
|
320 | }
|
321 | |
322 |
|
323 |
|
324 |
|
325 |
|
326 |
|
327 |
|
328 |
|
329 | function observable() {
|
330 | var _ref;
|
331 |
|
332 | var outerSubscribe = subscribe;
|
333 | return _ref = {
|
334 | |
335 |
|
336 |
|
337 |
|
338 |
|
339 |
|
340 |
|
341 |
|
342 | subscribe: function subscribe(observer) {
|
343 | if (typeof observer !== 'object' || observer === null) {
|
344 | throw new Error("Expected the observer to be an object. Instead, received: '" + kindOf(observer) + "'");
|
345 | }
|
346 |
|
347 | function observeState() {
|
348 | if (observer.next) {
|
349 | observer.next(getState());
|
350 | }
|
351 | }
|
352 |
|
353 | observeState();
|
354 | var unsubscribe = outerSubscribe(observeState);
|
355 | return {
|
356 | unsubscribe: unsubscribe
|
357 | };
|
358 | }
|
359 | }, _ref[$$observable] = function () {
|
360 | return this;
|
361 | }, _ref;
|
362 | }
|
363 |
|
364 |
|
365 |
|
366 |
|
367 | dispatch({
|
368 | type: ActionTypes.INIT
|
369 | });
|
370 | return _ref2 = {
|
371 | dispatch: dispatch,
|
372 | subscribe: subscribe,
|
373 | getState: getState,
|
374 | replaceReducer: replaceReducer
|
375 | }, _ref2[$$observable] = observable, _ref2;
|
376 | }
|
377 |
|
378 |
|
379 |
|
380 |
|
381 |
|
382 |
|
383 |
|
384 | function warning(message) {
|
385 |
|
386 | if (typeof console !== 'undefined' && typeof console.error === 'function') {
|
387 | console.error(message);
|
388 | }
|
389 |
|
390 |
|
391 |
|
392 | try {
|
393 |
|
394 |
|
395 |
|
396 | throw new Error(message);
|
397 | } catch (e) {}
|
398 |
|
399 | }
|
400 |
|
401 | function getUnexpectedStateShapeWarningMessage(inputState, reducers, action, unexpectedKeyCache) {
|
402 | var reducerKeys = Object.keys(reducers);
|
403 | var argumentName = action && action.type === ActionTypes.INIT ? 'preloadedState argument passed to createStore' : 'previous state received by the reducer';
|
404 |
|
405 | if (reducerKeys.length === 0) {
|
406 | return 'Store does not have a valid reducer. Make sure the argument passed ' + 'to combineReducers is an object whose values are reducers.';
|
407 | }
|
408 |
|
409 | if (!isPlainObject(inputState)) {
|
410 | return "The " + argumentName + " has unexpected type of \"" + kindOf(inputState) + "\". Expected argument to be an object with the following " + ("keys: \"" + reducerKeys.join('", "') + "\"");
|
411 | }
|
412 |
|
413 | var unexpectedKeys = Object.keys(inputState).filter(function (key) {
|
414 | return !reducers.hasOwnProperty(key) && !unexpectedKeyCache[key];
|
415 | });
|
416 | unexpectedKeys.forEach(function (key) {
|
417 | unexpectedKeyCache[key] = true;
|
418 | });
|
419 | if (action && action.type === ActionTypes.REPLACE) return;
|
420 |
|
421 | if (unexpectedKeys.length > 0) {
|
422 | 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.");
|
423 | }
|
424 | }
|
425 |
|
426 | function assertReducerShape(reducers) {
|
427 | Object.keys(reducers).forEach(function (key) {
|
428 | var reducer = reducers[key];
|
429 | var initialState = reducer(undefined, {
|
430 | type: ActionTypes.INIT
|
431 | });
|
432 |
|
433 | if (typeof initialState === 'undefined') {
|
434 | 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.");
|
435 | }
|
436 |
|
437 | if (typeof reducer(undefined, {
|
438 | type: ActionTypes.PROBE_UNKNOWN_ACTION()
|
439 | }) === 'undefined') {
|
440 | 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.");
|
441 | }
|
442 | });
|
443 | }
|
444 |
|
445 |
|
446 |
|
447 |
|
448 |
|
449 |
|
450 |
|
451 |
|
452 |
|
453 |
|
454 |
|
455 |
|
456 |
|
457 |
|
458 |
|
459 |
|
460 |
|
461 |
|
462 | function combineReducers(reducers) {
|
463 | var reducerKeys = Object.keys(reducers);
|
464 | var finalReducers = {};
|
465 |
|
466 | for (var i = 0; i < reducerKeys.length; i++) {
|
467 | var key = reducerKeys[i];
|
468 |
|
469 | {
|
470 | if (typeof reducers[key] === 'undefined') {
|
471 | warning("No reducer provided for key \"" + key + "\"");
|
472 | }
|
473 | }
|
474 |
|
475 | if (typeof reducers[key] === 'function') {
|
476 | finalReducers[key] = reducers[key];
|
477 | }
|
478 | }
|
479 |
|
480 | var finalReducerKeys = Object.keys(finalReducers);
|
481 |
|
482 |
|
483 | var unexpectedKeyCache;
|
484 |
|
485 | {
|
486 | unexpectedKeyCache = {};
|
487 | }
|
488 |
|
489 | var shapeAssertionError;
|
490 |
|
491 | try {
|
492 | assertReducerShape(finalReducers);
|
493 | } catch (e) {
|
494 | shapeAssertionError = e;
|
495 | }
|
496 |
|
497 | return function combination(state, action) {
|
498 | if (state === void 0) {
|
499 | state = {};
|
500 | }
|
501 |
|
502 | if (shapeAssertionError) {
|
503 | throw shapeAssertionError;
|
504 | }
|
505 |
|
506 | {
|
507 | var warningMessage = getUnexpectedStateShapeWarningMessage(state, finalReducers, action, unexpectedKeyCache);
|
508 |
|
509 | if (warningMessage) {
|
510 | warning(warningMessage);
|
511 | }
|
512 | }
|
513 |
|
514 | var hasChanged = false;
|
515 | var nextState = {};
|
516 |
|
517 | for (var _i = 0; _i < finalReducerKeys.length; _i++) {
|
518 | var _key = finalReducerKeys[_i];
|
519 | var reducer = finalReducers[_key];
|
520 | var previousStateForKey = state[_key];
|
521 | var nextStateForKey = reducer(previousStateForKey, action);
|
522 |
|
523 | if (typeof nextStateForKey === 'undefined') {
|
524 | var actionType = action && action.type;
|
525 | 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.");
|
526 | }
|
527 |
|
528 | nextState[_key] = nextStateForKey;
|
529 | hasChanged = hasChanged || nextStateForKey !== previousStateForKey;
|
530 | }
|
531 |
|
532 | hasChanged = hasChanged || finalReducerKeys.length !== Object.keys(state).length;
|
533 | return hasChanged ? nextState : state;
|
534 | };
|
535 | }
|
536 |
|
537 | function bindActionCreator(actionCreator, dispatch) {
|
538 | return function () {
|
539 | return dispatch(actionCreator.apply(this, arguments));
|
540 | };
|
541 | }
|
542 |
|
543 |
|
544 |
|
545 |
|
546 |
|
547 |
|
548 |
|
549 |
|
550 |
|
551 |
|
552 |
|
553 |
|
554 |
|
555 |
|
556 |
|
557 |
|
558 |
|
559 |
|
560 |
|
561 |
|
562 |
|
563 |
|
564 |
|
565 | function bindActionCreators(actionCreators, dispatch) {
|
566 | if (typeof actionCreators === 'function') {
|
567 | return bindActionCreator(actionCreators, dispatch);
|
568 | }
|
569 |
|
570 | if (typeof actionCreators !== 'object' || actionCreators === null) {
|
571 | 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\"?");
|
572 | }
|
573 |
|
574 | var boundActionCreators = {};
|
575 |
|
576 | for (var key in actionCreators) {
|
577 | var actionCreator = actionCreators[key];
|
578 |
|
579 | if (typeof actionCreator === 'function') {
|
580 | boundActionCreators[key] = bindActionCreator(actionCreator, dispatch);
|
581 | }
|
582 | }
|
583 |
|
584 | return boundActionCreators;
|
585 | }
|
586 |
|
587 | function _defineProperty(obj, key, value) {
|
588 | if (key in obj) {
|
589 | Object.defineProperty(obj, key, {
|
590 | value: value,
|
591 | enumerable: true,
|
592 | configurable: true,
|
593 | writable: true
|
594 | });
|
595 | } else {
|
596 | obj[key] = value;
|
597 | }
|
598 |
|
599 | return obj;
|
600 | }
|
601 |
|
602 | function ownKeys(object, enumerableOnly) {
|
603 | var keys = Object.keys(object);
|
604 |
|
605 | if (Object.getOwnPropertySymbols) {
|
606 | var symbols = Object.getOwnPropertySymbols(object);
|
607 | if (enumerableOnly) symbols = symbols.filter(function (sym) {
|
608 | return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
609 | });
|
610 | keys.push.apply(keys, symbols);
|
611 | }
|
612 |
|
613 | return keys;
|
614 | }
|
615 |
|
616 | function _objectSpread2(target) {
|
617 | for (var i = 1; i < arguments.length; i++) {
|
618 | var source = arguments[i] != null ? arguments[i] : {};
|
619 |
|
620 | if (i % 2) {
|
621 | ownKeys(Object(source), true).forEach(function (key) {
|
622 | _defineProperty(target, key, source[key]);
|
623 | });
|
624 | } else if (Object.getOwnPropertyDescriptors) {
|
625 | Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
626 | } else {
|
627 | ownKeys(Object(source)).forEach(function (key) {
|
628 | Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
629 | });
|
630 | }
|
631 | }
|
632 |
|
633 | return target;
|
634 | }
|
635 |
|
636 |
|
637 |
|
638 |
|
639 |
|
640 |
|
641 |
|
642 |
|
643 |
|
644 |
|
645 |
|
646 | function compose() {
|
647 | for (var _len = arguments.length, funcs = new Array(_len), _key = 0; _key < _len; _key++) {
|
648 | funcs[_key] = arguments[_key];
|
649 | }
|
650 |
|
651 | if (funcs.length === 0) {
|
652 | return function (arg) {
|
653 | return arg;
|
654 | };
|
655 | }
|
656 |
|
657 | if (funcs.length === 1) {
|
658 | return funcs[0];
|
659 | }
|
660 |
|
661 | return funcs.reduce(function (a, b) {
|
662 | return function () {
|
663 | return a(b.apply(void 0, arguments));
|
664 | };
|
665 | });
|
666 | }
|
667 |
|
668 |
|
669 |
|
670 |
|
671 |
|
672 |
|
673 |
|
674 |
|
675 |
|
676 |
|
677 |
|
678 |
|
679 |
|
680 |
|
681 |
|
682 |
|
683 |
|
684 |
|
685 | function applyMiddleware() {
|
686 | for (var _len = arguments.length, middlewares = new Array(_len), _key = 0; _key < _len; _key++) {
|
687 | middlewares[_key] = arguments[_key];
|
688 | }
|
689 |
|
690 | return function (createStore) {
|
691 | return function () {
|
692 | var store = createStore.apply(void 0, arguments);
|
693 |
|
694 | var _dispatch = function dispatch() {
|
695 | throw new Error('Dispatching while constructing your middleware is not allowed. ' + 'Other middleware would not be applied to this dispatch.');
|
696 | };
|
697 |
|
698 | var middlewareAPI = {
|
699 | getState: store.getState,
|
700 | dispatch: function dispatch() {
|
701 | return _dispatch.apply(void 0, arguments);
|
702 | }
|
703 | };
|
704 | var chain = middlewares.map(function (middleware) {
|
705 | return middleware(middlewareAPI);
|
706 | });
|
707 | _dispatch = compose.apply(void 0, chain)(store.dispatch);
|
708 | return _objectSpread2(_objectSpread2({}, store), {}, {
|
709 | dispatch: _dispatch
|
710 | });
|
711 | };
|
712 | };
|
713 | }
|
714 |
|
715 |
|
716 |
|
717 |
|
718 |
|
719 |
|
720 | function isCrushed() {}
|
721 |
|
722 | if (typeof isCrushed.name === 'string' && isCrushed.name !== 'isCrushed') {
|
723 | 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.');
|
724 | }
|
725 |
|
726 | exports.__DO_NOT_USE__ActionTypes = ActionTypes;
|
727 | exports.applyMiddleware = applyMiddleware;
|
728 | exports.bindActionCreators = bindActionCreators;
|
729 | exports.combineReducers = combineReducers;
|
730 | exports.compose = compose;
|
731 | exports.createStore = createStore;
|
732 |
|
733 | Object.defineProperty(exports, '__esModule', { value: true });
|
734 |
|
735 | })));
|