UNPKG

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