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.
package/lib/mobx.umd.js CHANGED
@@ -103,6 +103,8 @@
103
103
  */
104
104
  var deprecatedMessages = [];
105
105
  function deprecated(msg, thing) {
106
+ if (process.env.NODE_ENV === "production")
107
+ return false;
106
108
  if (thing) {
107
109
  return deprecated("'" + msg + "', use '" + thing + "' instead.");
108
110
  }
@@ -182,7 +184,7 @@
182
184
  return !descriptor || (descriptor.configurable !== false && descriptor.writable !== false);
183
185
  }
184
186
  function assertPropertyConfigurable(object, prop) {
185
- if (!isPropertyConfigurable(object, prop))
187
+ if (process.env.NODE_ENV !== "production" && !isPropertyConfigurable(object, prop))
186
188
  fail("Cannot make property '" + prop + "' observable, it is not configurable and writable in the target object");
187
189
  }
188
190
  function createInstanceofPredicate(name, clazz) {
@@ -363,7 +365,7 @@
363
365
  propertyCreator(target, prop, descriptor, target, decoratorArguments);
364
366
  return null;
365
367
  }
366
- if (!quacksLikeADecorator(arguments))
368
+ if (process.env.NODE_ENV !== "production" && !quacksLikeADecorator(arguments))
367
369
  fail("This function is a decorator, but it wasn't invoked like a decorator");
368
370
  if (!Object.prototype.hasOwnProperty.call(target, "__mobxDecorators")) {
369
371
  var inheritedDecorators = target.__mobxDecorators;
@@ -423,14 +425,15 @@
423
425
  return observable.map(v, { name: name, deep: false });
424
426
  if (isES6Set(v))
425
427
  return observable.set(v, { name: name, deep: false });
426
- return fail("The shallow modifier / decorator can only used in combination with arrays, objects, maps and sets");
428
+ return fail(process.env.NODE_ENV !== "production" &&
429
+ "The shallow modifier / decorator can only used in combination with arrays, objects, maps and sets");
427
430
  }
428
431
  function referenceEnhancer(newValue) {
429
432
  // never turn into an observable
430
433
  return newValue;
431
434
  }
432
435
  function refStructEnhancer(v, oldValue, name) {
433
- if (isObservable(v))
436
+ if (process.env.NODE_ENV !== "production" && isObservable(v))
434
437
  throw "observable.struct should not be used with observable values";
435
438
  if (deepEqual(v, oldValue))
436
439
  return oldValue;
@@ -440,7 +443,7 @@
440
443
  function createDecoratorForEnhancer(enhancer) {
441
444
  invariant(enhancer);
442
445
  var decorator = createPropDecorator(true, function (target, propertyName, descriptor, _decoratorTarget, decoratorArgs) {
443
- {
446
+ if (process.env.NODE_ENV !== "production") {
444
447
  invariant(!descriptor || !descriptor.get, "@observable cannot be used on getter (property \"" + propertyName + "\"), use @computed instead.");
445
448
  }
446
449
  var initialValue = descriptor
@@ -452,7 +455,7 @@
452
455
  });
453
456
  var res =
454
457
  // Extra process checks, as this happens during module initialization
455
- typeof process !== "undefined" && process.env && "development" !== "production"
458
+ typeof process !== "undefined" && process.env && process.env.NODE_ENV !== "production"
456
459
  ? function observableDecorator() {
457
460
  // This wrapper function is just to detect illegal decorator invocations, deprecate in a next version
458
461
  // and simply return the created prop decorator
@@ -488,7 +491,7 @@
488
491
  return defaultCreateObservableOptions;
489
492
  if (typeof thing === "string")
490
493
  return { name: thing, deep: true };
491
- {
494
+ if (process.env.NODE_ENV !== "production") {
492
495
  if (typeof thing !== "object")
493
496
  return fail("expected options object");
494
497
  Object.keys(thing).forEach(assertValidOption);
@@ -532,7 +535,8 @@
532
535
  if (res !== v)
533
536
  return res;
534
537
  // otherwise, just box it
535
- 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)'");
538
+ fail(process.env.NODE_ENV !== "production" &&
539
+ "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)'");
536
540
  }
537
541
  var observableFactories = {
538
542
  box: function (value, options) {
@@ -599,7 +603,7 @@
599
603
  Object.keys(observableFactories).forEach(function (name) { return (observable[name] = observableFactories[name]); });
600
604
  function incorrectlyUsedAsDecorator(methodName) {
601
605
  fail(
602
- // "development" !== "production" &&
606
+ // process.env.NODE_ENV !== "production" &&
603
607
  "Expected one or two arguments to observable." + methodName + ". Did you accidentally try to use observable." + methodName + " as decorator?");
604
608
  }
605
609
 
@@ -626,7 +630,7 @@
626
630
  return computedDecorator.apply(null, arguments);
627
631
  }
628
632
  // computed(expr, options?)
629
- {
633
+ if (process.env.NODE_ENV !== "production") {
630
634
  invariant(typeof arg1 === "function", "First argument to `computed` should be an expression.");
631
635
  invariant(arguments.length < 3, "Computed takes one or two arguments if used as function");
632
636
  }
@@ -733,7 +737,7 @@
733
737
  // function invariantShouldCompute(derivation: IDerivation) {
734
738
  // const newDepState = (derivation as any).dependenciesState
735
739
  // if (
736
- // "development" === "production" &&
740
+ // process.env.NODE_ENV === "production" &&
737
741
  // (newDepState === IDerivationState.POSSIBLY_STALE ||
738
742
  // newDepState === IDerivationState.NOT_TRACKING)
739
743
  // )
@@ -746,16 +750,19 @@
746
750
  var hasObservers = atom.observers.length > 0;
747
751
  // Should never be possible to change an observed observable from inside computed, see #798
748
752
  if (globalState.computationDepth > 0 && hasObservers)
749
- fail("Computed values are not allowed to cause side effects by changing observables that are already being observed. Tried to modify: " + atom.name);
753
+ fail(process.env.NODE_ENV !== "production" &&
754
+ "Computed values are not allowed to cause side effects by changing observables that are already being observed. Tried to modify: " + atom.name);
750
755
  // Should not be possible to change observed state outside strict mode, except during initialization, see #563
751
756
  if (!globalState.allowStateChanges && (hasObservers || globalState.enforceActions === "strict"))
752
- fail((globalState.enforceActions
757
+ fail(process.env.NODE_ENV !== "production" &&
758
+ (globalState.enforceActions
753
759
  ? "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: "
754
760
  : "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: ") +
755
761
  atom.name);
756
762
  }
757
763
  function checkIfStateReadsAreAllowed(observable) {
758
- if (!globalState.allowStateReads &&
764
+ if (process.env.NODE_ENV !== "production" &&
765
+ !globalState.allowStateReads &&
759
766
  globalState.observableRequiresReaction) {
760
767
  console.warn("[mobx] Observable " + observable.name + " being read outside a reactive context");
761
768
  }
@@ -796,6 +803,8 @@
796
803
  return result;
797
804
  }
798
805
  function warnAboutDerivationWithoutDependencies(derivation) {
806
+ if (process.env.NODE_ENV === "production")
807
+ return;
799
808
  if (globalState.reactionRequiresObservable || derivation.requiresObservable) {
800
809
  console.warn("[mobx] Derivation " + derivation.name + " is created/updated without reading any observable value");
801
810
  }
@@ -910,7 +919,7 @@
910
919
  var functionNameDescriptor = Object.getOwnPropertyDescriptor(function () { }, "name");
911
920
  var isFunctionNameConfigurable = functionNameDescriptor && functionNameDescriptor.configurable;
912
921
  function createAction(actionName, fn) {
913
- {
922
+ if (process.env.NODE_ENV !== "production") {
914
923
  invariant(typeof fn === "function", "`action` can only be invoked on functions");
915
924
  if (typeof actionName !== "string" || !actionName)
916
925
  fail("actions should have valid names, got: '" + actionName + "'");
@@ -918,7 +927,7 @@
918
927
  var res = function () {
919
928
  return executeAction(actionName, fn, this, arguments);
920
929
  };
921
- {
930
+ if (process.env.NODE_ENV !== "production") {
922
931
  if (isFunctionNameConfigurable) {
923
932
  Object.defineProperty(res, "name", { value: actionName });
924
933
  }
@@ -1235,7 +1244,8 @@
1235
1244
  }
1236
1245
  }
1237
1246
  else
1238
- invariant(false, "[ComputedValue '" + this.name + "'] It is not possible to assign a new value to a computed value.");
1247
+ invariant(false, process.env.NODE_ENV !== "production" &&
1248
+ "[ComputedValue '" + this.name + "'] It is not possible to assign a new value to a computed value.");
1239
1249
  };
1240
1250
  ComputedValue.prototype.trackAndCompute = function () {
1241
1251
  if (isSpyEnabled()) {
@@ -1309,6 +1319,8 @@
1309
1319
  });
1310
1320
  };
1311
1321
  ComputedValue.prototype.warnAboutUntrackedRead = function () {
1322
+ if (process.env.NODE_ENV === "production")
1323
+ return;
1312
1324
  if (this.requiresReaction === true) {
1313
1325
  fail("[mobx] Computed value " + this.name + " is read outside a reactive context");
1314
1326
  }
@@ -1950,12 +1962,12 @@
1950
1962
  }
1951
1963
 
1952
1964
  function dontReassignFields() {
1953
- fail("@action fields are not reassignable");
1965
+ fail(process.env.NODE_ENV !== "production" && "@action fields are not reassignable");
1954
1966
  }
1955
1967
  function namedActionDecorator(name) {
1956
1968
  return function (target, prop, descriptor) {
1957
1969
  if (descriptor) {
1958
- if (descriptor.get !== undefined) {
1970
+ if (process.env.NODE_ENV !== "production" && descriptor.get !== undefined) {
1959
1971
  return fail("@action cannot be used with getters");
1960
1972
  }
1961
1973
  // babel / typescript
@@ -2056,7 +2068,7 @@
2056
2068
  // TODO: deprecate?
2057
2069
  var actionName = typeof arg1 === "string" ? arg1 : arg1.name || "<unnamed action>";
2058
2070
  var fn = typeof arg1 === "function" ? arg1 : arg2;
2059
- {
2071
+ if (process.env.NODE_ENV !== "production") {
2060
2072
  invariant(typeof fn === "function" && fn.length === 0, "`runInAction` expects a function without arguments");
2061
2073
  if (typeof actionName !== "string" || !actionName)
2062
2074
  fail("actions should have valid names, got: '" + actionName + "'");
@@ -2078,7 +2090,7 @@
2078
2090
  */
2079
2091
  function autorun(view, opts) {
2080
2092
  if (opts === void 0) { opts = EMPTY_OBJECT; }
2081
- {
2093
+ if (process.env.NODE_ENV !== "production") {
2082
2094
  invariant(typeof view === "function", "Autorun expects a function as first argument");
2083
2095
  invariant(isAction(view) === false, "Autorun does not accept actions since actions are untrackable");
2084
2096
  }
@@ -2126,7 +2138,7 @@
2126
2138
  opts = { fireImmediately: opts };
2127
2139
  deprecated("Using fireImmediately as argument is deprecated. Use '{ fireImmediately: true }' instead");
2128
2140
  }
2129
- {
2141
+ if (process.env.NODE_ENV !== "production") {
2130
2142
  invariant(typeof expression === "function", "First argument to reaction should be a function");
2131
2143
  invariant(typeof opts === "object", "Third argument of reactions should be an object");
2132
2144
  }
@@ -2191,7 +2203,7 @@
2191
2203
  var cb = typeof arg3 === "function" ? arg3 : arg2;
2192
2204
  var orig = atom[hook];
2193
2205
  if (typeof orig !== "function")
2194
- return fail("Not an atom that can be (un)observed");
2206
+ return fail(process.env.NODE_ENV !== "production" && "Not an atom that can be (un)observed");
2195
2207
  atom[hook] = function () {
2196
2208
  orig.call(this);
2197
2209
  cb.call(this);
@@ -2256,7 +2268,7 @@
2256
2268
  }
2257
2269
 
2258
2270
  function decorate(thing, decorators) {
2259
- if (!isPlainObject(decorators))
2271
+ if (process.env.NODE_ENV !== "production" && !isPlainObject(decorators))
2260
2272
  fail("Decorators should be a key value map");
2261
2273
  var target = typeof thing === "function" ? thing.prototype : thing;
2262
2274
  var _loop_1 = function (prop) {
@@ -2265,7 +2277,7 @@
2265
2277
  propertyDecorators = [propertyDecorators];
2266
2278
  }
2267
2279
  // prettier-ignore
2268
- if (!propertyDecorators.every(function (decorator) { return typeof decorator === "function"; }))
2280
+ if (process.env.NODE_ENV !== "production" && !propertyDecorators.every(function (decorator) { return typeof decorator === "function"; }))
2269
2281
  fail("Decorate: expected a decorator function or array of decorator functions for '" + prop + "'");
2270
2282
  var descriptor = Object.getOwnPropertyDescriptor(target, prop);
2271
2283
  var newDescriptor = propertyDecorators.reduce(function (accDescriptor, decorator) { return decorator(target, prop, accDescriptor); }, descriptor);
@@ -2283,7 +2295,7 @@
2283
2295
  return extendObservable(target, properties, decorators, shallowCreateObservableOptions);
2284
2296
  }
2285
2297
  function extendObservable(target, properties, decorators, options) {
2286
- {
2298
+ if (process.env.NODE_ENV !== "production") {
2287
2299
  invariant(arguments.length >= 2 && arguments.length <= 4, "'extendObservable' expected 2-4 arguments");
2288
2300
  invariant(typeof target === "object", "'extendObservable' expects an object as first argument");
2289
2301
  invariant(!isObservableMap(target), "'extendObservable' should not be used on maps, use map.merge instead");
@@ -2301,7 +2313,7 @@
2301
2313
  try {
2302
2314
  for (var key in properties) {
2303
2315
  var descriptor = Object.getOwnPropertyDescriptor(properties, key);
2304
- {
2316
+ if (process.env.NODE_ENV !== "production") {
2305
2317
  if (isComputed(descriptor.value))
2306
2318
  fail("Passing a 'computed' as initial property value is no longer supported by extendObservable. Use a getter or decorator instead");
2307
2319
  }
@@ -2310,7 +2322,7 @@
2310
2322
  : descriptor.get
2311
2323
  ? computedDecorator
2312
2324
  : defaultDecorator;
2313
- if (typeof decorator !== "function")
2325
+ if (process.env.NODE_ENV !== "production" && typeof decorator !== "function")
2314
2326
  return fail("Not a valid decorator for '" + key + "', got: " + decorator);
2315
2327
  var resultDescriptor = decorator(target, key, descriptor, true);
2316
2328
  if (resultDescriptor // otherwise, assume already applied, due to `applyToInstance`
@@ -2357,7 +2369,7 @@
2357
2369
  }
2358
2370
  function flow(generator) {
2359
2371
  if (arguments.length !== 1)
2360
- fail("Flow expects one 1 argument and cannot be used as decorator");
2372
+ fail(!!process.env.NODE_ENV && "Flow expects one 1 argument and cannot be used as decorator");
2361
2373
  var name = generator.name || "<unnamed flow>";
2362
2374
  // Implementation based on https://github.com/tj/co/blob/master/index.js
2363
2375
  return function () {
@@ -2437,14 +2449,16 @@
2437
2449
  }
2438
2450
  else if (isObservableObject(thing)) {
2439
2451
  if (typeof propOrHandler !== "string")
2440
- return fail("InterceptReads can only be used with a specific property, not with an object in general");
2452
+ return fail(process.env.NODE_ENV !== "production" &&
2453
+ "InterceptReads can only be used with a specific property, not with an object in general");
2441
2454
  target = getAdministration(thing, propOrHandler);
2442
2455
  }
2443
2456
  else {
2444
- return fail("Expected observable map, object or array as first array");
2457
+ return fail(process.env.NODE_ENV !== "production" &&
2458
+ "Expected observable map, object or array as first array");
2445
2459
  }
2446
2460
  if (target.dehancer !== undefined)
2447
- return fail("An intercept reader was already established");
2461
+ return fail(process.env.NODE_ENV !== "production" && "An intercept reader was already established");
2448
2462
  target.dehancer = typeof propOrHandler === "function" ? propOrHandler : handler;
2449
2463
  return function () {
2450
2464
  target.dehancer = undefined;
@@ -2479,12 +2493,14 @@
2479
2493
  }
2480
2494
  function isComputed(value) {
2481
2495
  if (arguments.length > 1)
2482
- return fail("isComputed expects only 1 argument. Use isObservableProp to inspect the observability of a property");
2496
+ return fail(process.env.NODE_ENV !== "production" &&
2497
+ "isComputed expects only 1 argument. Use isObservableProp to inspect the observability of a property");
2483
2498
  return _isComputed(value);
2484
2499
  }
2485
2500
  function isComputedProp(value, propName) {
2486
2501
  if (typeof propName !== "string")
2487
- return fail("isComputed expected a property name as second argument");
2502
+ return fail(process.env.NODE_ENV !== "production" &&
2503
+ "isComputed expected a property name as second argument");
2488
2504
  return _isComputed(value, propName);
2489
2505
  }
2490
2506
 
@@ -2492,7 +2508,8 @@
2492
2508
  if (value === null || value === undefined)
2493
2509
  return false;
2494
2510
  if (property !== undefined) {
2495
- if (isObservableMap(value) || isObservableArray(value))
2511
+ if (process.env.NODE_ENV !== "production" &&
2512
+ (isObservableMap(value) || isObservableArray(value)))
2496
2513
  return fail("isObservable(object, propertyName) is not supported for arrays and maps. Use map.has or array.length instead.");
2497
2514
  if (isObservableObject(value)) {
2498
2515
  var o = value.$mobx;
@@ -2509,12 +2526,13 @@
2509
2526
  }
2510
2527
  function isObservable(value) {
2511
2528
  if (arguments.length !== 1)
2512
- fail("isObservable expects only 1 argument. Use isObservableProp to inspect the observability of a property");
2529
+ fail(process.env.NODE_ENV !== "production" &&
2530
+ "isObservable expects only 1 argument. Use isObservableProp to inspect the observability of a property");
2513
2531
  return _isObservable(value);
2514
2532
  }
2515
2533
  function isObservableProp(value, propName) {
2516
2534
  if (typeof propName !== "string")
2517
- return fail("expected a property name as second argument");
2535
+ return fail(process.env.NODE_ENV !== "production" && "expected a property name as second argument");
2518
2536
  return _isObservable(value, propName);
2519
2537
  }
2520
2538
 
@@ -2531,7 +2549,8 @@
2531
2549
  if (isObservableArray(obj)) {
2532
2550
  return obj.map(function (_, index) { return index; });
2533
2551
  }
2534
- return fail("'keys()' can only be used on observable objects, arrays, sets and maps");
2552
+ return fail(process.env.NODE_ENV !== "production" &&
2553
+ "'keys()' can only be used on observable objects, arrays, sets and maps");
2535
2554
  }
2536
2555
  function values(obj) {
2537
2556
  if (isObservableObject(obj)) {
@@ -2546,7 +2565,8 @@
2546
2565
  if (isObservableArray(obj)) {
2547
2566
  return obj.slice();
2548
2567
  }
2549
- return fail("'values()' can only be used on observable objects, arrays, sets and maps");
2568
+ return fail(process.env.NODE_ENV !== "production" &&
2569
+ "'values()' can only be used on observable objects, arrays, sets and maps");
2550
2570
  }
2551
2571
  function entries(obj) {
2552
2572
  if (isObservableObject(obj)) {
@@ -2561,7 +2581,8 @@
2561
2581
  if (isObservableArray(obj)) {
2562
2582
  return obj.map(function (key, index) { return [index, key]; });
2563
2583
  }
2564
- return fail("'entries()' can only be used on observable objects, arrays and maps");
2584
+ return fail(process.env.NODE_ENV !== "production" &&
2585
+ "'entries()' can only be used on observable objects, arrays and maps");
2565
2586
  }
2566
2587
  function set(obj, key, value) {
2567
2588
  if (arguments.length === 2 && !isObservableSet(obj)) {
@@ -2603,7 +2624,8 @@
2603
2624
  endBatch();
2604
2625
  }
2605
2626
  else {
2606
- return fail("'set()' can only be used on observable objects, arrays and maps");
2627
+ return fail(process.env.NODE_ENV !== "production" &&
2628
+ "'set()' can only be used on observable objects, arrays and maps");
2607
2629
  }
2608
2630
  }
2609
2631
  function remove(obj, key) {
@@ -2623,7 +2645,8 @@
2623
2645
  obj.splice(key, 1);
2624
2646
  }
2625
2647
  else {
2626
- return fail("'remove()' can only be used on observable objects, arrays and maps");
2648
+ return fail(process.env.NODE_ENV !== "production" &&
2649
+ "'remove()' can only be used on observable objects, arrays and maps");
2627
2650
  }
2628
2651
  }
2629
2652
  function has(obj, key) {
@@ -2643,7 +2666,8 @@
2643
2666
  return key >= 0 && key < obj.length;
2644
2667
  }
2645
2668
  else {
2646
- return fail("'has()' can only be used on observable objects, arrays and maps");
2669
+ return fail(process.env.NODE_ENV !== "production" &&
2670
+ "'has()' can only be used on observable objects, arrays and maps");
2647
2671
  }
2648
2672
  }
2649
2673
  function get(obj, key) {
@@ -2659,7 +2683,8 @@
2659
2683
  return obj[key];
2660
2684
  }
2661
2685
  else {
2662
- return fail("'get()' can only be used on observable objects, arrays and maps");
2686
+ return fail(process.env.NODE_ENV !== "production" &&
2687
+ "'get()' can only be used on observable objects, arrays and maps");
2663
2688
  }
2664
2689
  }
2665
2690
 
@@ -2779,7 +2804,8 @@
2779
2804
  enterBreakPoint = args.pop();
2780
2805
  var derivation = getAtomFromArgs(args);
2781
2806
  if (!derivation) {
2782
- 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");
2807
+ return fail(process.env.NODE_ENV !== "production" &&
2808
+ "'trace(break?)' can only be used inside a tracked computed value or a Reaction. Consider passing in the computed value or reaction explicitly");
2783
2809
  }
2784
2810
  if (derivation.isTracing === TraceMode.NONE) {
2785
2811
  console.log("[mobx.trace] '" + derivation.name + "' tracing enabled");
@@ -2847,7 +2873,7 @@
2847
2873
  return disposer;
2848
2874
  }
2849
2875
  function whenPromise(predicate, opts) {
2850
- if (opts && opts.onError)
2876
+ if (process.env.NODE_ENV !== "production" && opts && opts.onError)
2851
2877
  return fail("the options 'onError' and 'promise' cannot be combined");
2852
2878
  var cancel;
2853
2879
  var res = new Promise(function (resolve, reject) {
@@ -3768,7 +3794,8 @@
3768
3794
  * for callback details
3769
3795
  */
3770
3796
  ObservableMap.prototype.observe = function (listener, fireImmediately) {
3771
- invariant(fireImmediately !== true, "`observe` doesn't support fireImmediately=true in combination with maps.");
3797
+ process.env.NODE_ENV !== "production" &&
3798
+ invariant(fireImmediately !== true, "`observe` doesn't support fireImmediately=true in combination with maps.");
3772
3799
  return registerListener(this, listener);
3773
3800
  };
3774
3801
  ObservableMap.prototype.intercept = function (handler) {
@@ -3864,11 +3891,11 @@
3864
3891
  newValue: value
3865
3892
  }
3866
3893
  : null;
3867
- if (notifySpy && "development" !== "production")
3894
+ if (notifySpy && process.env.NODE_ENV !== "production")
3868
3895
  spyReportStart(change);
3869
3896
  if (notify)
3870
3897
  notifyListeners(this, change);
3871
- if (notifySpy && "development" !== "production")
3898
+ if (notifySpy && process.env.NODE_ENV !== "production")
3872
3899
  spyReportEnd();
3873
3900
  }
3874
3901
  return this;
@@ -3894,7 +3921,7 @@
3894
3921
  oldValue: value
3895
3922
  }
3896
3923
  : null;
3897
- if (notifySpy && "development" !== "production")
3924
+ if (notifySpy && process.env.NODE_ENV !== "production")
3898
3925
  spyReportStart(__assign(__assign({}, change), { name: this.name }));
3899
3926
  transaction(function () {
3900
3927
  _this._atom.reportChanged();
@@ -3902,7 +3929,7 @@
3902
3929
  });
3903
3930
  if (notify)
3904
3931
  notifyListeners(this, change);
3905
- if (notifySpy && "development" !== "production")
3932
+ if (notifySpy && process.env.NODE_ENV !== "production")
3906
3933
  spyReportEnd();
3907
3934
  return true;
3908
3935
  }
@@ -3972,7 +3999,8 @@
3972
3999
  };
3973
4000
  ObservableSet.prototype.observe = function (listener, fireImmediately) {
3974
4001
  // TODO 'fireImmediately' can be true?
3975
- invariant(fireImmediately !== true, "`observe` doesn't support fireImmediately=true in combination with sets.");
4002
+ process.env.NODE_ENV !== "production" &&
4003
+ invariant(fireImmediately !== true, "`observe` doesn't support fireImmediately=true in combination with sets.");
3976
4004
  return registerListener(this, listener);
3977
4005
  };
3978
4006
  ObservableSet.prototype.intercept = function (handler) {
@@ -4000,10 +4028,18 @@
4000
4028
  this.values = {};
4001
4029
  }
4002
4030
  ObservableObjectAdministration.prototype.read = function (owner, key) {
4031
+ if (process.env.NODE_ENV === "production" && this.target !== owner) {
4032
+ this.illegalAccess(owner, key);
4033
+ if (!this.values[key])
4034
+ return undefined;
4035
+ }
4003
4036
  return this.values[key].get();
4004
4037
  };
4005
4038
  ObservableObjectAdministration.prototype.write = function (owner, key, newValue) {
4006
4039
  var instance = this.target;
4040
+ if (process.env.NODE_ENV === "production" && instance !== owner) {
4041
+ this.illegalAccess(owner, key);
4042
+ }
4007
4043
  var observable = this.values[key];
4008
4044
  if (observable instanceof ComputedValue) {
4009
4045
  observable.set(newValue);
@@ -4113,7 +4149,8 @@
4113
4149
  * for callback details
4114
4150
  */
4115
4151
  ObservableObjectAdministration.prototype.observe = function (callback, fireImmediately) {
4116
- invariant(fireImmediately !== true, "`observe` doesn't support the fire immediately property for observable objects.");
4152
+ process.env.NODE_ENV !== "production" &&
4153
+ invariant(fireImmediately !== true, "`observe` doesn't support the fire immediately property for observable objects.");
4117
4154
  return registerListener(this, callback);
4118
4155
  };
4119
4156
  ObservableObjectAdministration.prototype.intercept = function (handler) {
@@ -4134,7 +4171,8 @@
4134
4171
  var adm = target.$mobx;
4135
4172
  if (adm)
4136
4173
  return adm;
4137
- invariant(Object.isExtensible(target), "Cannot make the designated object observable; it is not extensible");
4174
+ process.env.NODE_ENV !== "production" &&
4175
+ invariant(Object.isExtensible(target), "Cannot make the designated object observable; it is not extensible");
4138
4176
  if (!isPlainObject(target))
4139
4177
  name = (target.constructor.name || "ObservableObject") + "@" + getNextId();
4140
4178
  if (!name)
@@ -4242,7 +4280,8 @@
4242
4280
  if (typeof thing === "object" && thing !== null) {
4243
4281
  if (isObservableArray(thing)) {
4244
4282
  if (property !== undefined)
4245
- fail("It is not possible to get index atoms from arrays");
4283
+ fail(process.env.NODE_ENV !== "production" &&
4284
+ "It is not possible to get index atoms from arrays");
4246
4285
  return thing.$mobx.atom;
4247
4286
  }
4248
4287
  if (isObservableSet(thing)) {
@@ -4254,7 +4293,8 @@
4254
4293
  return getAtom(anyThing._keys);
4255
4294
  var observable = anyThing._data.get(property) || anyThing._hasMap.get(property);
4256
4295
  if (!observable)
4257
- fail("the entry '" + property + "' does not exist in the observable map '" + getDebugName(thing) + "'");
4296
+ fail(process.env.NODE_ENV !== "production" &&
4297
+ "the entry '" + property + "' does not exist in the observable map '" + getDebugName(thing) + "'");
4258
4298
  return observable;
4259
4299
  }
4260
4300
  // Initializers run lazily when transpiling to babel, so make sure they are run...
@@ -4263,10 +4303,11 @@
4263
4303
  thing[property]; // See #1072
4264
4304
  if (isObservableObject(thing)) {
4265
4305
  if (!property)
4266
- return fail("please specify a property");
4306
+ return fail(process.env.NODE_ENV !== "production" && "please specify a property");
4267
4307
  var observable = thing.$mobx.values[property];
4268
4308
  if (!observable)
4269
- fail("no observable property '" + property + "' found on the observable object '" + getDebugName(thing) + "'");
4309
+ fail(process.env.NODE_ENV !== "production" &&
4310
+ "no observable property '" + property + "' found on the observable object '" + getDebugName(thing) + "'");
4270
4311
  return observable;
4271
4312
  }
4272
4313
  if (isAtom(thing) || isComputedValue(thing) || isReaction(thing)) {
@@ -4279,7 +4320,7 @@
4279
4320
  return thing.$mobx;
4280
4321
  }
4281
4322
  }
4282
- return fail("Cannot obtain atom from " + thing);
4323
+ return fail(process.env.NODE_ENV !== "production" && "Cannot obtain atom from " + thing);
4283
4324
  }
4284
4325
  function getAdministration(thing, property) {
4285
4326
  if (!thing)
@@ -4294,7 +4335,7 @@
4294
4335
  initializeInstance(thing);
4295
4336
  if (thing.$mobx)
4296
4337
  return thing.$mobx;
4297
- fail("Cannot obtain administration from " + thing);
4338
+ fail(process.env.NODE_ENV !== "production" && "Cannot obtain administration from " + thing);
4298
4339
  }
4299
4340
  function getDebugName(thing, property) {
4300
4341
  var named;
@@ -4471,6 +4512,11 @@
4471
4512
  *
4472
4513
  */
4473
4514
  try {
4515
+ // define process.env if needed
4516
+ // if this is not a production build in the first place
4517
+ // (in which case the expression below would be substituted with 'production')
4518
+ // tslint:disable-next-line
4519
+ process.env.NODE_ENV;
4474
4520
  }
4475
4521
  catch (e) {
4476
4522
  var g = getGlobal();
@@ -4481,8 +4527,8 @@
4481
4527
  (function () {
4482
4528
  function testCodeMinification() { }
4483
4529
  if (testCodeMinification.name !== "testCodeMinification" &&
4484
- "development" !== "production" &&
4485
- process.env.IGNORE_MOBX_MINIFY_WARNING !== "true") {
4530
+ process.env.NODE_ENV !== "production" &&
4531
+ typeof process !== 'undefined' && process.env.IGNORE_MOBX_MINIFY_WARNING !== "true") {
4486
4532
  // trick so it doesn't get replaced
4487
4533
  var varName = ["process", "env", "NODE_ENV"].join(".");
4488
4534
  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");
@@ -4501,7 +4547,8 @@
4501
4547
  });
4502
4548
  }
4503
4549
  // TODO: remove in some future build
4504
- if (typeof module !== "undefined" &&
4550
+ if (process.env.NODE_ENV !== "production" &&
4551
+ typeof module !== "undefined" &&
4505
4552
  typeof module.exports !== "undefined") {
4506
4553
  var warnedAboutDefaultExport_1 = false;
4507
4554
  Object.defineProperty(module.exports, "default", {
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "mobx",
3
- "version": "4.15.3",
3
+ "version": "4.15.4",
4
4
  "description": "Simple, scalable state management.",
5
- "main": "lib/mobx.js",
5
+ "main": "lib/index.js",
6
6
  "umd:main": "lib/mobx.umd.js",
7
7
  "module": "lib/mobx.module.js",
8
8
  "browser": {
9
- "./lib/mobx.js": "./lib/mobx.js",
9
+ "./lib/mobx.js": "./lib/mobx.min.js",
10
10
  "./lib/mobx.module.js": "./lib/mobx.module.js"
11
11
  },
12
12
  "unpkg": "lib/mobx.umd.min.js",