1 | import React__default, { Component, createElement, PureComponent, Children } from 'react';
|
2 | import { isObservableArray, isObservableObject, isObservableMap, untracked, createAtom, Reaction, _allowStateChanges, $mobx, spy, getDebugName } from 'mobx';
|
3 |
|
4 | function _typeof(obj) {
|
5 | if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
|
6 | _typeof = function (obj) {
|
7 | return typeof obj;
|
8 | };
|
9 | } else {
|
10 | _typeof = function (obj) {
|
11 | return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
12 | };
|
13 | }
|
14 |
|
15 | return _typeof(obj);
|
16 | }
|
17 |
|
18 | function _classCallCheck(instance, Constructor) {
|
19 | if (!(instance instanceof Constructor)) {
|
20 | throw new TypeError("Cannot call a class as a function");
|
21 | }
|
22 | }
|
23 |
|
24 | function _defineProperties(target, props) {
|
25 | for (var i = 0; i < props.length; i++) {
|
26 | var descriptor = props[i];
|
27 | descriptor.enumerable = descriptor.enumerable || false;
|
28 | descriptor.configurable = true;
|
29 | if ("value" in descriptor) descriptor.writable = true;
|
30 | Object.defineProperty(target, descriptor.key, descriptor);
|
31 | }
|
32 | }
|
33 |
|
34 | function _createClass(Constructor, protoProps, staticProps) {
|
35 | if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
36 | if (staticProps) _defineProperties(Constructor, staticProps);
|
37 | return Constructor;
|
38 | }
|
39 |
|
40 | function _defineProperty(obj, key, value) {
|
41 | if (key in obj) {
|
42 | Object.defineProperty(obj, key, {
|
43 | value: value,
|
44 | enumerable: true,
|
45 | configurable: true,
|
46 | writable: true
|
47 | });
|
48 | } else {
|
49 | obj[key] = value;
|
50 | }
|
51 |
|
52 | return obj;
|
53 | }
|
54 |
|
55 | function _objectSpread(target) {
|
56 | for (var i = 1; i < arguments.length; i++) {
|
57 | var source = arguments[i] != null ? arguments[i] : {};
|
58 | var ownKeys = Object.keys(source);
|
59 |
|
60 | if (typeof Object.getOwnPropertySymbols === 'function') {
|
61 | ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
|
62 | return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
63 | }));
|
64 | }
|
65 |
|
66 | ownKeys.forEach(function (key) {
|
67 | _defineProperty(target, key, source[key]);
|
68 | });
|
69 | }
|
70 |
|
71 | return target;
|
72 | }
|
73 |
|
74 | function _inherits(subClass, superClass) {
|
75 | if (typeof superClass !== "function" && superClass !== null) {
|
76 | throw new TypeError("Super expression must either be null or a function");
|
77 | }
|
78 |
|
79 | subClass.prototype = Object.create(superClass && superClass.prototype, {
|
80 | constructor: {
|
81 | value: subClass,
|
82 | writable: true,
|
83 | configurable: true
|
84 | }
|
85 | });
|
86 | if (superClass) _setPrototypeOf(subClass, superClass);
|
87 | }
|
88 |
|
89 | function _getPrototypeOf(o) {
|
90 | _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
|
91 | return o.__proto__ || Object.getPrototypeOf(o);
|
92 | };
|
93 | return _getPrototypeOf(o);
|
94 | }
|
95 |
|
96 | function _setPrototypeOf(o, p) {
|
97 | _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
|
98 | o.__proto__ = p;
|
99 | return o;
|
100 | };
|
101 |
|
102 | return _setPrototypeOf(o, p);
|
103 | }
|
104 |
|
105 | function _assertThisInitialized(self) {
|
106 | if (self === void 0) {
|
107 | throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
108 | }
|
109 |
|
110 | return self;
|
111 | }
|
112 |
|
113 | function _possibleConstructorReturn(self, call) {
|
114 | if (call && (typeof call === "object" || typeof call === "function")) {
|
115 | return call;
|
116 | }
|
117 |
|
118 | return _assertThisInitialized(self);
|
119 | }
|
120 |
|
121 |
|
122 |
|
123 | function unwrapExports (x) {
|
124 | return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x.default : x;
|
125 | }
|
126 |
|
127 | function createCommonjsModule(fn, module) {
|
128 | return module = { exports: {} }, fn(module, module.exports), module.exports;
|
129 | }
|
130 |
|
131 | var reactIs_production_min = createCommonjsModule(function (module, exports) {
|
132 | Object.defineProperty(exports,"__esModule",{value:!0});
|
133 | var b="function"===typeof Symbol&&Symbol.for,c=b?Symbol.for("react.element"):60103,d=b?Symbol.for("react.portal"):60106,e=b?Symbol.for("react.fragment"):60107,f=b?Symbol.for("react.strict_mode"):60108,g=b?Symbol.for("react.profiler"):60114,h=b?Symbol.for("react.provider"):60109,k=b?Symbol.for("react.context"):60110,l=b?Symbol.for("react.async_mode"):60111,m=b?Symbol.for("react.forward_ref"):60112,n=b?Symbol.for("react.placeholder"):60113;
|
134 | function q(a){if("object"===typeof a&&null!==a){var p=a.$$typeof;switch(p){case c:switch(a=a.type,a){case l:case e:case g:case f:return a;default:switch(a=a&&a.$$typeof,a){case k:case m:case h:return a;default:return p}}case d:return p}}}exports.typeOf=q;exports.AsyncMode=l;exports.ContextConsumer=k;exports.ContextProvider=h;exports.Element=c;exports.ForwardRef=m;exports.Fragment=e;exports.Profiler=g;exports.Portal=d;exports.StrictMode=f;
|
135 | exports.isValidElementType=function(a){return "string"===typeof a||"function"===typeof a||a===e||a===l||a===g||a===f||a===n||"object"===typeof a&&null!==a&&("function"===typeof a.then||a.$$typeof===h||a.$$typeof===k||a.$$typeof===m)};exports.isAsyncMode=function(a){return q(a)===l};exports.isContextConsumer=function(a){return q(a)===k};exports.isContextProvider=function(a){return q(a)===h};exports.isElement=function(a){return "object"===typeof a&&null!==a&&a.$$typeof===c};
|
136 | exports.isForwardRef=function(a){return q(a)===m};exports.isFragment=function(a){return q(a)===e};exports.isProfiler=function(a){return q(a)===g};exports.isPortal=function(a){return q(a)===d};exports.isStrictMode=function(a){return q(a)===f};
|
137 | });
|
138 |
|
139 | unwrapExports(reactIs_production_min);
|
140 | var reactIs_production_min_1 = reactIs_production_min.typeOf;
|
141 | var reactIs_production_min_2 = reactIs_production_min.AsyncMode;
|
142 | var reactIs_production_min_3 = reactIs_production_min.ContextConsumer;
|
143 | var reactIs_production_min_4 = reactIs_production_min.ContextProvider;
|
144 | var reactIs_production_min_5 = reactIs_production_min.Element;
|
145 | var reactIs_production_min_6 = reactIs_production_min.ForwardRef;
|
146 | var reactIs_production_min_7 = reactIs_production_min.Fragment;
|
147 | var reactIs_production_min_8 = reactIs_production_min.Profiler;
|
148 | var reactIs_production_min_9 = reactIs_production_min.Portal;
|
149 | var reactIs_production_min_10 = reactIs_production_min.StrictMode;
|
150 | var reactIs_production_min_11 = reactIs_production_min.isValidElementType;
|
151 | var reactIs_production_min_12 = reactIs_production_min.isAsyncMode;
|
152 | var reactIs_production_min_13 = reactIs_production_min.isContextConsumer;
|
153 | var reactIs_production_min_14 = reactIs_production_min.isContextProvider;
|
154 | var reactIs_production_min_15 = reactIs_production_min.isElement;
|
155 | var reactIs_production_min_16 = reactIs_production_min.isForwardRef;
|
156 | var reactIs_production_min_17 = reactIs_production_min.isFragment;
|
157 | var reactIs_production_min_18 = reactIs_production_min.isProfiler;
|
158 | var reactIs_production_min_19 = reactIs_production_min.isPortal;
|
159 | var reactIs_production_min_20 = reactIs_production_min.isStrictMode;
|
160 |
|
161 | var reactIs = createCommonjsModule(function (module) {
|
162 |
|
163 | {
|
164 | module.exports = reactIs_production_min;
|
165 | }
|
166 | });
|
167 |
|
168 | var _ReactIs$ForwardRef;
|
169 |
|
170 | function _defineProperty$1(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
171 |
|
172 |
|
173 |
|
174 |
|
175 |
|
176 |
|
177 |
|
178 | var REACT_STATICS = {
|
179 | childContextTypes: true,
|
180 | contextTypes: true,
|
181 | defaultProps: true,
|
182 | displayName: true,
|
183 | getDefaultProps: true,
|
184 | getDerivedStateFromProps: true,
|
185 | mixins: true,
|
186 | propTypes: true,
|
187 | type: true
|
188 | };
|
189 |
|
190 | var KNOWN_STATICS = {
|
191 | name: true,
|
192 | length: true,
|
193 | prototype: true,
|
194 | caller: true,
|
195 | callee: true,
|
196 | arguments: true,
|
197 | arity: true
|
198 | };
|
199 |
|
200 | var TYPE_STATICS = _defineProperty$1({}, reactIs.ForwardRef, (_ReactIs$ForwardRef = {}, _defineProperty$1(_ReactIs$ForwardRef, '$$typeof', true), _defineProperty$1(_ReactIs$ForwardRef, 'render', true), _ReactIs$ForwardRef));
|
201 |
|
202 | var defineProperty = Object.defineProperty;
|
203 | var getOwnPropertyNames = Object.getOwnPropertyNames;
|
204 | var getOwnPropertySymbols = Object.getOwnPropertySymbols;
|
205 | var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
|
206 | var getPrototypeOf = Object.getPrototypeOf;
|
207 | var objectPrototype = Object.prototype;
|
208 |
|
209 | function hoistNonReactStatics(targetComponent, sourceComponent, blacklist) {
|
210 | if (typeof sourceComponent !== 'string') {
|
211 |
|
212 |
|
213 | if (objectPrototype) {
|
214 | var inheritedComponent = getPrototypeOf(sourceComponent);
|
215 | if (inheritedComponent && inheritedComponent !== objectPrototype) {
|
216 | hoistNonReactStatics(targetComponent, inheritedComponent, blacklist);
|
217 | }
|
218 | }
|
219 |
|
220 | var keys = getOwnPropertyNames(sourceComponent);
|
221 |
|
222 | if (getOwnPropertySymbols) {
|
223 | keys = keys.concat(getOwnPropertySymbols(sourceComponent));
|
224 | }
|
225 |
|
226 | var targetStatics = TYPE_STATICS[targetComponent['$$typeof']] || REACT_STATICS;
|
227 | var sourceStatics = TYPE_STATICS[sourceComponent['$$typeof']] || REACT_STATICS;
|
228 |
|
229 | for (var i = 0; i < keys.length; ++i) {
|
230 | var key = keys[i];
|
231 | if (!KNOWN_STATICS[key] && !(blacklist && blacklist[key]) && !(sourceStatics && sourceStatics[key]) && !(targetStatics && targetStatics[key])) {
|
232 | var descriptor = getOwnPropertyDescriptor(sourceComponent, key);
|
233 | try {
|
234 |
|
235 | defineProperty(targetComponent, key, descriptor);
|
236 | } catch (e) {}
|
237 | }
|
238 | }
|
239 |
|
240 | return targetComponent;
|
241 | }
|
242 |
|
243 | return targetComponent;
|
244 | }
|
245 |
|
246 | var hoistNonReactStatics_cjs = hoistNonReactStatics;
|
247 |
|
248 | var EventEmitter =
|
249 |
|
250 | function () {
|
251 | function EventEmitter() {
|
252 | _classCallCheck(this, EventEmitter);
|
253 |
|
254 | this.listeners = [];
|
255 | }
|
256 |
|
257 | _createClass(EventEmitter, [{
|
258 | key: "on",
|
259 | value: function on(cb) {
|
260 | var _this = this;
|
261 |
|
262 | this.listeners.push(cb);
|
263 | return function () {
|
264 | var index = _this.listeners.indexOf(cb);
|
265 |
|
266 | if (index !== -1) _this.listeners.splice(index, 1);
|
267 | };
|
268 | }
|
269 | }, {
|
270 | key: "emit",
|
271 | value: function emit(data) {
|
272 | this.listeners.forEach(function (fn) {
|
273 | return fn(data);
|
274 | });
|
275 | }
|
276 | }]);
|
277 |
|
278 | return EventEmitter;
|
279 | }();
|
280 |
|
281 | function createChainableTypeChecker(validate) {
|
282 | function checkType(isRequired, props, propName, componentName, location, propFullName) {
|
283 | for (var _len = arguments.length, rest = new Array(_len > 6 ? _len - 6 : 0), _key = 6; _key < _len; _key++) {
|
284 | rest[_key - 6] = arguments[_key];
|
285 | }
|
286 |
|
287 | return untracked(function () {
|
288 | componentName = componentName || "<<anonymous>>";
|
289 | propFullName = propFullName || propName;
|
290 |
|
291 | if (props[propName] == null) {
|
292 | if (isRequired) {
|
293 | var actual = props[propName] === null ? "null" : "undefined";
|
294 | return new Error("The " + location + " `" + propFullName + "` is marked as required " + "in `" + componentName + "`, but its value is `" + actual + "`.");
|
295 | }
|
296 |
|
297 | return null;
|
298 | } else {
|
299 | return validate.apply(void 0, [props, propName, componentName, location, propFullName].concat(rest));
|
300 | }
|
301 | });
|
302 | }
|
303 |
|
304 | var chainedCheckType = checkType.bind(null, false);
|
305 | chainedCheckType.isRequired = checkType.bind(null, true);
|
306 | return chainedCheckType;
|
307 | }
|
308 |
|
309 |
|
310 | function isSymbol(propType, propValue) {
|
311 |
|
312 | if (propType === "symbol") {
|
313 | return true;
|
314 | }
|
315 |
|
316 |
|
317 | if (propValue["@@toStringTag"] === "Symbol") {
|
318 | return true;
|
319 | }
|
320 |
|
321 |
|
322 | if (typeof Symbol === "function" && propValue instanceof Symbol) {
|
323 | return true;
|
324 | }
|
325 |
|
326 | return false;
|
327 | }
|
328 |
|
329 |
|
330 | function getPropType(propValue) {
|
331 | var propType = _typeof(propValue);
|
332 |
|
333 | if (Array.isArray(propValue)) {
|
334 | return "array";
|
335 | }
|
336 |
|
337 | if (propValue instanceof RegExp) {
|
338 |
|
339 |
|
340 |
|
341 | return "object";
|
342 | }
|
343 |
|
344 | if (isSymbol(propType, propValue)) {
|
345 | return "symbol";
|
346 | }
|
347 |
|
348 | return propType;
|
349 | }
|
350 |
|
351 |
|
352 |
|
353 | function getPreciseType(propValue) {
|
354 | var propType = getPropType(propValue);
|
355 |
|
356 | if (propType === "object") {
|
357 | if (propValue instanceof Date) {
|
358 | return "date";
|
359 | } else if (propValue instanceof RegExp) {
|
360 | return "regexp";
|
361 | }
|
362 | }
|
363 |
|
364 | return propType;
|
365 | }
|
366 |
|
367 | function createObservableTypeCheckerCreator(allowNativeType, mobxType) {
|
368 | return createChainableTypeChecker(function (props, propName, componentName, location, propFullName) {
|
369 | return untracked(function () {
|
370 | if (allowNativeType) {
|
371 | if (getPropType(props[propName]) === mobxType.toLowerCase()) return null;
|
372 | }
|
373 |
|
374 | var mobxChecker;
|
375 |
|
376 | switch (mobxType) {
|
377 | case "Array":
|
378 | mobxChecker = isObservableArray;
|
379 | break;
|
380 |
|
381 | case "Object":
|
382 | mobxChecker = isObservableObject;
|
383 | break;
|
384 |
|
385 | case "Map":
|
386 | mobxChecker = isObservableMap;
|
387 | break;
|
388 |
|
389 | default:
|
390 | throw new Error("Unexpected mobxType: ".concat(mobxType));
|
391 | }
|
392 |
|
393 | var propValue = props[propName];
|
394 |
|
395 | if (!mobxChecker(propValue)) {
|
396 | var preciseType = getPreciseType(propValue);
|
397 | var nativeTypeExpectationMessage = allowNativeType ? " or javascript `" + mobxType.toLowerCase() + "`" : "";
|
398 | return new Error("Invalid prop `" + propFullName + "` of type `" + preciseType + "` supplied to" + " `" + componentName + "`, expected `mobx.Observable" + mobxType + "`" + nativeTypeExpectationMessage + ".");
|
399 | }
|
400 |
|
401 | return null;
|
402 | });
|
403 | });
|
404 | }
|
405 |
|
406 | function createObservableArrayOfTypeChecker(allowNativeType, typeChecker) {
|
407 | return createChainableTypeChecker(function (props, propName, componentName, location, propFullName) {
|
408 | for (var _len2 = arguments.length, rest = new Array(_len2 > 5 ? _len2 - 5 : 0), _key2 = 5; _key2 < _len2; _key2++) {
|
409 | rest[_key2 - 5] = arguments[_key2];
|
410 | }
|
411 |
|
412 | return untracked(function () {
|
413 | if (typeof typeChecker !== "function") {
|
414 | return new Error("Property `" + propFullName + "` of component `" + componentName + "` has " + "invalid PropType notation.");
|
415 | }
|
416 |
|
417 | var error = createObservableTypeCheckerCreator(allowNativeType, "Array")(props, propName, componentName);
|
418 | if (error instanceof Error) return error;
|
419 | var propValue = props[propName];
|
420 |
|
421 | for (var i = 0; i < propValue.length; i++) {
|
422 | error = typeChecker.apply(void 0, [propValue, i, componentName, location, propFullName + "[" + i + "]"].concat(rest));
|
423 | if (error instanceof Error) return error;
|
424 | }
|
425 |
|
426 | return null;
|
427 | });
|
428 | });
|
429 | }
|
430 |
|
431 | var observableArray = createObservableTypeCheckerCreator(false, "Array");
|
432 | var observableArrayOf = createObservableArrayOfTypeChecker.bind(null, false);
|
433 | var observableMap = createObservableTypeCheckerCreator(false, "Map");
|
434 | var observableObject = createObservableTypeCheckerCreator(false, "Object");
|
435 | var arrayOrObservableArray = createObservableTypeCheckerCreator(true, "Array");
|
436 | var arrayOrObservableArrayOf = createObservableArrayOfTypeChecker.bind(null, true);
|
437 | var objectOrObservableObject = createObservableTypeCheckerCreator(true, "Object");
|
438 |
|
439 | var propTypes = Object.freeze({
|
440 | observableArray: observableArray,
|
441 | observableArrayOf: observableArrayOf,
|
442 | observableMap: observableMap,
|
443 | observableObject: observableObject,
|
444 | arrayOrObservableArray: arrayOrObservableArray,
|
445 | arrayOrObservableArrayOf: arrayOrObservableArrayOf,
|
446 | objectOrObservableObject: objectOrObservableObject
|
447 | });
|
448 |
|
449 | function isStateless(component) {
|
450 |
|
451 |
|
452 | return !(component.prototype && component.prototype.render);
|
453 | }
|
454 | var symbolId = 0;
|
455 | function newSymbol(name) {
|
456 | if (typeof Symbol === "function") {
|
457 | return Symbol(name);
|
458 | }
|
459 |
|
460 | var symbol = "__$mobx-react ".concat(name, " (").concat(symbolId, ")");
|
461 | symbolId++;
|
462 | return symbol;
|
463 | }
|
464 | var mobxMixins = newSymbol("patchMixins");
|
465 | var mobxPatchedDefinition = newSymbol("patchedDefinition");
|
466 |
|
467 | function getMixins(target, methodName) {
|
468 | var mixins = target[mobxMixins] = target[mobxMixins] || {};
|
469 | var methodMixins = mixins[methodName] = mixins[methodName] || {};
|
470 | methodMixins.locks = methodMixins.locks || 0;
|
471 | methodMixins.methods = methodMixins.methods || [];
|
472 | return methodMixins;
|
473 | }
|
474 |
|
475 | function wrapper(realMethod, mixins) {
|
476 | var _this = this;
|
477 |
|
478 | for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
479 | args[_key - 2] = arguments[_key];
|
480 | }
|
481 |
|
482 |
|
483 | mixins.locks++;
|
484 |
|
485 | try {
|
486 | var retVal;
|
487 |
|
488 | if (realMethod !== undefined && realMethod !== null) {
|
489 | retVal = realMethod.apply(this, args);
|
490 | }
|
491 |
|
492 | return retVal;
|
493 | } finally {
|
494 | mixins.locks--;
|
495 |
|
496 | if (mixins.locks === 0) {
|
497 | mixins.methods.forEach(function (mx) {
|
498 | mx.apply(_this, args);
|
499 | });
|
500 | }
|
501 | }
|
502 | }
|
503 |
|
504 | function wrapFunction(realMethod, mixins) {
|
505 | var fn = function fn() {
|
506 | for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
507 | args[_key2] = arguments[_key2];
|
508 | }
|
509 |
|
510 | wrapper.call.apply(wrapper, [this, realMethod, mixins].concat(args));
|
511 | };
|
512 |
|
513 | return fn;
|
514 | }
|
515 |
|
516 | function patch(target, methodName) {
|
517 | var mixins = getMixins(target, methodName);
|
518 |
|
519 | for (var _len3 = arguments.length, mixinMethods = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
|
520 | mixinMethods[_key3 - 2] = arguments[_key3];
|
521 | }
|
522 |
|
523 | for (var _i = 0; _i < mixinMethods.length; _i++) {
|
524 | var mixinMethod = mixinMethods[_i];
|
525 |
|
526 | if (mixins.methods.indexOf(mixinMethod) < 0) {
|
527 | mixins.methods.push(mixinMethod);
|
528 | }
|
529 | }
|
530 |
|
531 | var oldDefinition = Object.getOwnPropertyDescriptor(target, methodName);
|
532 |
|
533 | if (oldDefinition && oldDefinition[mobxPatchedDefinition]) {
|
534 |
|
535 | return;
|
536 | }
|
537 |
|
538 | var originalMethod = target[methodName];
|
539 | var newDefinition = createDefinition(target, methodName, oldDefinition ? oldDefinition.enumerable : undefined, mixins, originalMethod);
|
540 | Object.defineProperty(target, methodName, newDefinition);
|
541 | }
|
542 |
|
543 | function createDefinition(target, methodName, enumerable, mixins, originalMethod) {
|
544 | var _ref;
|
545 |
|
546 | var wrappedFunc = wrapFunction(originalMethod, mixins);
|
547 | return _ref = {}, _defineProperty(_ref, mobxPatchedDefinition, true), _defineProperty(_ref, "get", function get() {
|
548 | return wrappedFunc;
|
549 | }), _defineProperty(_ref, "set", function set(value) {
|
550 | if (this === target) {
|
551 | wrappedFunc = wrapFunction(value, mixins);
|
552 | } else {
|
553 |
|
554 |
|
555 |
|
556 |
|
557 | var newDefinition = createDefinition(this, methodName, enumerable, mixins, value);
|
558 | Object.defineProperty(this, methodName, newDefinition);
|
559 | }
|
560 | }), _defineProperty(_ref, "configurable", true), _defineProperty(_ref, "enumerable", enumerable), _ref;
|
561 | }
|
562 |
|
563 | var injectorContextTypes = {
|
564 | mobxStores: objectOrObservableObject
|
565 | };
|
566 | Object.seal(injectorContextTypes);
|
567 | var proxiedInjectorProps = {
|
568 | contextTypes: {
|
569 | get: function get() {
|
570 | return injectorContextTypes;
|
571 | },
|
572 | set: function set(_) {
|
573 | console.warn("Mobx Injector: you are trying to attach `contextTypes` on an component decorated with `inject` (or `observer`) HOC. Please specify the contextTypes on the wrapped component instead. It is accessible through the `wrappedComponent`");
|
574 | },
|
575 | configurable: true,
|
576 | enumerable: false
|
577 | },
|
578 | isMobxInjector: {
|
579 | value: true,
|
580 | writable: true,
|
581 | configurable: true,
|
582 | enumerable: true
|
583 | }
|
584 | |
585 |
|
586 |
|
587 |
|
588 | };
|
589 |
|
590 | function createStoreInjector(grabStoresFn, component, injectNames) {
|
591 | var displayName = "inject-" + (component.displayName || component.name || component.constructor && component.constructor.name || "Unknown");
|
592 | if (injectNames) displayName += "-with-" + injectNames;
|
593 |
|
594 | var Injector =
|
595 |
|
596 | function (_Component) {
|
597 | _inherits(Injector, _Component);
|
598 |
|
599 | function Injector() {
|
600 | var _getPrototypeOf2;
|
601 |
|
602 | var _this;
|
603 |
|
604 | _classCallCheck(this, Injector);
|
605 |
|
606 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
607 | args[_key] = arguments[_key];
|
608 | }
|
609 |
|
610 | _this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(Injector)).call.apply(_getPrototypeOf2, [this].concat(args)));
|
611 |
|
612 | _this.storeRef = function (instance) {
|
613 | _this.wrappedInstance = instance;
|
614 | };
|
615 |
|
616 | return _this;
|
617 | }
|
618 |
|
619 | _createClass(Injector, [{
|
620 | key: "render",
|
621 | value: function render() {
|
622 |
|
623 |
|
624 |
|
625 | var newProps = {};
|
626 |
|
627 | for (var key in this.props) {
|
628 | if (this.props.hasOwnProperty(key)) {
|
629 | newProps[key] = this.props[key];
|
630 | }
|
631 | }
|
632 |
|
633 | var additionalProps = grabStoresFn(this.context.mobxStores || {}, newProps, this.context) || {};
|
634 |
|
635 | for (var _key2 in additionalProps) {
|
636 | newProps[_key2] = additionalProps[_key2];
|
637 | }
|
638 |
|
639 | if (!isStateless(component)) {
|
640 | newProps.ref = this.storeRef;
|
641 | }
|
642 |
|
643 | return createElement(component, newProps);
|
644 | }
|
645 | }]);
|
646 |
|
647 | return Injector;
|
648 | }(Component);
|
649 |
|
650 |
|
651 | Injector.displayName = displayName;
|
652 | hoistNonReactStatics_cjs(Injector, component);
|
653 | Injector.wrappedComponent = component;
|
654 | Object.defineProperties(Injector, proxiedInjectorProps);
|
655 | return Injector;
|
656 | }
|
657 |
|
658 | function grabStoresByName(storeNames) {
|
659 | return function (baseStores, nextProps) {
|
660 | storeNames.forEach(function (storeName) {
|
661 | if (storeName in nextProps
|
662 | ) return;
|
663 | if (!(storeName in baseStores)) throw new Error("MobX injector: Store '" + storeName + "' is not available! Make sure it is provided by some Provider");
|
664 | nextProps[storeName] = baseStores[storeName];
|
665 | });
|
666 | return nextProps;
|
667 | };
|
668 | }
|
669 |
|
670 |
|
671 |
|
672 |
|
673 |
|
674 |
|
675 |
|
676 |
|
677 | function inject()
|
678 | /* fn(stores, nextProps) or ...storeNames */
|
679 | {
|
680 | var grabStoresFn;
|
681 |
|
682 | if (typeof arguments[0] === "function") {
|
683 | grabStoresFn = arguments[0];
|
684 | return function (componentClass) {
|
685 | var injected = createStoreInjector(grabStoresFn, componentClass);
|
686 | injected.isMobxInjector = false;
|
687 |
|
688 |
|
689 |
|
690 | injected = observer(injected);
|
691 | injected.isMobxInjector = true;
|
692 |
|
693 | return injected;
|
694 | };
|
695 | } else {
|
696 | var storeNames = [];
|
697 |
|
698 | for (var i = 0; i < arguments.length; i++) {
|
699 | storeNames[i] = arguments[i];
|
700 | }
|
701 |
|
702 | grabStoresFn = grabStoresByName(storeNames);
|
703 | return function (componentClass) {
|
704 | return createStoreInjector(grabStoresFn, componentClass, storeNames.join("-"));
|
705 | };
|
706 | }
|
707 | }
|
708 |
|
709 | var ReactIs = require("react-is");
|
710 |
|
711 | var mobxAdminProperty = $mobx || "$mobx";
|
712 | var mobxIsUnmounted = newSymbol("isUnmounted");
|
713 |
|
714 |
|
715 |
|
716 |
|
717 | var isDevtoolsEnabled = false;
|
718 | var isUsingStaticRendering = false;
|
719 | var warnedAboutObserverInjectDeprecation = false;
|
720 |
|
721 | var componentByNodeRegistry = typeof WeakMap !== "undefined" ? new WeakMap() : undefined;
|
722 | var renderReporter = new EventEmitter();
|
723 | var skipRenderKey = newSymbol("skipRender");
|
724 | var isForcingUpdateKey = newSymbol("isForcingUpdate");
|
725 |
|
726 |
|
727 |
|
728 |
|
729 |
|
730 |
|
731 |
|
732 | function setHiddenProp(target, prop, value) {
|
733 | if (!Object.hasOwnProperty.call(target, prop)) {
|
734 | Object.defineProperty(target, prop, {
|
735 | enumerable: false,
|
736 | configurable: true,
|
737 | writable: true,
|
738 | value: value
|
739 | });
|
740 | } else {
|
741 | target[prop] = value;
|
742 | }
|
743 | }
|
744 |
|
745 | function findDOMNode$1(component) {
|
746 |
|
747 | return null;
|
748 | }
|
749 |
|
750 | function reportRendering(component) {
|
751 | var node = findDOMNode$1(component);
|
752 | if (node && componentByNodeRegistry) componentByNodeRegistry.set(node, component);
|
753 | renderReporter.emit({
|
754 | event: "render",
|
755 | renderTime: component.__$mobRenderEnd - component.__$mobRenderStart,
|
756 | totalTime: Date.now() - component.__$mobRenderStart,
|
757 | component: component,
|
758 | node: node
|
759 | });
|
760 | }
|
761 |
|
762 | function trackComponents() {
|
763 | if (typeof WeakMap === "undefined") throw new Error("[mobx-react] tracking components is not supported in this browser.");
|
764 | if (!isDevtoolsEnabled) isDevtoolsEnabled = true;
|
765 | }
|
766 | function useStaticRendering(useStaticRendering) {
|
767 | isUsingStaticRendering = useStaticRendering;
|
768 | }
|
769 |
|
770 |
|
771 |
|
772 |
|
773 | var errorsReporter = new EventEmitter();
|
774 |
|
775 |
|
776 |
|
777 |
|
778 | function patch$1(target, funcName) {
|
779 | patch(target, funcName, reactiveMixin[funcName]);
|
780 | }
|
781 |
|
782 | function shallowEqual(objA, objB) {
|
783 |
|
784 | if (is(objA, objB)) return true;
|
785 |
|
786 | if (_typeof(objA) !== "object" || objA === null || _typeof(objB) !== "object" || objB === null) {
|
787 | return false;
|
788 | }
|
789 |
|
790 | var keysA = Object.keys(objA);
|
791 | var keysB = Object.keys(objB);
|
792 | if (keysA.length !== keysB.length) return false;
|
793 |
|
794 | for (var i = 0; i < keysA.length; i++) {
|
795 | if (!hasOwnProperty.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) {
|
796 | return false;
|
797 | }
|
798 | }
|
799 |
|
800 | return true;
|
801 | }
|
802 |
|
803 | function is(x, y) {
|
804 |
|
805 | if (x === y) {
|
806 | return x !== 0 || 1 / x === 1 / y;
|
807 | } else {
|
808 | return x !== x && y !== y;
|
809 | }
|
810 | }
|
811 |
|
812 | function makeComponentReactive(render) {
|
813 | var _this2 = this;
|
814 |
|
815 | if (isUsingStaticRendering === true) return render.call(this);
|
816 |
|
817 | function reactiveRender() {
|
818 | var _this = this;
|
819 |
|
820 | isRenderingPending = false;
|
821 | var exception = undefined;
|
822 | var rendering = undefined;
|
823 | reaction.track(function () {
|
824 | if (isDevtoolsEnabled) {
|
825 | _this.__$mobRenderStart = Date.now();
|
826 | }
|
827 |
|
828 | try {
|
829 | rendering = _allowStateChanges(false, baseRender);
|
830 | } catch (e) {
|
831 | exception = e;
|
832 | }
|
833 |
|
834 | if (isDevtoolsEnabled) {
|
835 | _this.__$mobRenderEnd = Date.now();
|
836 | }
|
837 | });
|
838 |
|
839 | if (exception) {
|
840 | errorsReporter.emit(exception);
|
841 | throw exception;
|
842 | }
|
843 |
|
844 | return rendering;
|
845 | }
|
846 |
|
847 |
|
848 | var initialName = this.displayName || this.name || this.constructor && (this.constructor.displayName || this.constructor.name) || "<component>";
|
849 | var rootNodeID = this._reactInternalInstance && this._reactInternalInstance._rootNodeID || this._reactInternalInstance && this._reactInternalInstance._debugID || this._reactInternalFiber && this._reactInternalFiber._debugID;
|
850 | |
851 |
|
852 |
|
853 |
|
854 |
|
855 | setHiddenProp(this, skipRenderKey, false);
|
856 | |
857 |
|
858 |
|
859 |
|
860 |
|
861 | setHiddenProp(this, isForcingUpdateKey, false);
|
862 |
|
863 | var baseRender = render.bind(this);
|
864 | var isRenderingPending = false;
|
865 | var reaction = new Reaction("".concat(initialName, "#").concat(rootNodeID, ".render()"), function () {
|
866 | if (!isRenderingPending) {
|
867 |
|
868 |
|
869 |
|
870 | isRenderingPending = true;
|
871 | if (typeof _this2.componentWillReact === "function") _this2.componentWillReact();
|
872 |
|
873 | if (_this2[mobxIsUnmounted] !== true) {
|
874 |
|
875 |
|
876 |
|
877 | var hasError = true;
|
878 |
|
879 | try {
|
880 | setHiddenProp(_this2, isForcingUpdateKey, true);
|
881 | if (!_this2[skipRenderKey]) Component.prototype.forceUpdate.call(_this2);
|
882 | hasError = false;
|
883 | } finally {
|
884 | setHiddenProp(_this2, isForcingUpdateKey, false);
|
885 | if (hasError) reaction.dispose();
|
886 | }
|
887 | }
|
888 | }
|
889 | });
|
890 | reaction.reactComponent = this;
|
891 | reactiveRender[mobxAdminProperty] = reaction;
|
892 | this.render = reactiveRender;
|
893 | return reactiveRender.call(this);
|
894 | }
|
895 |
|
896 |
|
897 |
|
898 |
|
899 |
|
900 | var reactiveMixin = {
|
901 | componentWillUnmount: function componentWillUnmount() {
|
902 | if (isUsingStaticRendering === true) return;
|
903 | this.render[mobxAdminProperty] && this.render[mobxAdminProperty].dispose();
|
904 | this[mobxIsUnmounted] = true;
|
905 |
|
906 | if (isDevtoolsEnabled) {
|
907 | var node = findDOMNode$1(this);
|
908 |
|
909 | if (node && componentByNodeRegistry) {
|
910 | componentByNodeRegistry.delete(node);
|
911 | }
|
912 |
|
913 | renderReporter.emit({
|
914 | event: "destroy",
|
915 | component: this,
|
916 | node: node
|
917 | });
|
918 | }
|
919 | },
|
920 | componentDidMount: function componentDidMount() {
|
921 | if (isDevtoolsEnabled) {
|
922 | reportRendering(this);
|
923 | }
|
924 | },
|
925 | componentDidUpdate: function componentDidUpdate() {
|
926 | if (isDevtoolsEnabled) {
|
927 | reportRendering(this);
|
928 | }
|
929 | },
|
930 | shouldComponentUpdate: function shouldComponentUpdate(nextProps, nextState) {
|
931 | if (isUsingStaticRendering) {
|
932 | console.warn("[mobx-react] It seems that a re-rendering of a React component is triggered while in static (server-side) mode. Please make sure components are rendered only once server-side.");
|
933 | }
|
934 |
|
935 |
|
936 | if (this.state !== nextState) {
|
937 | return true;
|
938 | }
|
939 |
|
940 |
|
941 |
|
942 |
|
943 |
|
944 | return !shallowEqual(this.props, nextProps);
|
945 | }
|
946 | };
|
947 |
|
948 | function makeObservableProp(target, propName) {
|
949 | var valueHolderKey = newSymbol("reactProp_".concat(propName, "_valueHolder"));
|
950 | var atomHolderKey = newSymbol("reactProp_".concat(propName, "_atomHolder"));
|
951 |
|
952 | function getAtom() {
|
953 | if (!this[atomHolderKey]) {
|
954 | setHiddenProp(this, atomHolderKey, createAtom("reactive " + propName));
|
955 | }
|
956 |
|
957 | return this[atomHolderKey];
|
958 | }
|
959 |
|
960 | Object.defineProperty(target, propName, {
|
961 | configurable: true,
|
962 | enumerable: true,
|
963 | get: function get() {
|
964 | getAtom.call(this).reportObserved();
|
965 | return this[valueHolderKey];
|
966 | },
|
967 | set: function set(v) {
|
968 | if (!this[isForcingUpdateKey] && !shallowEqual(this[valueHolderKey], v)) {
|
969 | setHiddenProp(this, valueHolderKey, v);
|
970 | setHiddenProp(this, skipRenderKey, true);
|
971 | getAtom.call(this).reportChanged();
|
972 | setHiddenProp(this, skipRenderKey, false);
|
973 | } else {
|
974 | setHiddenProp(this, valueHolderKey, v);
|
975 | }
|
976 | }
|
977 | });
|
978 | }
|
979 |
|
980 |
|
981 |
|
982 |
|
983 |
|
984 | function observer(arg1, arg2) {
|
985 | if (typeof arg1 === "string") {
|
986 | throw new Error("Store names should be provided as array");
|
987 | }
|
988 |
|
989 | if (Array.isArray(arg1)) {
|
990 |
|
991 |
|
992 | if (!warnedAboutObserverInjectDeprecation) {
|
993 | warnedAboutObserverInjectDeprecation = true;
|
994 | console.warn('Mobx observer: Using observer to inject stores is deprecated since 4.0. Use `@inject("store1", "store2") @observer ComponentClass` or `inject("store1", "store2")(observer(componentClass))` instead of `@observer(["store1", "store2"]) ComponentClass`');
|
995 | }
|
996 |
|
997 | if (!arg2) {
|
998 |
|
999 | return function (componentClass) {
|
1000 | return observer(arg1, componentClass);
|
1001 | };
|
1002 | } else {
|
1003 | return inject.apply(null, arg1)(observer(arg2));
|
1004 | }
|
1005 | }
|
1006 |
|
1007 | var componentClass = arg1;
|
1008 |
|
1009 | if (componentClass.isMobxInjector === true) {
|
1010 | console.warn("Mobx observer: You are trying to use 'observer' on a component that already has 'inject'. Please apply 'observer' before applying 'inject'");
|
1011 | }
|
1012 |
|
1013 | if (componentClass.__proto__ === PureComponent) {
|
1014 | console.warn("Mobx observer: You are using 'observer' on React.PureComponent. These two achieve two opposite goals and should not be used together");
|
1015 | }
|
1016 |
|
1017 |
|
1018 |
|
1019 |
|
1020 | if (componentClass["$$typeof"] === ReactIs.ForwardRef) {
|
1021 | var _baseRender = componentClass.render;
|
1022 | if (typeof _baseRender !== "function") throw new Error("render property of ForwardRef was not a function");
|
1023 | return _objectSpread({}, componentClass, {
|
1024 | render: function render() {
|
1025 | var _arguments = arguments;
|
1026 | return React__default.createElement(Observer, null, function () {
|
1027 | return _baseRender.apply(undefined, _arguments);
|
1028 | });
|
1029 | }
|
1030 | });
|
1031 | }
|
1032 |
|
1033 |
|
1034 |
|
1035 |
|
1036 | if (typeof componentClass === "function" && (!componentClass.prototype || !componentClass.prototype.render) && !componentClass.isReactClass && !Component.isPrototypeOf(componentClass)) {
|
1037 | var _class, _temp;
|
1038 |
|
1039 | var observerComponent = observer((_temp = _class =
|
1040 |
|
1041 | function (_Component) {
|
1042 | _inherits(_class, _Component);
|
1043 |
|
1044 | function _class() {
|
1045 | _classCallCheck(this, _class);
|
1046 |
|
1047 | return _possibleConstructorReturn(this, _getPrototypeOf(_class).apply(this, arguments));
|
1048 | }
|
1049 |
|
1050 | _createClass(_class, [{
|
1051 | key: "render",
|
1052 | value: function render() {
|
1053 | return componentClass.call(this, this.props, this.context);
|
1054 | }
|
1055 | }]);
|
1056 |
|
1057 | return _class;
|
1058 | }(Component), _class.displayName = componentClass.displayName || componentClass.name, _class.contextTypes = componentClass.contextTypes, _class.propTypes = componentClass.propTypes, _class.defaultProps = componentClass.defaultProps, _temp));
|
1059 | hoistNonReactStatics_cjs(observerComponent, componentClass);
|
1060 | return observerComponent;
|
1061 | }
|
1062 |
|
1063 | if (!componentClass) {
|
1064 | throw new Error("Please pass a valid component to 'observer'");
|
1065 | }
|
1066 |
|
1067 | var target = componentClass.prototype || componentClass;
|
1068 | mixinLifecycleEvents(target);
|
1069 | componentClass.isMobXReactObserver = true;
|
1070 | makeObservableProp(target, "props");
|
1071 | makeObservableProp(target, "state");
|
1072 | var baseRender = target.render;
|
1073 |
|
1074 | target.render = function () {
|
1075 | return makeComponentReactive.call(this, baseRender);
|
1076 | };
|
1077 |
|
1078 | return componentClass;
|
1079 | }
|
1080 |
|
1081 | function mixinLifecycleEvents(target) {
|
1082 | ["componentDidMount", "componentWillUnmount", "componentDidUpdate"].forEach(function (funcName) {
|
1083 | patch$1(target, funcName);
|
1084 | });
|
1085 |
|
1086 | if (!target.shouldComponentUpdate) {
|
1087 | target.shouldComponentUpdate = reactiveMixin.shouldComponentUpdate;
|
1088 | } else {
|
1089 | if (target.shouldComponentUpdate !== reactiveMixin.shouldComponentUpdate) {
|
1090 |
|
1091 | console.warn("Use `shouldComponentUpdate` in an `observer` based component breaks the behavior of `observer` and might lead to unexpected results. Manually implementing `sCU` should not be needed when using mobx-react.");
|
1092 | }
|
1093 | }
|
1094 | }
|
1095 |
|
1096 | var Observer = observer(function (_ref) {
|
1097 | var children = _ref.children,
|
1098 | observerInject = _ref.inject,
|
1099 | render = _ref.render;
|
1100 | var component = children || render;
|
1101 |
|
1102 | if (typeof component === "undefined") {
|
1103 | return null;
|
1104 | }
|
1105 |
|
1106 | if (!observerInject) {
|
1107 | return component();
|
1108 | }
|
1109 |
|
1110 |
|
1111 | console.warn("<Observer inject=.../> is no longer supported. Please use inject on the enclosing component instead");
|
1112 | var InjectComponent = inject(observerInject)(component);
|
1113 | return React__default.createElement(InjectComponent, null);
|
1114 | });
|
1115 | Observer.displayName = "Observer";
|
1116 |
|
1117 | var ObserverPropsCheck = function ObserverPropsCheck(props, key, componentName, location, propFullName) {
|
1118 | var extraKey = key === "children" ? "render" : "children";
|
1119 |
|
1120 | if (typeof props[key] === "function" && typeof props[extraKey] === "function") {
|
1121 | return new Error("Invalid prop,do not use children and render in the same time in`" + componentName);
|
1122 | }
|
1123 |
|
1124 | if (typeof props[key] === "function" || typeof props[extraKey] === "function") {
|
1125 | return;
|
1126 | }
|
1127 |
|
1128 | return new Error("Invalid prop `" + propFullName + "` of type `" + _typeof(props[key]) + "` supplied to" + " `" + componentName + "`, expected `function`.");
|
1129 | };
|
1130 |
|
1131 | Observer.propTypes = {
|
1132 | render: ObserverPropsCheck,
|
1133 | children: ObserverPropsCheck
|
1134 | };
|
1135 |
|
1136 |
|
1137 |
|
1138 |
|
1139 |
|
1140 |
|
1141 |
|
1142 |
|
1143 | function componentWillMount() {
|
1144 |
|
1145 | var state = this.constructor.getDerivedStateFromProps(this.props, this.state);
|
1146 | if (state !== null && state !== undefined) {
|
1147 | this.setState(state);
|
1148 | }
|
1149 | }
|
1150 |
|
1151 | function componentWillReceiveProps(nextProps) {
|
1152 |
|
1153 |
|
1154 | function updater(prevState) {
|
1155 | var state = this.constructor.getDerivedStateFromProps(nextProps, prevState);
|
1156 | return state !== null && state !== undefined ? state : null;
|
1157 | }
|
1158 |
|
1159 | this.setState(updater.bind(this));
|
1160 | }
|
1161 |
|
1162 | function componentWillUpdate(nextProps, nextState) {
|
1163 | try {
|
1164 | var prevProps = this.props;
|
1165 | var prevState = this.state;
|
1166 | this.props = nextProps;
|
1167 | this.state = nextState;
|
1168 | this.__reactInternalSnapshotFlag = true;
|
1169 | this.__reactInternalSnapshot = this.getSnapshotBeforeUpdate(
|
1170 | prevProps,
|
1171 | prevState
|
1172 | );
|
1173 | } finally {
|
1174 | this.props = prevProps;
|
1175 | this.state = prevState;
|
1176 | }
|
1177 | }
|
1178 |
|
1179 |
|
1180 |
|
1181 | componentWillMount.__suppressDeprecationWarning = true;
|
1182 | componentWillReceiveProps.__suppressDeprecationWarning = true;
|
1183 | componentWillUpdate.__suppressDeprecationWarning = true;
|
1184 |
|
1185 | function polyfill(Component$$1) {
|
1186 | var prototype = Component$$1.prototype;
|
1187 |
|
1188 | if (!prototype || !prototype.isReactComponent) {
|
1189 | throw new Error('Can only polyfill class components');
|
1190 | }
|
1191 |
|
1192 | if (
|
1193 | typeof Component$$1.getDerivedStateFromProps !== 'function' &&
|
1194 | typeof prototype.getSnapshotBeforeUpdate !== 'function'
|
1195 | ) {
|
1196 | return Component$$1;
|
1197 | }
|
1198 |
|
1199 |
|
1200 |
|
1201 |
|
1202 | var foundWillMountName = null;
|
1203 | var foundWillReceivePropsName = null;
|
1204 | var foundWillUpdateName = null;
|
1205 | if (typeof prototype.componentWillMount === 'function') {
|
1206 | foundWillMountName = 'componentWillMount';
|
1207 | } else if (typeof prototype.UNSAFE_componentWillMount === 'function') {
|
1208 | foundWillMountName = 'UNSAFE_componentWillMount';
|
1209 | }
|
1210 | if (typeof prototype.componentWillReceiveProps === 'function') {
|
1211 | foundWillReceivePropsName = 'componentWillReceiveProps';
|
1212 | } else if (typeof prototype.UNSAFE_componentWillReceiveProps === 'function') {
|
1213 | foundWillReceivePropsName = 'UNSAFE_componentWillReceiveProps';
|
1214 | }
|
1215 | if (typeof prototype.componentWillUpdate === 'function') {
|
1216 | foundWillUpdateName = 'componentWillUpdate';
|
1217 | } else if (typeof prototype.UNSAFE_componentWillUpdate === 'function') {
|
1218 | foundWillUpdateName = 'UNSAFE_componentWillUpdate';
|
1219 | }
|
1220 | if (
|
1221 | foundWillMountName !== null ||
|
1222 | foundWillReceivePropsName !== null ||
|
1223 | foundWillUpdateName !== null
|
1224 | ) {
|
1225 | var componentName = Component$$1.displayName || Component$$1.name;
|
1226 | var newApiName =
|
1227 | typeof Component$$1.getDerivedStateFromProps === 'function'
|
1228 | ? 'getDerivedStateFromProps()'
|
1229 | : 'getSnapshotBeforeUpdate()';
|
1230 |
|
1231 | throw Error(
|
1232 | 'Unsafe legacy lifecycles will not be called for components using new component APIs.\n\n' +
|
1233 | componentName +
|
1234 | ' uses ' +
|
1235 | newApiName +
|
1236 | ' but also contains the following legacy lifecycles:' +
|
1237 | (foundWillMountName !== null ? '\n ' + foundWillMountName : '') +
|
1238 | (foundWillReceivePropsName !== null
|
1239 | ? '\n ' + foundWillReceivePropsName
|
1240 | : '') +
|
1241 | (foundWillUpdateName !== null ? '\n ' + foundWillUpdateName : '') +
|
1242 | '\n\nThe above lifecycles should be removed. Learn more about this warning here:\n' +
|
1243 | 'https://fb.me/react-async-component-lifecycle-hooks'
|
1244 | );
|
1245 | }
|
1246 |
|
1247 |
|
1248 |
|
1249 |
|
1250 | if (typeof Component$$1.getDerivedStateFromProps === 'function') {
|
1251 | prototype.componentWillMount = componentWillMount;
|
1252 | prototype.componentWillReceiveProps = componentWillReceiveProps;
|
1253 | }
|
1254 |
|
1255 |
|
1256 |
|
1257 |
|
1258 | if (typeof prototype.getSnapshotBeforeUpdate === 'function') {
|
1259 | if (typeof prototype.componentDidUpdate !== 'function') {
|
1260 | throw new Error(
|
1261 | 'Cannot polyfill getSnapshotBeforeUpdate() for components that do not define componentDidUpdate() on the prototype'
|
1262 | );
|
1263 | }
|
1264 |
|
1265 | prototype.componentWillUpdate = componentWillUpdate;
|
1266 |
|
1267 | var componentDidUpdate = prototype.componentDidUpdate;
|
1268 |
|
1269 | prototype.componentDidUpdate = function componentDidUpdatePolyfill(
|
1270 | prevProps,
|
1271 | prevState,
|
1272 | maybeSnapshot
|
1273 | ) {
|
1274 |
|
1275 |
|
1276 |
|
1277 |
|
1278 |
|
1279 |
|
1280 |
|
1281 |
|
1282 | var snapshot = this.__reactInternalSnapshotFlag
|
1283 | ? this.__reactInternalSnapshot
|
1284 | : maybeSnapshot;
|
1285 |
|
1286 | componentDidUpdate.call(this, prevProps, prevState, snapshot);
|
1287 | };
|
1288 | }
|
1289 |
|
1290 | return Component$$1;
|
1291 | }
|
1292 |
|
1293 | var specialReactKeys = {
|
1294 | children: true,
|
1295 | key: true,
|
1296 | ref: true
|
1297 | };
|
1298 |
|
1299 | var Provider =
|
1300 |
|
1301 | function (_Component) {
|
1302 | _inherits(Provider, _Component);
|
1303 |
|
1304 | function Provider(props, context) {
|
1305 | var _this;
|
1306 |
|
1307 | _classCallCheck(this, Provider);
|
1308 |
|
1309 | _this = _possibleConstructorReturn(this, _getPrototypeOf(Provider).call(this, props, context));
|
1310 | _this.state = {};
|
1311 | copyStores(props, _this.state);
|
1312 | return _this;
|
1313 | }
|
1314 |
|
1315 | _createClass(Provider, [{
|
1316 | key: "render",
|
1317 | value: function render() {
|
1318 | return Children.only(this.props.children);
|
1319 | }
|
1320 | }, {
|
1321 | key: "getChildContext",
|
1322 | value: function getChildContext() {
|
1323 | var stores = {};
|
1324 |
|
1325 | copyStores(this.context.mobxStores, stores);
|
1326 |
|
1327 | copyStores(this.props, stores);
|
1328 | return {
|
1329 | mobxStores: stores
|
1330 | };
|
1331 | }
|
1332 | }], [{
|
1333 | key: "getDerivedStateFromProps",
|
1334 | value: function getDerivedStateFromProps(nextProps, prevState) {
|
1335 | if (!nextProps) return null;
|
1336 | if (!prevState) return nextProps;
|
1337 |
|
1338 | if (Object.keys(nextProps).filter(validStoreName).length !== Object.keys(prevState).filter(validStoreName).length) console.warn("MobX Provider: The set of provided stores has changed. Please avoid changing stores as the change might not propagate to all children");
|
1339 | if (!nextProps.suppressChangedStoreWarning) for (var key in nextProps) {
|
1340 | if (validStoreName(key) && prevState[key] !== nextProps[key]) console.warn("MobX Provider: Provided store '" + key + "' has changed. Please avoid replacing stores as the change might not propagate to all children");
|
1341 | }
|
1342 | return nextProps;
|
1343 | }
|
1344 | }]);
|
1345 |
|
1346 | return Provider;
|
1347 | }(Component);
|
1348 |
|
1349 | Provider.contextTypes = {
|
1350 | mobxStores: objectOrObservableObject
|
1351 | };
|
1352 | Provider.childContextTypes = {
|
1353 | mobxStores: objectOrObservableObject.isRequired
|
1354 | };
|
1355 |
|
1356 | function copyStores(from, to) {
|
1357 | if (!from) return;
|
1358 |
|
1359 | for (var key in from) {
|
1360 | if (validStoreName(key)) to[key] = from[key];
|
1361 | }
|
1362 | }
|
1363 |
|
1364 | function validStoreName(key) {
|
1365 | return !specialReactKeys[key] && key !== "suppressChangedStoreWarning";
|
1366 | }
|
1367 |
|
1368 |
|
1369 | polyfill(Provider);
|
1370 |
|
1371 | var storeKey = newSymbol("disposeOnUnmount");
|
1372 |
|
1373 | function runDisposersOnWillUnmount() {
|
1374 | var _this = this;
|
1375 |
|
1376 | if (!this[storeKey]) {
|
1377 |
|
1378 | return;
|
1379 | }
|
1380 |
|
1381 | this[storeKey].forEach(function (propKeyOrFunction) {
|
1382 | var prop = typeof propKeyOrFunction === "string" ? _this[propKeyOrFunction] : propKeyOrFunction;
|
1383 |
|
1384 | if (prop !== undefined && prop !== null) {
|
1385 | if (typeof prop !== "function") {
|
1386 | throw new Error("[mobx-react] disposeOnUnmount only works on functions such as disposers returned by reactions, autorun, etc.");
|
1387 | }
|
1388 |
|
1389 | prop();
|
1390 | }
|
1391 | });
|
1392 | this[storeKey] = [];
|
1393 | }
|
1394 |
|
1395 | function disposeOnUnmount(target, propertyKeyOrFunction) {
|
1396 | if (Array.isArray(propertyKeyOrFunction)) {
|
1397 | return propertyKeyOrFunction.map(function (fn) {
|
1398 | return disposeOnUnmount(target, fn);
|
1399 | });
|
1400 | }
|
1401 |
|
1402 | if (!target instanceof Component) {
|
1403 | throw new Error("[mobx-react] disposeOnUnmount only works on class based React components.");
|
1404 | }
|
1405 |
|
1406 | if (typeof propertyKeyOrFunction !== "string" && typeof propertyKeyOrFunction !== "function") {
|
1407 | throw new Error("[mobx-react] disposeOnUnmount only works if the parameter is either a property key or a function.");
|
1408 | }
|
1409 |
|
1410 |
|
1411 | var componentWasAlreadyModified = !!target[storeKey];
|
1412 | var store = target[storeKey] || (target[storeKey] = []);
|
1413 | store.push(propertyKeyOrFunction);
|
1414 |
|
1415 | if (!componentWasAlreadyModified) {
|
1416 | patch(target, "componentWillUnmount", runDisposersOnWillUnmount);
|
1417 | }
|
1418 |
|
1419 |
|
1420 | if (typeof propertyKeyOrFunction !== "string") {
|
1421 | return propertyKeyOrFunction;
|
1422 | }
|
1423 | }
|
1424 |
|
1425 | if (!Component) throw new Error("mobx-react requires React to be available");
|
1426 | if (!spy) throw new Error("mobx-react requires mobx to be available");
|
1427 | var onError = function onError(fn) {
|
1428 | return errorsReporter.on(fn);
|
1429 | };
|
1430 |
|
1431 | if ((typeof __MOBX_DEVTOOLS_GLOBAL_HOOK__ === "undefined" ? "undefined" : _typeof(__MOBX_DEVTOOLS_GLOBAL_HOOK__)) === "object") {
|
1432 | var mobx = {
|
1433 | spy: spy,
|
1434 | extras: {
|
1435 | getDebugName: getDebugName
|
1436 | }
|
1437 | };
|
1438 | var mobxReact = {
|
1439 | renderReporter: renderReporter,
|
1440 | componentByNodeRegistry: componentByNodeRegistry,
|
1441 | componentByNodeRegistery: componentByNodeRegistry,
|
1442 | trackComponents: trackComponents
|
1443 | };
|
1444 |
|
1445 | __MOBX_DEVTOOLS_GLOBAL_HOOK__.injectMobxReact(mobxReact, mobx);
|
1446 | }
|
1447 |
|
1448 | export { propTypes, propTypes as PropTypes, onError, observer, Observer, renderReporter, componentByNodeRegistry as componentByNodeRegistery, componentByNodeRegistry, trackComponents, useStaticRendering, Provider, inject, disposeOnUnmount };
|