UNPKG

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