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