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