mobx 4.15.3 → 4.15.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -97,6 +97,8 @@ function invariant(check, message) {
97
97
  */
98
98
  var deprecatedMessages = [];
99
99
  function deprecated(msg, thing) {
100
+ if (process.env.NODE_ENV === "production")
101
+ return false;
100
102
  if (thing) {
101
103
  return deprecated("'" + msg + "', use '" + thing + "' instead.");
102
104
  }
@@ -176,7 +178,7 @@ function isPropertyConfigurable(object, prop) {
176
178
  return !descriptor || (descriptor.configurable !== false && descriptor.writable !== false);
177
179
  }
178
180
  function assertPropertyConfigurable(object, prop) {
179
- if (!isPropertyConfigurable(object, prop))
181
+ if (process.env.NODE_ENV !== "production" && !isPropertyConfigurable(object, prop))
180
182
  fail("Cannot make property '" + prop + "' observable, it is not configurable and writable in the target object");
181
183
  }
182
184
  function createInstanceofPredicate(name, clazz) {
@@ -357,7 +359,7 @@ function createPropDecorator(propertyInitiallyEnumerable, propertyCreator) {
357
359
  propertyCreator(target, prop, descriptor, target, decoratorArguments);
358
360
  return null;
359
361
  }
360
- if (!quacksLikeADecorator(arguments))
362
+ if (process.env.NODE_ENV !== "production" && !quacksLikeADecorator(arguments))
361
363
  fail("This function is a decorator, but it wasn't invoked like a decorator");
362
364
  if (!Object.prototype.hasOwnProperty.call(target, "__mobxDecorators")) {
363
365
  var inheritedDecorators = target.__mobxDecorators;
@@ -417,14 +419,15 @@ function shallowEnhancer(v, _, name) {
417
419
  return observable.map(v, { name: name, deep: false });
418
420
  if (isES6Set(v))
419
421
  return observable.set(v, { name: name, deep: false });
420
- return fail("The shallow modifier / decorator can only used in combination with arrays, objects, maps and sets");
422
+ return fail(process.env.NODE_ENV !== "production" &&
423
+ "The shallow modifier / decorator can only used in combination with arrays, objects, maps and sets");
421
424
  }
422
425
  function referenceEnhancer(newValue) {
423
426
  // never turn into an observable
424
427
  return newValue;
425
428
  }
426
429
  function refStructEnhancer(v, oldValue, name) {
427
- if (isObservable(v))
430
+ if (process.env.NODE_ENV !== "production" && isObservable(v))
428
431
  throw "observable.struct should not be used with observable values";
429
432
  if (deepEqual(v, oldValue))
430
433
  return oldValue;
@@ -434,7 +437,7 @@ function refStructEnhancer(v, oldValue, name) {
434
437
  function createDecoratorForEnhancer(enhancer) {
435
438
  invariant(enhancer);
436
439
  var decorator = createPropDecorator(true, function (target, propertyName, descriptor, _decoratorTarget, decoratorArgs) {
437
- {
440
+ if (process.env.NODE_ENV !== "production") {
438
441
  invariant(!descriptor || !descriptor.get, "@observable cannot be used on getter (property \"" + propertyName + "\"), use @computed instead.");
439
442
  }
440
443
  var initialValue = descriptor
@@ -446,7 +449,7 @@ function createDecoratorForEnhancer(enhancer) {
446
449
  });
447
450
  var res =
448
451
  // Extra process checks, as this happens during module initialization
449
- typeof process !== "undefined" && process.env && "development" !== "production"
452
+ typeof process !== "undefined" && process.env && process.env.NODE_ENV !== "production"
450
453
  ? function observableDecorator() {
451
454
  // This wrapper function is just to detect illegal decorator invocations, deprecate in a next version
452
455
  // and simply return the created prop decorator
@@ -482,7 +485,7 @@ function asCreateObservableOptions(thing) {
482
485
  return defaultCreateObservableOptions;
483
486
  if (typeof thing === "string")
484
487
  return { name: thing, deep: true };
485
- {
488
+ if (process.env.NODE_ENV !== "production") {
486
489
  if (typeof thing !== "object")
487
490
  return fail("expected options object");
488
491
  Object.keys(thing).forEach(assertValidOption);
@@ -526,7 +529,8 @@ function createObservable(v, arg2, arg3) {
526
529
  if (res !== v)
527
530
  return res;
528
531
  // otherwise, just box it
529
- fail("The provided value could not be converted into an observable. If you want just create an observable reference to the object use 'observable.box(value)'");
532
+ fail(process.env.NODE_ENV !== "production" &&
533
+ "The provided value could not be converted into an observable. If you want just create an observable reference to the object use 'observable.box(value)'");
530
534
  }
531
535
  var observableFactories = {
532
536
  box: function (value, options) {
@@ -593,7 +597,7 @@ var observable = createObservable;
593
597
  Object.keys(observableFactories).forEach(function (name) { return (observable[name] = observableFactories[name]); });
594
598
  function incorrectlyUsedAsDecorator(methodName) {
595
599
  fail(
596
- // "development" !== "production" &&
600
+ // process.env.NODE_ENV !== "production" &&
597
601
  "Expected one or two arguments to observable." + methodName + ". Did you accidentally try to use observable." + methodName + " as decorator?");
598
602
  }
599
603
 
@@ -620,7 +624,7 @@ var computed = function computed(arg1, arg2, arg3) {
620
624
  return computedDecorator.apply(null, arguments);
621
625
  }
622
626
  // computed(expr, options?)
623
- {
627
+ if (process.env.NODE_ENV !== "production") {
624
628
  invariant(typeof arg1 === "function", "First argument to `computed` should be an expression.");
625
629
  invariant(arguments.length < 3, "Computed takes one or two arguments if used as function");
626
630
  }
@@ -728,7 +732,7 @@ function shouldCompute(derivation) {
728
732
  // function invariantShouldCompute(derivation: IDerivation) {
729
733
  // const newDepState = (derivation as any).dependenciesState
730
734
  // if (
731
- // "development" === "production" &&
735
+ // process.env.NODE_ENV === "production" &&
732
736
  // (newDepState === IDerivationState.POSSIBLY_STALE ||
733
737
  // newDepState === IDerivationState.NOT_TRACKING)
734
738
  // )
@@ -741,16 +745,19 @@ function checkIfStateModificationsAreAllowed(atom) {
741
745
  var hasObservers = atom.observers.length > 0;
742
746
  // Should never be possible to change an observed observable from inside computed, see #798
743
747
  if (globalState.computationDepth > 0 && hasObservers)
744
- fail("Computed values are not allowed to cause side effects by changing observables that are already being observed. Tried to modify: " + atom.name);
748
+ fail(process.env.NODE_ENV !== "production" &&
749
+ "Computed values are not allowed to cause side effects by changing observables that are already being observed. Tried to modify: " + atom.name);
745
750
  // Should not be possible to change observed state outside strict mode, except during initialization, see #563
746
751
  if (!globalState.allowStateChanges && (hasObservers || globalState.enforceActions === "strict"))
747
- fail((globalState.enforceActions
752
+ fail(process.env.NODE_ENV !== "production" &&
753
+ (globalState.enforceActions
748
754
  ? "Since strict-mode is enabled, changing observed observable values outside actions is not allowed. Please wrap the code in an `action` if this change is intended. Tried to modify: "
749
755
  : "Side effects like changing state are not allowed at this point. Are you trying to modify state from, for example, the render function of a React component? Tried to modify: ") +
750
756
  atom.name);
751
757
  }
752
758
  function checkIfStateReadsAreAllowed(observable) {
753
- if (!globalState.allowStateReads &&
759
+ if (process.env.NODE_ENV !== "production" &&
760
+ !globalState.allowStateReads &&
754
761
  globalState.observableRequiresReaction) {
755
762
  console.warn("[mobx] Observable " + observable.name + " being read outside a reactive context");
756
763
  }
@@ -791,6 +798,8 @@ function trackDerivedFunction(derivation, f, context) {
791
798
  return result;
792
799
  }
793
800
  function warnAboutDerivationWithoutDependencies(derivation) {
801
+ if (process.env.NODE_ENV === "production")
802
+ return;
794
803
  if (globalState.reactionRequiresObservable || derivation.requiresObservable) {
795
804
  console.warn("[mobx] Derivation " + derivation.name + " is created/updated without reading any observable value");
796
805
  }
@@ -905,7 +914,7 @@ var nextActionId = 1;
905
914
  var functionNameDescriptor = Object.getOwnPropertyDescriptor(function () { }, "name");
906
915
  var isFunctionNameConfigurable = functionNameDescriptor && functionNameDescriptor.configurable;
907
916
  function createAction(actionName, fn) {
908
- {
917
+ if (process.env.NODE_ENV !== "production") {
909
918
  invariant(typeof fn === "function", "`action` can only be invoked on functions");
910
919
  if (typeof actionName !== "string" || !actionName)
911
920
  fail("actions should have valid names, got: '" + actionName + "'");
@@ -913,7 +922,7 @@ function createAction(actionName, fn) {
913
922
  var res = function () {
914
923
  return executeAction(actionName, fn, this, arguments);
915
924
  };
916
- {
925
+ if (process.env.NODE_ENV !== "production") {
917
926
  if (isFunctionNameConfigurable) {
918
927
  Object.defineProperty(res, "name", { value: actionName });
919
928
  }
@@ -1230,7 +1239,8 @@ var ComputedValue = /** @class */ (function () {
1230
1239
  }
1231
1240
  }
1232
1241
  else
1233
- invariant(false, "[ComputedValue '" + this.name + "'] It is not possible to assign a new value to a computed value.");
1242
+ invariant(false, process.env.NODE_ENV !== "production" &&
1243
+ "[ComputedValue '" + this.name + "'] It is not possible to assign a new value to a computed value.");
1234
1244
  };
1235
1245
  ComputedValue.prototype.trackAndCompute = function () {
1236
1246
  if (isSpyEnabled()) {
@@ -1304,6 +1314,8 @@ var ComputedValue = /** @class */ (function () {
1304
1314
  });
1305
1315
  };
1306
1316
  ComputedValue.prototype.warnAboutUntrackedRead = function () {
1317
+ if (process.env.NODE_ENV === "production")
1318
+ return;
1307
1319
  if (this.requiresReaction === true) {
1308
1320
  fail("[mobx] Computed value " + this.name + " is read outside a reactive context");
1309
1321
  }
@@ -1945,12 +1957,12 @@ function spy(listener) {
1945
1957
  }
1946
1958
 
1947
1959
  function dontReassignFields() {
1948
- fail("@action fields are not reassignable");
1960
+ fail(process.env.NODE_ENV !== "production" && "@action fields are not reassignable");
1949
1961
  }
1950
1962
  function namedActionDecorator(name) {
1951
1963
  return function (target, prop, descriptor) {
1952
1964
  if (descriptor) {
1953
- if (descriptor.get !== undefined) {
1965
+ if (process.env.NODE_ENV !== "production" && descriptor.get !== undefined) {
1954
1966
  return fail("@action cannot be used with getters");
1955
1967
  }
1956
1968
  // babel / typescript
@@ -2051,7 +2063,7 @@ function runInAction(arg1, arg2) {
2051
2063
  // TODO: deprecate?
2052
2064
  var actionName = typeof arg1 === "string" ? arg1 : arg1.name || "<unnamed action>";
2053
2065
  var fn = typeof arg1 === "function" ? arg1 : arg2;
2054
- {
2066
+ if (process.env.NODE_ENV !== "production") {
2055
2067
  invariant(typeof fn === "function" && fn.length === 0, "`runInAction` expects a function without arguments");
2056
2068
  if (typeof actionName !== "string" || !actionName)
2057
2069
  fail("actions should have valid names, got: '" + actionName + "'");
@@ -2073,7 +2085,7 @@ function defineBoundAction(target, propertyName, fn) {
2073
2085
  */
2074
2086
  function autorun(view, opts) {
2075
2087
  if (opts === void 0) { opts = EMPTY_OBJECT; }
2076
- {
2088
+ if (process.env.NODE_ENV !== "production") {
2077
2089
  invariant(typeof view === "function", "Autorun expects a function as first argument");
2078
2090
  invariant(isAction(view) === false, "Autorun does not accept actions since actions are untrackable");
2079
2091
  }
@@ -2121,7 +2133,7 @@ function reaction(expression, effect, opts) {
2121
2133
  opts = { fireImmediately: opts };
2122
2134
  deprecated("Using fireImmediately as argument is deprecated. Use '{ fireImmediately: true }' instead");
2123
2135
  }
2124
- {
2136
+ if (process.env.NODE_ENV !== "production") {
2125
2137
  invariant(typeof expression === "function", "First argument to reaction should be a function");
2126
2138
  invariant(typeof opts === "object", "Third argument of reactions should be an object");
2127
2139
  }
@@ -2186,7 +2198,7 @@ function interceptHook(hook, thing, arg2, arg3) {
2186
2198
  var cb = typeof arg3 === "function" ? arg3 : arg2;
2187
2199
  var orig = atom[hook];
2188
2200
  if (typeof orig !== "function")
2189
- return fail("Not an atom that can be (un)observed");
2201
+ return fail(process.env.NODE_ENV !== "production" && "Not an atom that can be (un)observed");
2190
2202
  atom[hook] = function () {
2191
2203
  orig.call(this);
2192
2204
  cb.call(this);
@@ -2251,7 +2263,7 @@ function configure(options) {
2251
2263
  }
2252
2264
 
2253
2265
  function decorate(thing, decorators) {
2254
- if (!isPlainObject(decorators))
2266
+ if (process.env.NODE_ENV !== "production" && !isPlainObject(decorators))
2255
2267
  fail("Decorators should be a key value map");
2256
2268
  var target = typeof thing === "function" ? thing.prototype : thing;
2257
2269
  var _loop_1 = function (prop) {
@@ -2260,7 +2272,7 @@ function decorate(thing, decorators) {
2260
2272
  propertyDecorators = [propertyDecorators];
2261
2273
  }
2262
2274
  // prettier-ignore
2263
- if (!propertyDecorators.every(function (decorator) { return typeof decorator === "function"; }))
2275
+ if (process.env.NODE_ENV !== "production" && !propertyDecorators.every(function (decorator) { return typeof decorator === "function"; }))
2264
2276
  fail("Decorate: expected a decorator function or array of decorator functions for '" + prop + "'");
2265
2277
  var descriptor = Object.getOwnPropertyDescriptor(target, prop);
2266
2278
  var newDescriptor = propertyDecorators.reduce(function (accDescriptor, decorator) { return decorator(target, prop, accDescriptor); }, descriptor);
@@ -2278,7 +2290,7 @@ function extendShallowObservable(target, properties, decorators) {
2278
2290
  return extendObservable(target, properties, decorators, shallowCreateObservableOptions);
2279
2291
  }
2280
2292
  function extendObservable(target, properties, decorators, options) {
2281
- {
2293
+ if (process.env.NODE_ENV !== "production") {
2282
2294
  invariant(arguments.length >= 2 && arguments.length <= 4, "'extendObservable' expected 2-4 arguments");
2283
2295
  invariant(typeof target === "object", "'extendObservable' expects an object as first argument");
2284
2296
  invariant(!isObservableMap(target), "'extendObservable' should not be used on maps, use map.merge instead");
@@ -2296,7 +2308,7 @@ function extendObservable(target, properties, decorators, options) {
2296
2308
  try {
2297
2309
  for (var key in properties) {
2298
2310
  var descriptor = Object.getOwnPropertyDescriptor(properties, key);
2299
- {
2311
+ if (process.env.NODE_ENV !== "production") {
2300
2312
  if (isComputed(descriptor.value))
2301
2313
  fail("Passing a 'computed' as initial property value is no longer supported by extendObservable. Use a getter or decorator instead");
2302
2314
  }
@@ -2305,7 +2317,7 @@ function extendObservable(target, properties, decorators, options) {
2305
2317
  : descriptor.get
2306
2318
  ? computedDecorator
2307
2319
  : defaultDecorator;
2308
- if (typeof decorator !== "function")
2320
+ if (process.env.NODE_ENV !== "production" && typeof decorator !== "function")
2309
2321
  return fail("Not a valid decorator for '" + key + "', got: " + decorator);
2310
2322
  var resultDescriptor = decorator(target, key, descriptor, true);
2311
2323
  if (resultDescriptor // otherwise, assume already applied, due to `applyToInstance`
@@ -2352,7 +2364,7 @@ function isFlowCancellationError(error) {
2352
2364
  }
2353
2365
  function flow(generator) {
2354
2366
  if (arguments.length !== 1)
2355
- fail("Flow expects one 1 argument and cannot be used as decorator");
2367
+ fail(!!process.env.NODE_ENV && "Flow expects one 1 argument and cannot be used as decorator");
2356
2368
  var name = generator.name || "<unnamed flow>";
2357
2369
  // Implementation based on https://github.com/tj/co/blob/master/index.js
2358
2370
  return function () {
@@ -2432,14 +2444,16 @@ function interceptReads(thing, propOrHandler, handler) {
2432
2444
  }
2433
2445
  else if (isObservableObject(thing)) {
2434
2446
  if (typeof propOrHandler !== "string")
2435
- return fail("InterceptReads can only be used with a specific property, not with an object in general");
2447
+ return fail(process.env.NODE_ENV !== "production" &&
2448
+ "InterceptReads can only be used with a specific property, not with an object in general");
2436
2449
  target = getAdministration(thing, propOrHandler);
2437
2450
  }
2438
2451
  else {
2439
- return fail("Expected observable map, object or array as first array");
2452
+ return fail(process.env.NODE_ENV !== "production" &&
2453
+ "Expected observable map, object or array as first array");
2440
2454
  }
2441
2455
  if (target.dehancer !== undefined)
2442
- return fail("An intercept reader was already established");
2456
+ return fail(process.env.NODE_ENV !== "production" && "An intercept reader was already established");
2443
2457
  target.dehancer = typeof propOrHandler === "function" ? propOrHandler : handler;
2444
2458
  return function () {
2445
2459
  target.dehancer = undefined;
@@ -2474,12 +2488,14 @@ function _isComputed(value, property) {
2474
2488
  }
2475
2489
  function isComputed(value) {
2476
2490
  if (arguments.length > 1)
2477
- return fail("isComputed expects only 1 argument. Use isObservableProp to inspect the observability of a property");
2491
+ return fail(process.env.NODE_ENV !== "production" &&
2492
+ "isComputed expects only 1 argument. Use isObservableProp to inspect the observability of a property");
2478
2493
  return _isComputed(value);
2479
2494
  }
2480
2495
  function isComputedProp(value, propName) {
2481
2496
  if (typeof propName !== "string")
2482
- return fail("isComputed expected a property name as second argument");
2497
+ return fail(process.env.NODE_ENV !== "production" &&
2498
+ "isComputed expected a property name as second argument");
2483
2499
  return _isComputed(value, propName);
2484
2500
  }
2485
2501
 
@@ -2487,7 +2503,8 @@ function _isObservable(value, property) {
2487
2503
  if (value === null || value === undefined)
2488
2504
  return false;
2489
2505
  if (property !== undefined) {
2490
- if (isObservableMap(value) || isObservableArray(value))
2506
+ if (process.env.NODE_ENV !== "production" &&
2507
+ (isObservableMap(value) || isObservableArray(value)))
2491
2508
  return fail("isObservable(object, propertyName) is not supported for arrays and maps. Use map.has or array.length instead.");
2492
2509
  if (isObservableObject(value)) {
2493
2510
  var o = value.$mobx;
@@ -2504,12 +2521,13 @@ function _isObservable(value, property) {
2504
2521
  }
2505
2522
  function isObservable(value) {
2506
2523
  if (arguments.length !== 1)
2507
- fail("isObservable expects only 1 argument. Use isObservableProp to inspect the observability of a property");
2524
+ fail(process.env.NODE_ENV !== "production" &&
2525
+ "isObservable expects only 1 argument. Use isObservableProp to inspect the observability of a property");
2508
2526
  return _isObservable(value);
2509
2527
  }
2510
2528
  function isObservableProp(value, propName) {
2511
2529
  if (typeof propName !== "string")
2512
- return fail("expected a property name as second argument");
2530
+ return fail(process.env.NODE_ENV !== "production" && "expected a property name as second argument");
2513
2531
  return _isObservable(value, propName);
2514
2532
  }
2515
2533
 
@@ -2526,7 +2544,8 @@ function keys(obj) {
2526
2544
  if (isObservableArray(obj)) {
2527
2545
  return obj.map(function (_, index) { return index; });
2528
2546
  }
2529
- return fail("'keys()' can only be used on observable objects, arrays, sets and maps");
2547
+ return fail(process.env.NODE_ENV !== "production" &&
2548
+ "'keys()' can only be used on observable objects, arrays, sets and maps");
2530
2549
  }
2531
2550
  function values(obj) {
2532
2551
  if (isObservableObject(obj)) {
@@ -2541,7 +2560,8 @@ function values(obj) {
2541
2560
  if (isObservableArray(obj)) {
2542
2561
  return obj.slice();
2543
2562
  }
2544
- return fail("'values()' can only be used on observable objects, arrays, sets and maps");
2563
+ return fail(process.env.NODE_ENV !== "production" &&
2564
+ "'values()' can only be used on observable objects, arrays, sets and maps");
2545
2565
  }
2546
2566
  function entries(obj) {
2547
2567
  if (isObservableObject(obj)) {
@@ -2556,7 +2576,8 @@ function entries(obj) {
2556
2576
  if (isObservableArray(obj)) {
2557
2577
  return obj.map(function (key, index) { return [index, key]; });
2558
2578
  }
2559
- return fail("'entries()' can only be used on observable objects, arrays and maps");
2579
+ return fail(process.env.NODE_ENV !== "production" &&
2580
+ "'entries()' can only be used on observable objects, arrays and maps");
2560
2581
  }
2561
2582
  function set(obj, key, value) {
2562
2583
  if (arguments.length === 2 && !isObservableSet(obj)) {
@@ -2598,7 +2619,8 @@ function set(obj, key, value) {
2598
2619
  endBatch();
2599
2620
  }
2600
2621
  else {
2601
- return fail("'set()' can only be used on observable objects, arrays and maps");
2622
+ return fail(process.env.NODE_ENV !== "production" &&
2623
+ "'set()' can only be used on observable objects, arrays and maps");
2602
2624
  }
2603
2625
  }
2604
2626
  function remove(obj, key) {
@@ -2618,7 +2640,8 @@ function remove(obj, key) {
2618
2640
  obj.splice(key, 1);
2619
2641
  }
2620
2642
  else {
2621
- return fail("'remove()' can only be used on observable objects, arrays and maps");
2643
+ return fail(process.env.NODE_ENV !== "production" &&
2644
+ "'remove()' can only be used on observable objects, arrays and maps");
2622
2645
  }
2623
2646
  }
2624
2647
  function has(obj, key) {
@@ -2638,7 +2661,8 @@ function has(obj, key) {
2638
2661
  return key >= 0 && key < obj.length;
2639
2662
  }
2640
2663
  else {
2641
- return fail("'has()' can only be used on observable objects, arrays and maps");
2664
+ return fail(process.env.NODE_ENV !== "production" &&
2665
+ "'has()' can only be used on observable objects, arrays and maps");
2642
2666
  }
2643
2667
  }
2644
2668
  function get(obj, key) {
@@ -2654,7 +2678,8 @@ function get(obj, key) {
2654
2678
  return obj[key];
2655
2679
  }
2656
2680
  else {
2657
- return fail("'get()' can only be used on observable objects, arrays and maps");
2681
+ return fail(process.env.NODE_ENV !== "production" &&
2682
+ "'get()' can only be used on observable objects, arrays and maps");
2658
2683
  }
2659
2684
  }
2660
2685
 
@@ -2774,7 +2799,8 @@ function trace() {
2774
2799
  enterBreakPoint = args.pop();
2775
2800
  var derivation = getAtomFromArgs(args);
2776
2801
  if (!derivation) {
2777
- return fail("'trace(break?)' can only be used inside a tracked computed value or a Reaction. Consider passing in the computed value or reaction explicitly");
2802
+ return fail(process.env.NODE_ENV !== "production" &&
2803
+ "'trace(break?)' can only be used inside a tracked computed value or a Reaction. Consider passing in the computed value or reaction explicitly");
2778
2804
  }
2779
2805
  if (derivation.isTracing === TraceMode.NONE) {
2780
2806
  console.log("[mobx.trace] '" + derivation.name + "' tracing enabled");
@@ -2842,7 +2868,7 @@ function _when(predicate, effect, opts) {
2842
2868
  return disposer;
2843
2869
  }
2844
2870
  function whenPromise(predicate, opts) {
2845
- if (opts && opts.onError)
2871
+ if (process.env.NODE_ENV !== "production" && opts && opts.onError)
2846
2872
  return fail("the options 'onError' and 'promise' cannot be combined");
2847
2873
  var cancel;
2848
2874
  var res = new Promise(function (resolve, reject) {
@@ -3763,7 +3789,8 @@ var ObservableMap = /** @class */ (function () {
3763
3789
  * for callback details
3764
3790
  */
3765
3791
  ObservableMap.prototype.observe = function (listener, fireImmediately) {
3766
- invariant(fireImmediately !== true, "`observe` doesn't support fireImmediately=true in combination with maps.");
3792
+ process.env.NODE_ENV !== "production" &&
3793
+ invariant(fireImmediately !== true, "`observe` doesn't support fireImmediately=true in combination with maps.");
3767
3794
  return registerListener(this, listener);
3768
3795
  };
3769
3796
  ObservableMap.prototype.intercept = function (handler) {
@@ -3859,11 +3886,11 @@ var ObservableSet = /** @class */ (function () {
3859
3886
  newValue: value
3860
3887
  }
3861
3888
  : null;
3862
- if (notifySpy && "development" !== "production")
3889
+ if (notifySpy && process.env.NODE_ENV !== "production")
3863
3890
  spyReportStart(change);
3864
3891
  if (notify)
3865
3892
  notifyListeners(this, change);
3866
- if (notifySpy && "development" !== "production")
3893
+ if (notifySpy && process.env.NODE_ENV !== "production")
3867
3894
  spyReportEnd();
3868
3895
  }
3869
3896
  return this;
@@ -3889,7 +3916,7 @@ var ObservableSet = /** @class */ (function () {
3889
3916
  oldValue: value
3890
3917
  }
3891
3918
  : null;
3892
- if (notifySpy && "development" !== "production")
3919
+ if (notifySpy && process.env.NODE_ENV !== "production")
3893
3920
  spyReportStart(__assign(__assign({}, change), { name: this.name }));
3894
3921
  transaction(function () {
3895
3922
  _this._atom.reportChanged();
@@ -3897,7 +3924,7 @@ var ObservableSet = /** @class */ (function () {
3897
3924
  });
3898
3925
  if (notify)
3899
3926
  notifyListeners(this, change);
3900
- if (notifySpy && "development" !== "production")
3927
+ if (notifySpy && process.env.NODE_ENV !== "production")
3901
3928
  spyReportEnd();
3902
3929
  return true;
3903
3930
  }
@@ -3967,7 +3994,8 @@ var ObservableSet = /** @class */ (function () {
3967
3994
  };
3968
3995
  ObservableSet.prototype.observe = function (listener, fireImmediately) {
3969
3996
  // TODO 'fireImmediately' can be true?
3970
- invariant(fireImmediately !== true, "`observe` doesn't support fireImmediately=true in combination with sets.");
3997
+ process.env.NODE_ENV !== "production" &&
3998
+ invariant(fireImmediately !== true, "`observe` doesn't support fireImmediately=true in combination with sets.");
3971
3999
  return registerListener(this, listener);
3972
4000
  };
3973
4001
  ObservableSet.prototype.intercept = function (handler) {
@@ -3995,10 +4023,18 @@ var ObservableObjectAdministration = /** @class */ (function () {
3995
4023
  this.values = {};
3996
4024
  }
3997
4025
  ObservableObjectAdministration.prototype.read = function (owner, key) {
4026
+ if (process.env.NODE_ENV === "production" && this.target !== owner) {
4027
+ this.illegalAccess(owner, key);
4028
+ if (!this.values[key])
4029
+ return undefined;
4030
+ }
3998
4031
  return this.values[key].get();
3999
4032
  };
4000
4033
  ObservableObjectAdministration.prototype.write = function (owner, key, newValue) {
4001
4034
  var instance = this.target;
4035
+ if (process.env.NODE_ENV === "production" && instance !== owner) {
4036
+ this.illegalAccess(owner, key);
4037
+ }
4002
4038
  var observable = this.values[key];
4003
4039
  if (observable instanceof ComputedValue) {
4004
4040
  observable.set(newValue);
@@ -4108,7 +4144,8 @@ var ObservableObjectAdministration = /** @class */ (function () {
4108
4144
  * for callback details
4109
4145
  */
4110
4146
  ObservableObjectAdministration.prototype.observe = function (callback, fireImmediately) {
4111
- invariant(fireImmediately !== true, "`observe` doesn't support the fire immediately property for observable objects.");
4147
+ process.env.NODE_ENV !== "production" &&
4148
+ invariant(fireImmediately !== true, "`observe` doesn't support the fire immediately property for observable objects.");
4112
4149
  return registerListener(this, callback);
4113
4150
  };
4114
4151
  ObservableObjectAdministration.prototype.intercept = function (handler) {
@@ -4129,7 +4166,8 @@ function asObservableObject(target, name, defaultEnhancer) {
4129
4166
  var adm = target.$mobx;
4130
4167
  if (adm)
4131
4168
  return adm;
4132
- invariant(Object.isExtensible(target), "Cannot make the designated object observable; it is not extensible");
4169
+ process.env.NODE_ENV !== "production" &&
4170
+ invariant(Object.isExtensible(target), "Cannot make the designated object observable; it is not extensible");
4133
4171
  if (!isPlainObject(target))
4134
4172
  name = (target.constructor.name || "ObservableObject") + "@" + getNextId();
4135
4173
  if (!name)
@@ -4237,7 +4275,8 @@ function getAtom(thing, property) {
4237
4275
  if (typeof thing === "object" && thing !== null) {
4238
4276
  if (isObservableArray(thing)) {
4239
4277
  if (property !== undefined)
4240
- fail("It is not possible to get index atoms from arrays");
4278
+ fail(process.env.NODE_ENV !== "production" &&
4279
+ "It is not possible to get index atoms from arrays");
4241
4280
  return thing.$mobx.atom;
4242
4281
  }
4243
4282
  if (isObservableSet(thing)) {
@@ -4249,7 +4288,8 @@ function getAtom(thing, property) {
4249
4288
  return getAtom(anyThing._keys);
4250
4289
  var observable = anyThing._data.get(property) || anyThing._hasMap.get(property);
4251
4290
  if (!observable)
4252
- fail("the entry '" + property + "' does not exist in the observable map '" + getDebugName(thing) + "'");
4291
+ fail(process.env.NODE_ENV !== "production" &&
4292
+ "the entry '" + property + "' does not exist in the observable map '" + getDebugName(thing) + "'");
4253
4293
  return observable;
4254
4294
  }
4255
4295
  // Initializers run lazily when transpiling to babel, so make sure they are run...
@@ -4258,10 +4298,11 @@ function getAtom(thing, property) {
4258
4298
  thing[property]; // See #1072
4259
4299
  if (isObservableObject(thing)) {
4260
4300
  if (!property)
4261
- return fail("please specify a property");
4301
+ return fail(process.env.NODE_ENV !== "production" && "please specify a property");
4262
4302
  var observable = thing.$mobx.values[property];
4263
4303
  if (!observable)
4264
- fail("no observable property '" + property + "' found on the observable object '" + getDebugName(thing) + "'");
4304
+ fail(process.env.NODE_ENV !== "production" &&
4305
+ "no observable property '" + property + "' found on the observable object '" + getDebugName(thing) + "'");
4265
4306
  return observable;
4266
4307
  }
4267
4308
  if (isAtom(thing) || isComputedValue(thing) || isReaction(thing)) {
@@ -4274,7 +4315,7 @@ function getAtom(thing, property) {
4274
4315
  return thing.$mobx;
4275
4316
  }
4276
4317
  }
4277
- return fail("Cannot obtain atom from " + thing);
4318
+ return fail(process.env.NODE_ENV !== "production" && "Cannot obtain atom from " + thing);
4278
4319
  }
4279
4320
  function getAdministration(thing, property) {
4280
4321
  if (!thing)
@@ -4289,7 +4330,7 @@ function getAdministration(thing, property) {
4289
4330
  initializeInstance(thing);
4290
4331
  if (thing.$mobx)
4291
4332
  return thing.$mobx;
4292
- fail("Cannot obtain administration from " + thing);
4333
+ fail(process.env.NODE_ENV !== "production" && "Cannot obtain administration from " + thing);
4293
4334
  }
4294
4335
  function getDebugName(thing, property) {
4295
4336
  var named;
@@ -4466,6 +4507,11 @@ but at least in this file we can magically reorder the imports with trial and er
4466
4507
  *
4467
4508
  */
4468
4509
  try {
4510
+ // define process.env if needed
4511
+ // if this is not a production build in the first place
4512
+ // (in which case the expression below would be substituted with 'production')
4513
+ // tslint:disable-next-line
4514
+ process.env.NODE_ENV;
4469
4515
  }
4470
4516
  catch (e) {
4471
4517
  var g = getGlobal();
@@ -4476,8 +4522,8 @@ catch (e) {
4476
4522
  (function () {
4477
4523
  function testCodeMinification() { }
4478
4524
  if (testCodeMinification.name !== "testCodeMinification" &&
4479
- "development" !== "production" &&
4480
- process.env.IGNORE_MOBX_MINIFY_WARNING !== "true") {
4525
+ process.env.NODE_ENV !== "production" &&
4526
+ typeof process !== 'undefined' && process.env.IGNORE_MOBX_MINIFY_WARNING !== "true") {
4481
4527
  // trick so it doesn't get replaced
4482
4528
  var varName = ["process", "env", "NODE_ENV"].join(".");
4483
4529
  console.warn("[mobx] you are running a minified build, but '" + varName + "' was not set to 'production' in your bundler. This results in an unnecessarily large and slow bundle");
@@ -4496,7 +4542,8 @@ if (typeof __MOBX_DEVTOOLS_GLOBAL_HOOK__ === "object") {
4496
4542
  });
4497
4543
  }
4498
4544
  // TODO: remove in some future build
4499
- if (typeof module !== "undefined" &&
4545
+ if (process.env.NODE_ENV !== "production" &&
4546
+ typeof module !== "undefined" &&
4500
4547
  typeof module.exports !== "undefined") {
4501
4548
  var warnedAboutDefaultExport_1 = false;
4502
4549
  Object.defineProperty(module.exports, "default", {