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