UNPKG

29.2 kBJavaScriptView Raw
1(function (global, factory) {
2 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('mobx'), require('react'), require('react-dom'), require('mobx-react-lite')) :
3 typeof define === 'function' && define.amd ? define(['exports', 'mobx', 'react', 'react-dom', 'mobx-react-lite'], factory) :
4 (global = global || self, factory(global.mobxReact = {}, global.mobx, global.React, global.ReactDOM, global.mobxReactLite));
5}(this, (function (exports, mobx, React, reactDom, mobxReactLite) { 'use strict';
6
7 var React__default = 'default' in React ? React['default'] : React;
8
9 let symbolId = 0;
10
11 function createSymbol(name) {
12 if (typeof Symbol === "function") {
13 return Symbol(name);
14 }
15
16 const symbol = `__$mobx-react ${name} (${symbolId})`;
17 symbolId++;
18 return symbol;
19 }
20
21 const createdSymbols = {};
22 function newSymbol(name) {
23 if (!createdSymbols[name]) {
24 createdSymbols[name] = createSymbol(name);
25 }
26
27 return createdSymbols[name];
28 }
29 function shallowEqual(objA, objB) {
30 //From: https://github.com/facebook/fbjs/blob/c69904a511b900266935168223063dd8772dfc40/packages/fbjs/src/core/shallowEqual.js
31 if (is(objA, objB)) return true;
32
33 if (typeof objA !== "object" || objA === null || typeof objB !== "object" || objB === null) {
34 return false;
35 }
36
37 const keysA = Object.keys(objA);
38 const keysB = Object.keys(objB);
39 if (keysA.length !== keysB.length) return false;
40
41 for (let i = 0; i < keysA.length; i++) {
42 if (!Object.hasOwnProperty.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) {
43 return false;
44 }
45 }
46
47 return true;
48 }
49
50 function is(x, y) {
51 // From: https://github.com/facebook/fbjs/blob/c69904a511b900266935168223063dd8772dfc40/packages/fbjs/src/core/shallowEqual.js
52 if (x === y) {
53 return x !== 0 || 1 / x === 1 / y;
54 } else {
55 return x !== x && y !== y;
56 }
57 } // based on https://github.com/mridgway/hoist-non-react-statics/blob/master/src/index.js
58
59
60 const hoistBlackList = {
61 $$typeof: 1,
62 render: 1,
63 compare: 1,
64 type: 1,
65 childContextTypes: 1,
66 contextType: 1,
67 contextTypes: 1,
68 defaultProps: 1,
69 getDefaultProps: 1,
70 getDerivedStateFromError: 1,
71 getDerivedStateFromProps: 1,
72 mixins: 1,
73 propTypes: 1
74 };
75 function copyStaticProperties(base, target) {
76 const protoProps = Object.getOwnPropertyNames(Object.getPrototypeOf(base));
77 Object.getOwnPropertyNames(base).forEach(key => {
78 if (!hoistBlackList[key] && protoProps.indexOf(key) === -1) {
79 Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(base, key));
80 }
81 });
82 }
83 /**
84 * Helper to set `prop` to `this` as non-enumerable (hidden prop)
85 * @param target
86 * @param prop
87 * @param value
88 */
89
90 function setHiddenProp(target, prop, value) {
91 if (!Object.hasOwnProperty.call(target, prop)) {
92 Object.defineProperty(target, prop, {
93 enumerable: false,
94 configurable: true,
95 writable: true,
96 value
97 });
98 } else {
99 target[prop] = value;
100 }
101 }
102 /**
103 * Utilities for patching componentWillUnmount, to make sure @disposeOnUnmount works correctly icm with user defined hooks
104 * and the handler provided by mobx-react
105 */
106
107 const mobxMixins =
108 /*#__PURE__*/
109 newSymbol("patchMixins");
110 const mobxPatchedDefinition =
111 /*#__PURE__*/
112 newSymbol("patchedDefinition");
113
114 function getMixins(target, methodName) {
115 const mixins = target[mobxMixins] = target[mobxMixins] || {};
116 const methodMixins = mixins[methodName] = mixins[methodName] || {};
117 methodMixins.locks = methodMixins.locks || 0;
118 methodMixins.methods = methodMixins.methods || [];
119 return methodMixins;
120 }
121
122 function wrapper(realMethod, mixins, ...args) {
123 // locks are used to ensure that mixins are invoked only once per invocation, even on recursive calls
124 mixins.locks++;
125
126 try {
127 let retVal;
128
129 if (realMethod !== undefined && realMethod !== null) {
130 retVal = realMethod.apply(this, args);
131 }
132
133 return retVal;
134 } finally {
135 mixins.locks--;
136
137 if (mixins.locks === 0) {
138 mixins.methods.forEach(mx => {
139 mx.apply(this, args);
140 });
141 }
142 }
143 }
144
145 function wrapFunction(realMethod, mixins) {
146 const fn = function (...args) {
147 wrapper.call(this, realMethod, mixins, ...args);
148 };
149
150 return fn;
151 }
152
153 function patch(target, methodName, mixinMethod) {
154 const mixins = getMixins(target, methodName);
155
156 if (mixins.methods.indexOf(mixinMethod) < 0) {
157 mixins.methods.push(mixinMethod);
158 }
159
160 const oldDefinition = Object.getOwnPropertyDescriptor(target, methodName);
161
162 if (oldDefinition && oldDefinition[mobxPatchedDefinition]) {
163 // already patched definition, do not repatch
164 return;
165 }
166
167 const originalMethod = target[methodName];
168 const newDefinition = createDefinition(target, methodName, oldDefinition ? oldDefinition.enumerable : undefined, mixins, originalMethod);
169 Object.defineProperty(target, methodName, newDefinition);
170 }
171
172 function createDefinition(target, methodName, enumerable, mixins, originalMethod) {
173 let wrappedFunc = wrapFunction(originalMethod, mixins);
174 return {
175 [mobxPatchedDefinition]: true,
176 get: function () {
177 return wrappedFunc;
178 },
179 set: function (value) {
180 if (this === target) {
181 wrappedFunc = wrapFunction(value, mixins);
182 } else {
183 // when it is an instance of the prototype/a child prototype patch that particular case again separately
184 // since we need to store separate values depending on wether it is the actual instance, the prototype, etc
185 // e.g. the method for super might not be the same as the method for the prototype which might be not the same
186 // as the method for the instance
187 const newDefinition = createDefinition(this, methodName, enumerable, mixins, value);
188 Object.defineProperty(this, methodName, newDefinition);
189 }
190 },
191 configurable: true,
192 enumerable: enumerable
193 };
194 }
195
196 const mobxAdminProperty = mobx.$mobx || "$mobx";
197 const mobxIsUnmounted =
198 /*#__PURE__*/
199 newSymbol("isUnmounted");
200 const skipRenderKey =
201 /*#__PURE__*/
202 newSymbol("skipRender");
203 const isForcingUpdateKey =
204 /*#__PURE__*/
205 newSymbol("isForcingUpdate");
206 function makeClassComponentObserver(componentClass) {
207 const target = componentClass.prototype;
208 if (target.componentWillReact) throw new Error("The componentWillReact life-cycle event is no longer supported");
209
210 if (componentClass["__proto__"] !== React.PureComponent) {
211 if (!target.shouldComponentUpdate) target.shouldComponentUpdate = observerSCU;else if (target.shouldComponentUpdate !== observerSCU) // n.b. unequal check, instead of existence check, as @observer might be on superclass as well
212 throw new Error("It is not allowed to use shouldComponentUpdate in observer based components.");
213 } // this.props and this.state are made observable, just to make sure @computed fields that
214 // are defined inside the component, and which rely on state or props, re-compute if state or props change
215 // (otherwise the computed wouldn't update and become stale on props change, since props are not observable)
216 // However, this solution is not without it's own problems: https://github.com/mobxjs/mobx-react/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3Aobservable-props-or-not+
217
218
219 makeObservableProp(target, "props");
220 makeObservableProp(target, "state");
221 const baseRender = target.render;
222
223 target.render = function () {
224 return makeComponentReactive.call(this, baseRender);
225 };
226
227 patch(target, "componentWillUnmount", function () {
228 if (mobxReactLite.isUsingStaticRendering() === true) return;
229
230 if (this.render[mobxAdminProperty]) {
231 this.render[mobxAdminProperty].dispose();
232 } else {
233 const displayName = getDisplayName(this);
234 console.warn(`The render function for an observer component (${displayName}) was modified after MobX attached. This is not supported, since the new function can't be triggered by MobX.`);
235 }
236
237 this[mobxIsUnmounted] = true;
238 });
239 return componentClass;
240 } // Generates a friendly name for debugging
241
242 function getDisplayName(comp) {
243 return comp.displayName || comp.name || comp.constructor && (comp.constructor.displayName || comp.constructor.name) || "<component>";
244 }
245
246 function makeComponentReactive(render) {
247 if (mobxReactLite.isUsingStaticRendering() === true) return render.call(this);
248 /**
249 * If props are shallowly modified, react will render anyway,
250 * so atom.reportChanged() should not result in yet another re-render
251 */
252
253 setHiddenProp(this, skipRenderKey, false);
254 /**
255 * forceUpdate will re-assign this.props. We don't want that to cause a loop,
256 * so detect these changes
257 */
258
259 setHiddenProp(this, isForcingUpdateKey, false);
260 const initialName = getDisplayName(this);
261 const baseRender = render.bind(this);
262 let isRenderingPending = false;
263 const reaction = new mobx.Reaction(`${initialName}.render()`, () => {
264 if (!isRenderingPending) {
265 // N.B. Getting here *before mounting* means that a component constructor has side effects (see the relevant test in misc.js)
266 // This unidiomatic React usage but React will correctly warn about this so we continue as usual
267 // See #85 / Pull #44
268 isRenderingPending = true;
269
270 if (this[mobxIsUnmounted] !== true) {
271 let hasError = true;
272
273 try {
274 setHiddenProp(this, isForcingUpdateKey, true);
275 if (!this[skipRenderKey]) React.Component.prototype.forceUpdate.call(this);
276 hasError = false;
277 } finally {
278 setHiddenProp(this, isForcingUpdateKey, false);
279 if (hasError) reaction.dispose();
280 }
281 }
282 }
283 });
284 reaction["reactComponent"] = this;
285 reactiveRender[mobxAdminProperty] = reaction;
286 this.render = reactiveRender;
287
288 function reactiveRender() {
289 isRenderingPending = false;
290 let exception = undefined;
291 let rendering = undefined;
292 reaction.track(() => {
293 try {
294 rendering = mobx._allowStateChanges(false, baseRender);
295 } catch (e) {
296 exception = e;
297 }
298 });
299
300 if (exception) {
301 throw exception;
302 }
303
304 return rendering;
305 }
306
307 return reactiveRender.call(this);
308 }
309
310 function observerSCU(nextProps, nextState) {
311 if (mobxReactLite.isUsingStaticRendering()) {
312 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.");
313 } // update on any state changes (as is the default)
314
315
316 if (this.state !== nextState) {
317 return true;
318 } // update if props are shallowly not equal, inspired by PureRenderMixin
319 // we could return just 'false' here, and avoid the `skipRender` checks etc
320 // however, it is nicer if lifecycle events are triggered like usually,
321 // so we return true here if props are shallowly modified.
322
323
324 return !shallowEqual(this.props, nextProps);
325 }
326
327 function makeObservableProp(target, propName) {
328 const valueHolderKey = newSymbol(`reactProp_${propName}_valueHolder`);
329 const atomHolderKey = newSymbol(`reactProp_${propName}_atomHolder`);
330
331 function getAtom() {
332 if (!this[atomHolderKey]) {
333 setHiddenProp(this, atomHolderKey, mobx.createAtom("reactive " + propName));
334 }
335
336 return this[atomHolderKey];
337 }
338
339 Object.defineProperty(target, propName, {
340 configurable: true,
341 enumerable: true,
342 get: function () {
343 let prevReadState = false;
344
345 if (mobx._allowStateReadsStart && mobx._allowStateReadsEnd) {
346 prevReadState = mobx._allowStateReadsStart(true);
347 }
348
349 getAtom.call(this).reportObserved();
350
351 if (mobx._allowStateReadsStart && mobx._allowStateReadsEnd) {
352 mobx._allowStateReadsEnd(prevReadState);
353 }
354
355 return this[valueHolderKey];
356 },
357 set: function set(v) {
358 if (!this[isForcingUpdateKey] && !shallowEqual(this[valueHolderKey], v)) {
359 setHiddenProp(this, valueHolderKey, v);
360 setHiddenProp(this, skipRenderKey, true);
361 getAtom.call(this).reportChanged();
362 setHiddenProp(this, skipRenderKey, false);
363 } else {
364 setHiddenProp(this, valueHolderKey, v);
365 }
366 }
367 });
368 }
369
370 const hasSymbol = typeof Symbol === "function" && Symbol.for; // Using react-is had some issues (and operates on elements, not on types), see #608 / #609
371
372 const ReactForwardRefSymbol = hasSymbol ?
373 /*#__PURE__*/
374 Symbol.for("react.forward_ref") : typeof React.forwardRef === "function" &&
375 /*#__PURE__*/
376 React.forwardRef(props => null)["$$typeof"];
377 const ReactMemoSymbol = hasSymbol ?
378 /*#__PURE__*/
379 Symbol.for("react.memo") : typeof React.memo === "function" &&
380 /*#__PURE__*/
381 React.memo(props => null)["$$typeof"];
382 /**
383 * Observer function / decorator
384 */
385
386 function observer(component) {
387 if (component["isMobxInjector"] === true) {
388 console.warn("Mobx observer: You are trying to use 'observer' on a component that already has 'inject'. Please apply 'observer' before applying 'inject'");
389 }
390
391 if (ReactMemoSymbol && component["$$typeof"] === ReactMemoSymbol) {
392 throw new Error("Mobx observer: You are trying to use 'observer' on function component wrapped to either another observer or 'React.memo'. The observer already applies 'React.memo' for you.");
393 } // Unwrap forward refs into `<Observer>` component
394 // we need to unwrap the render, because it is the inner render that needs to be tracked,
395 // not the ForwardRef HoC
396
397
398 if (ReactForwardRefSymbol && component["$$typeof"] === ReactForwardRefSymbol) {
399 const baseRender = component["render"];
400 if (typeof baseRender !== "function") throw new Error("render property of ForwardRef was not a function");
401 return React.forwardRef(function ObserverForwardRef() {
402 return React.createElement(mobxReactLite.Observer, null, () => baseRender.apply(undefined, arguments));
403 });
404 } // Function component
405
406
407 if (typeof component === "function" && (!component.prototype || !component.prototype.render) && !component["isReactClass"] && !Object.prototype.isPrototypeOf.call(React.Component, component)) {
408 return mobxReactLite.observer(component);
409 }
410
411 return makeClassComponentObserver(component);
412 }
413
414 const MobXProviderContext =
415 /*#__PURE__*/
416 React__default.createContext({});
417 function Provider(props) {
418 const {
419 children,
420 ...stores
421 } = props;
422 const parentValue = React__default.useContext(MobXProviderContext);
423 const mutableProviderRef = React__default.useRef({ ...parentValue,
424 ...stores
425 });
426 const value = mutableProviderRef.current;
427
428 {
429 const newValue = { ...value,
430 ...stores
431 }; // spread in previous state for the context based stores
432
433 if (!shallowEqual(value, newValue)) {
434 throw new Error("MobX Provider: The set of provided stores has changed. See: https://github.com/mobxjs/mobx-react#the-set-of-provided-stores-has-changed-error.");
435 }
436 }
437
438 return React__default.createElement(MobXProviderContext.Provider, {
439 value: value
440 }, children);
441 }
442 Provider.displayName = "MobXProvider";
443
444 /**
445 * Store Injection
446 */
447
448 function createStoreInjector(grabStoresFn, component, injectNames, makeReactive) {
449 // Support forward refs
450 let Injector = React__default.forwardRef((props, ref) => {
451 const newProps = { ...props
452 };
453 const context = React__default.useContext(MobXProviderContext);
454 Object.assign(newProps, grabStoresFn(context || {}, newProps) || {});
455
456 if (ref) {
457 newProps.ref = ref;
458 }
459
460 return React__default.createElement(component, newProps);
461 });
462 if (makeReactive) Injector = observer(Injector);
463 Injector["isMobxInjector"] = true; // assigned late to suppress observer warning
464 // Static fields from component should be visible on the generated Injector
465
466 copyStaticProperties(component, Injector);
467 Injector["wrappedComponent"] = component;
468 Injector.displayName = getInjectName(component, injectNames);
469 return Injector;
470 }
471
472 function getInjectName(component, injectNames) {
473 let displayName;
474 const componentName = component.displayName || component.name || component.constructor && component.constructor.name || "Component";
475 if (injectNames) displayName = "inject-with-" + injectNames + "(" + componentName + ")";else displayName = "inject(" + componentName + ")";
476 return displayName;
477 }
478
479 function grabStoresByName(storeNames) {
480 return function (baseStores, nextProps) {
481 storeNames.forEach(function (storeName) {
482 if (storeName in nextProps // prefer props over stores
483 ) return;
484 if (!(storeName in baseStores)) throw new Error("MobX injector: Store '" + storeName + "' is not available! Make sure it is provided by some Provider");
485 nextProps[storeName] = baseStores[storeName];
486 });
487 return nextProps;
488 };
489 }
490 /**
491 * higher order component that injects stores to a child.
492 * takes either a varargs list of strings, which are stores read from the context,
493 * or a function that manually maps the available stores from the context to props:
494 * storesToProps(mobxStores, props, context) => newProps
495 */
496
497
498 function inject(
499 /* fn(stores, nextProps) or ...storeNames */
500 ...storeNames) {
501 if (typeof arguments[0] === "function") {
502 let grabStoresFn = arguments[0];
503 return componentClass => createStoreInjector(grabStoresFn, componentClass, grabStoresFn.name, true);
504 } else {
505 return componentClass => createStoreInjector(grabStoresByName(storeNames), componentClass, storeNames.join("-"), false);
506 }
507 }
508
509 const protoStoreKey =
510 /*#__PURE__*/
511 newSymbol("disposeOnUnmountProto");
512 const instStoreKey =
513 /*#__PURE__*/
514 newSymbol("disposeOnUnmountInst");
515
516 function runDisposersOnWillUnmount() {
517 [...(this[protoStoreKey] || []), ...(this[instStoreKey] || [])].forEach(propKeyOrFunction => {
518 const prop = typeof propKeyOrFunction === "string" ? this[propKeyOrFunction] : propKeyOrFunction;
519
520 if (prop !== undefined && prop !== null) {
521 if (Array.isArray(prop)) prop.map(f => f());else prop();
522 }
523 });
524 }
525
526 function disposeOnUnmount(target, propertyKeyOrFunction) {
527 if (Array.isArray(propertyKeyOrFunction)) {
528 return propertyKeyOrFunction.map(fn => disposeOnUnmount(target, fn));
529 }
530
531 const c = Object.getPrototypeOf(target).constructor || Object.getPrototypeOf(target.constructor);
532 const c2 = Object.getPrototypeOf(target.constructor);
533
534 if (!(c === React__default.Component || c === React__default.PureComponent || c2 === React__default.Component || c2 === React__default.PureComponent)) {
535 throw new Error("[mobx-react] disposeOnUnmount only supports direct subclasses of React.Component or React.PureComponent.");
536 }
537
538 if (typeof propertyKeyOrFunction !== "string" && typeof propertyKeyOrFunction !== "function" && !Array.isArray(propertyKeyOrFunction)) {
539 throw new Error("[mobx-react] disposeOnUnmount only works if the parameter is either a property key or a function.");
540 } // decorator's target is the prototype, so it doesn't have any instance properties like props
541
542
543 const isDecorator = typeof propertyKeyOrFunction === "string"; // add property key / function we want run (disposed) to the store
544
545 const componentWasAlreadyModified = !!target[protoStoreKey] || !!target[instStoreKey];
546 const store = isDecorator ? // decorators are added to the prototype store
547 target[protoStoreKey] || (target[protoStoreKey] = []) : // functions are added to the instance store
548 target[instStoreKey] || (target[instStoreKey] = []);
549 store.push(propertyKeyOrFunction); // tweak the component class componentWillUnmount if not done already
550
551 if (!componentWasAlreadyModified) {
552 patch(target, "componentWillUnmount", runDisposersOnWillUnmount);
553 } // return the disposer as is if invoked as a non decorator
554
555
556 if (typeof propertyKeyOrFunction !== "string") {
557 return propertyKeyOrFunction;
558 }
559 }
560
561 function createChainableTypeChecker(validator) {
562 function checkType(isRequired, props, propName, componentName, location, propFullName, ...rest) {
563 return mobx.untracked(() => {
564 componentName = componentName || "<<anonymous>>";
565 propFullName = propFullName || propName;
566
567 if (props[propName] == null) {
568 if (isRequired) {
569 const actual = props[propName] === null ? "null" : "undefined";
570 return new Error("The " + location + " `" + propFullName + "` is marked as required " + "in `" + componentName + "`, but its value is `" + actual + "`.");
571 }
572
573 return null;
574 } else {
575 // @ts-ignore rest arg is necessary for some React internals - fails tests otherwise
576 return validator(props, propName, componentName, location, propFullName, ...rest);
577 }
578 });
579 }
580
581 const chainedCheckType = checkType.bind(null, false); // Add isRequired to satisfy Requirable
582
583 chainedCheckType.isRequired = checkType.bind(null, true);
584 return chainedCheckType;
585 } // Copied from React.PropTypes
586
587
588 function isSymbol(propType, propValue) {
589 // Native Symbol.
590 if (propType === "symbol") {
591 return true;
592 } // 19.4.3.5 Symbol.prototype[@@toStringTag] === 'Symbol'
593
594
595 if (propValue["@@toStringTag"] === "Symbol") {
596 return true;
597 } // Fallback for non-spec compliant Symbols which are polyfilled.
598
599
600 if (typeof Symbol === "function" && propValue instanceof Symbol) {
601 return true;
602 }
603
604 return false;
605 } // Copied from React.PropTypes
606
607
608 function getPropType(propValue) {
609 const propType = typeof propValue;
610
611 if (Array.isArray(propValue)) {
612 return "array";
613 }
614
615 if (propValue instanceof RegExp) {
616 // Old webkits (at least until Android 4.0) return 'function' rather than
617 // 'object' for typeof a RegExp. We'll normalize this here so that /bla/
618 // passes PropTypes.object.
619 return "object";
620 }
621
622 if (isSymbol(propType, propValue)) {
623 return "symbol";
624 }
625
626 return propType;
627 } // This handles more types than `getPropType`. Only used for error messages.
628 // Copied from React.PropTypes
629
630
631 function getPreciseType(propValue) {
632 const propType = getPropType(propValue);
633
634 if (propType === "object") {
635 if (propValue instanceof Date) {
636 return "date";
637 } else if (propValue instanceof RegExp) {
638 return "regexp";
639 }
640 }
641
642 return propType;
643 }
644
645 function createObservableTypeCheckerCreator(allowNativeType, mobxType) {
646 return createChainableTypeChecker((props, propName, componentName, location, propFullName) => {
647 return mobx.untracked(() => {
648 if (allowNativeType) {
649 if (getPropType(props[propName]) === mobxType.toLowerCase()) return null;
650 }
651
652 let mobxChecker;
653
654 switch (mobxType) {
655 case "Array":
656 mobxChecker = mobx.isObservableArray;
657 break;
658
659 case "Object":
660 mobxChecker = mobx.isObservableObject;
661 break;
662
663 case "Map":
664 mobxChecker = mobx.isObservableMap;
665 break;
666
667 default:
668 throw new Error(`Unexpected mobxType: ${mobxType}`);
669 }
670
671 const propValue = props[propName];
672
673 if (!mobxChecker(propValue)) {
674 const preciseType = getPreciseType(propValue);
675 const nativeTypeExpectationMessage = allowNativeType ? " or javascript `" + mobxType.toLowerCase() + "`" : "";
676 return new Error("Invalid prop `" + propFullName + "` of type `" + preciseType + "` supplied to" + " `" + componentName + "`, expected `mobx.Observable" + mobxType + "`" + nativeTypeExpectationMessage + ".");
677 }
678
679 return null;
680 });
681 });
682 }
683
684 function createObservableArrayOfTypeChecker(allowNativeType, typeChecker) {
685 return createChainableTypeChecker((props, propName, componentName, location, propFullName, ...rest) => {
686 return mobx.untracked(() => {
687 if (typeof typeChecker !== "function") {
688 return new Error("Property `" + propFullName + "` of component `" + componentName + "` has " + "invalid PropType notation.");
689 } else {
690 let error = createObservableTypeCheckerCreator(allowNativeType, "Array")(props, propName, componentName, location, propFullName);
691 if (error instanceof Error) return error;
692 const propValue = props[propName];
693
694 for (let i = 0; i < propValue.length; i++) {
695 error = typeChecker(propValue, i, componentName, location, propFullName + "[" + i + "]", ...rest);
696 if (error instanceof Error) return error;
697 }
698
699 return null;
700 }
701 });
702 });
703 }
704
705 const observableArray =
706 /*#__PURE__*/
707 createObservableTypeCheckerCreator(false, "Array");
708 const observableArrayOf =
709 /*#__PURE__*/
710 createObservableArrayOfTypeChecker.bind(null, false);
711 const observableMap =
712 /*#__PURE__*/
713 createObservableTypeCheckerCreator(false, "Map");
714 const observableObject =
715 /*#__PURE__*/
716 createObservableTypeCheckerCreator(false, "Object");
717 const arrayOrObservableArray =
718 /*#__PURE__*/
719 createObservableTypeCheckerCreator(true, "Array");
720 const arrayOrObservableArrayOf =
721 /*#__PURE__*/
722 createObservableArrayOfTypeChecker.bind(null, true);
723 const objectOrObservableObject =
724 /*#__PURE__*/
725 createObservableTypeCheckerCreator(true, "Object");
726 const PropTypes = {
727 observableArray,
728 observableArrayOf,
729 observableMap,
730 observableObject,
731 arrayOrObservableArray,
732 arrayOrObservableArrayOf,
733 objectOrObservableObject
734 };
735
736 if (!React.Component) throw new Error("mobx-react requires React to be available");
737 if (!mobx.observable) throw new Error("mobx-react requires mobx to be available");
738 if (typeof reactDom.unstable_batchedUpdates === "function") mobx.configure({
739 reactionScheduler: reactDom.unstable_batchedUpdates
740 });
741
742 Object.defineProperty(exports, 'Observer', {
743 enumerable: true,
744 get: function () {
745 return mobxReactLite.Observer;
746 }
747 });
748 Object.defineProperty(exports, 'isUsingStaticRendering', {
749 enumerable: true,
750 get: function () {
751 return mobxReactLite.isUsingStaticRendering;
752 }
753 });
754 Object.defineProperty(exports, 'useAsObservableSource', {
755 enumerable: true,
756 get: function () {
757 return mobxReactLite.useAsObservableSource;
758 }
759 });
760 Object.defineProperty(exports, 'useLocalStore', {
761 enumerable: true,
762 get: function () {
763 return mobxReactLite.useLocalStore;
764 }
765 });
766 Object.defineProperty(exports, 'useObserver', {
767 enumerable: true,
768 get: function () {
769 return mobxReactLite.useObserver;
770 }
771 });
772 Object.defineProperty(exports, 'useStaticRendering', {
773 enumerable: true,
774 get: function () {
775 return mobxReactLite.useStaticRendering;
776 }
777 });
778 exports.MobXProviderContext = MobXProviderContext;
779 exports.PropTypes = PropTypes;
780 exports.Provider = Provider;
781 exports.disposeOnUnmount = disposeOnUnmount;
782 exports.inject = inject;
783 exports.observer = observer;
784
785 Object.defineProperty(exports, '__esModule', { value: true });
786
787})));
788//# sourceMappingURL=mobxreact.umd.development.js.map