mobx 5.15.3 → 5.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.es6.js CHANGED
@@ -21,6 +21,8 @@ function invariant(check, message) {
21
21
  */
22
22
  const deprecatedMessages = [];
23
23
  function deprecated(msg, thing) {
24
+ if (process.env.NODE_ENV === "production")
25
+ return false;
24
26
  if (thing) {
25
27
  return deprecated(`'${msg}', use '${thing}' instead.`);
26
28
  }
@@ -81,7 +83,7 @@ function isPropertyConfigurable(object, prop) {
81
83
  return !descriptor || (descriptor.configurable !== false && descriptor.writable !== false);
82
84
  }
83
85
  function assertPropertyConfigurable(object, prop) {
84
- if (!isPropertyConfigurable(object, prop))
86
+ if (process.env.NODE_ENV !== "production" && !isPropertyConfigurable(object, prop))
85
87
  fail(`Cannot make property '${prop.toString()}' observable, it is not configurable and writable in the target object`);
86
88
  }
87
89
  function createInstanceofPredicate(name, clazz) {
@@ -258,7 +260,7 @@ function createPropDecorator(propertyInitiallyEnumerable, propertyCreator) {
258
260
  propertyCreator(target, prop, descriptor, target, decoratorArguments);
259
261
  return null;
260
262
  }
261
- if (!quacksLikeADecorator(arguments))
263
+ if (process.env.NODE_ENV !== "production" && !quacksLikeADecorator(arguments))
262
264
  fail("This function is a decorator, but it wasn't invoked like a decorator");
263
265
  if (!Object.prototype.hasOwnProperty.call(target, mobxPendingDecorators)) {
264
266
  const inheritedDecorators = target[mobxPendingDecorators];
@@ -319,14 +321,15 @@ function shallowEnhancer(v, _, name) {
319
321
  return observable.map(v, { name, deep: false });
320
322
  if (isES6Set(v))
321
323
  return observable.set(v, { name, deep: false });
322
- return fail("The shallow modifier / decorator can only used in combination with arrays, objects, maps and sets");
324
+ return fail(process.env.NODE_ENV !== "production" &&
325
+ "The shallow modifier / decorator can only used in combination with arrays, objects, maps and sets");
323
326
  }
324
327
  function referenceEnhancer(newValue) {
325
328
  // never turn into an observable
326
329
  return newValue;
327
330
  }
328
331
  function refStructEnhancer(v, oldValue, name) {
329
- if (isObservable(v))
332
+ if (process.env.NODE_ENV !== "production" && isObservable(v))
330
333
  throw `observable.struct should not be used with observable values`;
331
334
  if (deepEqual(v, oldValue))
332
335
  return oldValue;
@@ -336,7 +339,7 @@ function refStructEnhancer(v, oldValue, name) {
336
339
  function createDecoratorForEnhancer(enhancer) {
337
340
  invariant(enhancer);
338
341
  const decorator = createPropDecorator(true, (target, propertyName, descriptor, _decoratorTarget, decoratorArgs) => {
339
- {
342
+ if (process.env.NODE_ENV !== "production") {
340
343
  invariant(!descriptor || !descriptor.get, `@observable cannot be used on getter (property "${stringifyKey(propertyName)}"), use @computed instead.`);
341
344
  }
342
345
  const initialValue = descriptor
@@ -348,7 +351,7 @@ function createDecoratorForEnhancer(enhancer) {
348
351
  });
349
352
  const res =
350
353
  // Extra process checks, as this happens during module initialization
351
- typeof process !== "undefined" && process.env && "development" !== "production"
354
+ typeof process !== "undefined" && process.env && process.env.NODE_ENV !== "production"
352
355
  ? function observableDecorator() {
353
356
  // This wrapper function is just to detect illegal decorator invocations, deprecate in a next version
354
357
  // and simply return the created prop decorator
@@ -379,7 +382,7 @@ function asCreateObservableOptions(thing) {
379
382
  return defaultCreateObservableOptions;
380
383
  if (typeof thing === "string")
381
384
  return { name: thing, deep: true, proxy: true };
382
- {
385
+ if (process.env.NODE_ENV !== "production") {
383
386
  if (typeof thing !== "object")
384
387
  return fail("expected options object");
385
388
  Object.keys(thing).forEach(assertValidOption);
@@ -423,7 +426,8 @@ function createObservable(v, arg2, arg3) {
423
426
  if (res !== v)
424
427
  return res;
425
428
  // otherwise, just box it
426
- 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)'`);
429
+ fail(process.env.NODE_ENV !== "production" &&
430
+ `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)'`);
427
431
  }
428
432
  const observableFactories = {
429
433
  box(value, options) {
@@ -475,7 +479,7 @@ const observable = createObservable;
475
479
  Object.keys(observableFactories).forEach(name => (observable[name] = observableFactories[name]));
476
480
  function incorrectlyUsedAsDecorator(methodName) {
477
481
  fail(
478
- // "development" !== "production" &&
482
+ // process.env.NODE_ENV !== "production" &&
479
483
  `Expected one or two arguments to observable.${methodName}. Did you accidentally try to use observable.${methodName} as decorator?`);
480
484
  }
481
485
 
@@ -503,7 +507,7 @@ const computed = function computed(arg1, arg2, arg3) {
503
507
  return computedDecorator.apply(null, arguments);
504
508
  }
505
509
  // computed(expr, options?)
506
- {
510
+ if (process.env.NODE_ENV !== "production") {
507
511
  invariant(typeof arg1 === "function", "First argument to `computed` should be an expression.");
508
512
  invariant(arguments.length < 3, "Computed takes one or two arguments if used as function");
509
513
  }
@@ -610,7 +614,7 @@ function shouldCompute(derivation) {
610
614
  // function invariantShouldCompute(derivation: IDerivation) {
611
615
  // const newDepState = (derivation as any).dependenciesState
612
616
  // if (
613
- // "development" === "production" &&
617
+ // process.env.NODE_ENV === "production" &&
614
618
  // (newDepState === IDerivationState.POSSIBLY_STALE ||
615
619
  // newDepState === IDerivationState.NOT_TRACKING)
616
620
  // )
@@ -623,16 +627,19 @@ function checkIfStateModificationsAreAllowed(atom) {
623
627
  const hasObservers = atom.observers.size > 0;
624
628
  // Should never be possible to change an observed observable from inside computed, see #798
625
629
  if (globalState.computationDepth > 0 && hasObservers)
626
- fail(`Computed values are not allowed to cause side effects by changing observables that are already being observed. Tried to modify: ${atom.name}`);
630
+ fail(process.env.NODE_ENV !== "production" &&
631
+ `Computed values are not allowed to cause side effects by changing observables that are already being observed. Tried to modify: ${atom.name}`);
627
632
  // Should not be possible to change observed state outside strict mode, except during initialization, see #563
628
633
  if (!globalState.allowStateChanges && (hasObservers || globalState.enforceActions === "strict"))
629
- fail((globalState.enforceActions
634
+ fail(process.env.NODE_ENV !== "production" &&
635
+ (globalState.enforceActions
630
636
  ? "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: "
631
637
  : "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: ") +
632
638
  atom.name);
633
639
  }
634
640
  function checkIfStateReadsAreAllowed(observable) {
635
- if (!globalState.allowStateReads &&
641
+ if (process.env.NODE_ENV !== "production" &&
642
+ !globalState.allowStateReads &&
636
643
  globalState.observableRequiresReaction) {
637
644
  console.warn(`[mobx] Observable ${observable.name} being read outside a reactive context`);
638
645
  }
@@ -671,6 +678,8 @@ function trackDerivedFunction(derivation, f, context) {
671
678
  return result;
672
679
  }
673
680
  function warnAboutDerivationWithoutDependencies(derivation) {
681
+ if (process.env.NODE_ENV === "production")
682
+ return;
674
683
  if (derivation.observing.length !== 0)
675
684
  return;
676
685
  if (globalState.reactionRequiresObservable || derivation.requiresObservable) {
@@ -790,7 +799,7 @@ let nextActionId = 1;
790
799
  const functionNameDescriptor = Object.getOwnPropertyDescriptor(() => { }, "name");
791
800
  const isFunctionNameConfigurable = functionNameDescriptor && functionNameDescriptor.configurable;
792
801
  function createAction(actionName, fn, ref) {
793
- {
802
+ if (process.env.NODE_ENV !== "production") {
794
803
  invariant(typeof fn === "function", "`action` can only be invoked on functions");
795
804
  if (typeof actionName !== "string" || !actionName)
796
805
  fail(`actions should have valid names, got: '${actionName}'`);
@@ -799,7 +808,7 @@ function createAction(actionName, fn, ref) {
799
808
  return executeAction(actionName, fn, ref || this, arguments);
800
809
  };
801
810
  res.isMobxAction = true;
802
- {
811
+ if (process.env.NODE_ENV !== "production") {
803
812
  if (isFunctionNameConfigurable) {
804
813
  Object.defineProperty(res, "name", { value: actionName });
805
814
  }
@@ -822,7 +831,7 @@ function executeAction(actionName, fn, scope, args) {
822
831
  function _startAction(actionName, scope, args) {
823
832
  const notifySpy = isSpyEnabled() && !!actionName;
824
833
  let startTime = 0;
825
- if (notifySpy && "development" !== "production") {
834
+ if (notifySpy && process.env.NODE_ENV !== "production") {
826
835
  startTime = Date.now();
827
836
  const l = (args && args.length) || 0;
828
837
  const flattendArgs = new Array(l);
@@ -864,7 +873,7 @@ function _endAction(runInfo) {
864
873
  allowStateReadsEnd(runInfo.prevAllowStateReads);
865
874
  endBatch();
866
875
  untrackedEnd(runInfo.prevDerivation);
867
- if (runInfo.notifySpy && "development" !== "production") {
876
+ if (runInfo.notifySpy && process.env.NODE_ENV !== "production") {
868
877
  spyReportEnd({ time: Date.now() - runInfo.startTime });
869
878
  }
870
879
  globalState.suppressReactionErrors = false;
@@ -909,7 +918,7 @@ class ObservableValue extends Atom {
909
918
  this.equals = equals;
910
919
  this.hasUnreportedChange = false;
911
920
  this.value = enhancer(value, undefined, name);
912
- if (notifySpy && isSpyEnabled() && "development" !== "production") {
921
+ if (notifySpy && isSpyEnabled() && process.env.NODE_ENV !== "production") {
913
922
  // only notify spy if this is a stand-alone observable
914
923
  spyReport({ type: "create", name: this.name, newValue: "" + this.value });
915
924
  }
@@ -924,7 +933,7 @@ class ObservableValue extends Atom {
924
933
  newValue = this.prepareNewValue(newValue);
925
934
  if (newValue !== globalState.UNCHANGED) {
926
935
  const notifySpy = isSpyEnabled();
927
- if (notifySpy && "development" !== "production") {
936
+ if (notifySpy && process.env.NODE_ENV !== "production") {
928
937
  spyReportStart({
929
938
  type: "update",
930
939
  name: this.name,
@@ -933,7 +942,7 @@ class ObservableValue extends Atom {
933
942
  });
934
943
  }
935
944
  this.setNewValue(newValue);
936
- if (notifySpy && "development" !== "production")
945
+ if (notifySpy && process.env.NODE_ENV !== "production")
937
946
  spyReportEnd();
938
947
  }
939
948
  }
@@ -1118,10 +1127,11 @@ class ComputedValue {
1118
1127
  }
1119
1128
  }
1120
1129
  else
1121
- invariant(false, `[ComputedValue '${this.name}'] It is not possible to assign a new value to a computed value.`);
1130
+ invariant(false, process.env.NODE_ENV !== "production" &&
1131
+ `[ComputedValue '${this.name}'] It is not possible to assign a new value to a computed value.`);
1122
1132
  }
1123
1133
  trackAndCompute() {
1124
- if (isSpyEnabled() && "development" !== "production") {
1134
+ if (isSpyEnabled() && process.env.NODE_ENV !== "production") {
1125
1135
  spyReport({
1126
1136
  object: this.scope,
1127
1137
  type: "compute",
@@ -1191,6 +1201,8 @@ class ComputedValue {
1191
1201
  });
1192
1202
  }
1193
1203
  warnAboutUntrackedRead() {
1204
+ if (process.env.NODE_ENV === "production")
1205
+ return;
1194
1206
  if (this.requiresReaction === true) {
1195
1207
  fail(`[mobx] Computed value ${this.name} is read outside a reactive context`);
1196
1208
  }
@@ -1659,7 +1671,7 @@ class Reaction {
1659
1671
  this.onInvalidate();
1660
1672
  if (this._isTrackPending &&
1661
1673
  isSpyEnabled() &&
1662
- "development" !== "production") {
1674
+ process.env.NODE_ENV !== "production") {
1663
1675
  // onInvalidate didn't trigger track right away..
1664
1676
  spyReport({
1665
1677
  name: this.name,
@@ -1682,7 +1694,7 @@ class Reaction {
1682
1694
  startBatch();
1683
1695
  const notify = isSpyEnabled();
1684
1696
  let startTime;
1685
- if (notify && "development" !== "production") {
1697
+ if (notify && process.env.NODE_ENV !== "production") {
1686
1698
  startTime = Date.now();
1687
1699
  spyReportStart({
1688
1700
  name: this.name,
@@ -1699,7 +1711,7 @@ class Reaction {
1699
1711
  }
1700
1712
  if (isCaughtException(result))
1701
1713
  this.reportExceptionInDerivation(result.cause);
1702
- if (notify && "development" !== "production") {
1714
+ if (notify && process.env.NODE_ENV !== "production") {
1703
1715
  spyReportEnd({
1704
1716
  time: Date.now() - startTime
1705
1717
  });
@@ -1801,9 +1813,11 @@ function setReactionScheduler(fn) {
1801
1813
  }
1802
1814
 
1803
1815
  function isSpyEnabled() {
1804
- return !!globalState.spyListeners.length;
1816
+ return process.env.NODE_ENV !== "production" && !!globalState.spyListeners.length;
1805
1817
  }
1806
1818
  function spyReport(event) {
1819
+ if (process.env.NODE_ENV === "production")
1820
+ return; // dead code elimination can do the rest
1807
1821
  if (!globalState.spyListeners.length)
1808
1822
  return;
1809
1823
  const listeners = globalState.spyListeners;
@@ -1811,18 +1825,26 @@ function spyReport(event) {
1811
1825
  listeners[i](event);
1812
1826
  }
1813
1827
  function spyReportStart(event) {
1828
+ if (process.env.NODE_ENV === "production")
1829
+ return;
1814
1830
  const change = Object.assign(Object.assign({}, event), { spyReportStart: true });
1815
1831
  spyReport(change);
1816
1832
  }
1817
1833
  const END_EVENT = { spyReportEnd: true };
1818
1834
  function spyReportEnd(change) {
1835
+ if (process.env.NODE_ENV === "production")
1836
+ return;
1819
1837
  if (change)
1820
1838
  spyReport(Object.assign(Object.assign({}, change), { spyReportEnd: true }));
1821
1839
  else
1822
1840
  spyReport(END_EVENT);
1823
1841
  }
1824
1842
  function spy(listener) {
1825
- {
1843
+ if (process.env.NODE_ENV === "production") {
1844
+ console.warn(`[mobx.spy] Is a no-op in production builds`);
1845
+ return function () { };
1846
+ }
1847
+ else {
1826
1848
  globalState.spyListeners.push(listener);
1827
1849
  return once(() => {
1828
1850
  globalState.spyListeners = globalState.spyListeners.filter(l => l !== listener);
@@ -1831,12 +1853,12 @@ function spy(listener) {
1831
1853
  }
1832
1854
 
1833
1855
  function dontReassignFields() {
1834
- fail("@action fields are not reassignable");
1856
+ fail(process.env.NODE_ENV !== "production" && "@action fields are not reassignable");
1835
1857
  }
1836
1858
  function namedActionDecorator(name) {
1837
1859
  return function (target, prop, descriptor) {
1838
1860
  if (descriptor) {
1839
- if (descriptor.get !== undefined) {
1861
+ if (process.env.NODE_ENV !== "production" && descriptor.get !== undefined) {
1840
1862
  return fail("@action cannot be used with getters");
1841
1863
  }
1842
1864
  // babel / typescript
@@ -1936,7 +1958,7 @@ action.bound = boundActionDecorator;
1936
1958
  function runInAction(arg1, arg2) {
1937
1959
  const actionName = typeof arg1 === "string" ? arg1 : arg1.name || "<unnamed action>";
1938
1960
  const fn = typeof arg1 === "function" ? arg1 : arg2;
1939
- {
1961
+ if (process.env.NODE_ENV !== "production") {
1940
1962
  invariant(typeof fn === "function" && fn.length === 0, "`runInAction` expects a function without arguments");
1941
1963
  if (typeof actionName !== "string" || !actionName)
1942
1964
  fail(`actions should have valid names, got: '${actionName}'`);
@@ -1957,7 +1979,7 @@ function defineBoundAction(target, propertyName, fn) {
1957
1979
  * @returns disposer function, which can be used to stop the view from being updated in the future.
1958
1980
  */
1959
1981
  function autorun(view, opts = EMPTY_OBJECT) {
1960
- {
1982
+ if (process.env.NODE_ENV !== "production") {
1961
1983
  invariant(typeof view === "function", "Autorun expects a function as first argument");
1962
1984
  invariant(isAction(view) === false, "Autorun does not accept actions since actions are untrackable");
1963
1985
  }
@@ -2000,7 +2022,7 @@ function createSchedulerFromOptions(opts) {
2000
2022
  : run;
2001
2023
  }
2002
2024
  function reaction(expression, effect, opts = EMPTY_OBJECT) {
2003
- {
2025
+ if (process.env.NODE_ENV !== "production") {
2004
2026
  invariant(typeof expression === "function", "First argument to reaction should be a function");
2005
2027
  invariant(typeof opts === "object", "Third argument of reactions should be an object");
2006
2028
  }
@@ -2072,7 +2094,7 @@ function interceptHook(hook, thing, arg2, arg3) {
2072
2094
  }
2073
2095
  const orig = atom[hook];
2074
2096
  if (typeof orig !== "function")
2075
- return fail("Not an atom that can be (un)observed");
2097
+ return fail(process.env.NODE_ENV !== "production" && "Not an atom that can be (un)observed");
2076
2098
  return function () {
2077
2099
  const hookListeners = atom[listenersKey];
2078
2100
  if (hookListeners) {
@@ -2136,14 +2158,16 @@ function configure(options) {
2136
2158
  }
2137
2159
 
2138
2160
  function decorate(thing, decorators) {
2139
- invariant(isPlainObject(decorators), "Decorators should be a key value map");
2161
+ process.env.NODE_ENV !== "production" &&
2162
+ invariant(isPlainObject(decorators), "Decorators should be a key value map");
2140
2163
  const target = typeof thing === "function" ? thing.prototype : thing;
2141
2164
  for (let prop in decorators) {
2142
2165
  let propertyDecorators = decorators[prop];
2143
2166
  if (!Array.isArray(propertyDecorators)) {
2144
2167
  propertyDecorators = [propertyDecorators];
2145
2168
  }
2146
- invariant(propertyDecorators.every(decorator => typeof decorator === "function"), `Decorate: expected a decorator function or array of decorator functions for '${prop}'`);
2169
+ process.env.NODE_ENV !== "production" &&
2170
+ invariant(propertyDecorators.every(decorator => typeof decorator === "function"), `Decorate: expected a decorator function or array of decorator functions for '${prop}'`);
2147
2171
  const descriptor = Object.getOwnPropertyDescriptor(target, prop);
2148
2172
  const newDescriptor = propertyDecorators.reduce((accDescriptor, decorator) => decorator(target, prop, accDescriptor), descriptor);
2149
2173
  if (newDescriptor)
@@ -2153,7 +2177,7 @@ function decorate(thing, decorators) {
2153
2177
  }
2154
2178
 
2155
2179
  function extendObservable(target, properties, decorators, options) {
2156
- {
2180
+ if (process.env.NODE_ENV !== "production") {
2157
2181
  invariant(arguments.length >= 2 && arguments.length <= 4, "'extendObservable' expected 2-4 arguments");
2158
2182
  invariant(typeof target === "object", "'extendObservable' expects an object as first argument");
2159
2183
  invariant(!isObservableMap(target), "'extendObservable' should not be used on maps, use map.merge instead");
@@ -2170,7 +2194,7 @@ function getDefaultDecoratorFromObjectOptions(options) {
2170
2194
  return options.defaultDecorator || (options.deep === false ? refDecorator : deepDecorator);
2171
2195
  }
2172
2196
  function extendObservableObjectWithProperties(target, properties, decorators, defaultDecorator) {
2173
- {
2197
+ if (process.env.NODE_ENV !== "production") {
2174
2198
  invariant(!isObservable(properties), "Extending an object with another observable (object) is not supported. Please construct an explicit propertymap, using `toJS` if need. See issue #540");
2175
2199
  if (decorators) {
2176
2200
  const keys = getPlainObjectKeys(decorators);
@@ -2185,7 +2209,7 @@ function extendObservableObjectWithProperties(target, properties, decorators, de
2185
2209
  const keys = getPlainObjectKeys(properties);
2186
2210
  for (const key of keys) {
2187
2211
  const descriptor = Object.getOwnPropertyDescriptor(properties, key);
2188
- {
2212
+ if (process.env.NODE_ENV !== "production") {
2189
2213
  if (!isPlainObject(properties))
2190
2214
  fail(`'extendObservabe' only accepts plain objects as second argument`);
2191
2215
  if (isComputed(descriptor.value))
@@ -2196,7 +2220,7 @@ function extendObservableObjectWithProperties(target, properties, decorators, de
2196
2220
  : descriptor.get
2197
2221
  ? computedDecorator
2198
2222
  : defaultDecorator;
2199
- if (typeof decorator !== "function")
2223
+ if (process.env.NODE_ENV !== "production" && typeof decorator !== "function")
2200
2224
  fail(`Not a valid decorator for '${stringifyKey(key)}', got: ${decorator}`);
2201
2225
  const resultDescriptor = decorator(target, key, descriptor, true);
2202
2226
  if (resultDescriptor // otherwise, assume already applied, due to `applyToInstance`
@@ -2242,7 +2266,7 @@ function isFlowCancellationError(error) {
2242
2266
  }
2243
2267
  function flow(generator) {
2244
2268
  if (arguments.length !== 1)
2245
- fail(`Flow expects 1 argument and cannot be used as decorator`);
2269
+ fail(!!process.env.NODE_ENV && `Flow expects 1 argument and cannot be used as decorator`);
2246
2270
  const name = generator.name || "<unnamed flow>";
2247
2271
  // Implementation based on https://github.com/tj/co/blob/master/index.js
2248
2272
  return function () {
@@ -2322,14 +2346,16 @@ function interceptReads(thing, propOrHandler, handler) {
2322
2346
  }
2323
2347
  else if (isObservableObject(thing)) {
2324
2348
  if (typeof propOrHandler !== "string")
2325
- return fail(`InterceptReads can only be used with a specific property, not with an object in general`);
2349
+ return fail(process.env.NODE_ENV !== "production" &&
2350
+ `InterceptReads can only be used with a specific property, not with an object in general`);
2326
2351
  target = getAdministration(thing, propOrHandler);
2327
2352
  }
2328
2353
  else {
2329
- return fail(`Expected observable map, object or array as first array`);
2354
+ return fail(process.env.NODE_ENV !== "production" &&
2355
+ `Expected observable map, object or array as first array`);
2330
2356
  }
2331
2357
  if (target.dehancer !== undefined)
2332
- return fail(`An intercept reader was already established`);
2358
+ return fail(process.env.NODE_ENV !== "production" && `An intercept reader was already established`);
2333
2359
  target.dehancer = typeof propOrHandler === "function" ? propOrHandler : handler;
2334
2360
  return () => {
2335
2361
  target.dehancer = undefined;
@@ -2364,12 +2390,14 @@ function _isComputed(value, property) {
2364
2390
  }
2365
2391
  function isComputed(value) {
2366
2392
  if (arguments.length > 1)
2367
- return fail(`isComputed expects only 1 argument. Use isObservableProp to inspect the observability of a property`);
2393
+ return fail(process.env.NODE_ENV !== "production" &&
2394
+ `isComputed expects only 1 argument. Use isObservableProp to inspect the observability of a property`);
2368
2395
  return _isComputed(value);
2369
2396
  }
2370
2397
  function isComputedProp(value, propName) {
2371
2398
  if (typeof propName !== "string")
2372
- return fail(`isComputed expected a property name as second argument`);
2399
+ return fail(process.env.NODE_ENV !== "production" &&
2400
+ `isComputed expected a property name as second argument`);
2373
2401
  return _isComputed(value, propName);
2374
2402
  }
2375
2403
 
@@ -2377,7 +2405,8 @@ function _isObservable(value, property) {
2377
2405
  if (value === null || value === undefined)
2378
2406
  return false;
2379
2407
  if (property !== undefined) {
2380
- if (isObservableMap(value) || isObservableArray(value))
2408
+ if (process.env.NODE_ENV !== "production" &&
2409
+ (isObservableMap(value) || isObservableArray(value)))
2381
2410
  return fail("isObservable(object, propertyName) is not supported for arrays and maps. Use map.has or array.length instead.");
2382
2411
  if (isObservableObject(value)) {
2383
2412
  return value[$mobx].values.has(property);
@@ -2393,12 +2422,13 @@ function _isObservable(value, property) {
2393
2422
  }
2394
2423
  function isObservable(value) {
2395
2424
  if (arguments.length !== 1)
2396
- fail(`isObservable expects only 1 argument. Use isObservableProp to inspect the observability of a property`);
2425
+ fail(process.env.NODE_ENV !== "production" &&
2426
+ `isObservable expects only 1 argument. Use isObservableProp to inspect the observability of a property`);
2397
2427
  return _isObservable(value);
2398
2428
  }
2399
2429
  function isObservableProp(value, propName) {
2400
2430
  if (typeof propName !== "string")
2401
- return fail(`expected a property name as second argument`);
2431
+ return fail(process.env.NODE_ENV !== "production" && `expected a property name as second argument`);
2402
2432
  return _isObservable(value, propName);
2403
2433
  }
2404
2434
 
@@ -2415,7 +2445,8 @@ function keys(obj) {
2415
2445
  if (isObservableArray(obj)) {
2416
2446
  return obj.map((_, index) => index);
2417
2447
  }
2418
- return fail("'keys()' can only be used on observable objects, arrays, sets and maps");
2448
+ return fail(process.env.NODE_ENV !== "production" &&
2449
+ "'keys()' can only be used on observable objects, arrays, sets and maps");
2419
2450
  }
2420
2451
  function values(obj) {
2421
2452
  if (isObservableObject(obj)) {
@@ -2430,7 +2461,8 @@ function values(obj) {
2430
2461
  if (isObservableArray(obj)) {
2431
2462
  return obj.slice();
2432
2463
  }
2433
- return fail("'values()' can only be used on observable objects, arrays, sets and maps");
2464
+ return fail(process.env.NODE_ENV !== "production" &&
2465
+ "'values()' can only be used on observable objects, arrays, sets and maps");
2434
2466
  }
2435
2467
  function entries(obj) {
2436
2468
  if (isObservableObject(obj)) {
@@ -2445,7 +2477,8 @@ function entries(obj) {
2445
2477
  if (isObservableArray(obj)) {
2446
2478
  return obj.map((key, index) => [index, key]);
2447
2479
  }
2448
- return fail("'entries()' can only be used on observable objects, arrays and maps");
2480
+ return fail(process.env.NODE_ENV !== "production" &&
2481
+ "'entries()' can only be used on observable objects, arrays and maps");
2449
2482
  }
2450
2483
  function set(obj, key, value) {
2451
2484
  if (arguments.length === 2 && !isObservableSet(obj)) {
@@ -2487,7 +2520,8 @@ function set(obj, key, value) {
2487
2520
  endBatch();
2488
2521
  }
2489
2522
  else {
2490
- return fail("'set()' can only be used on observable objects, arrays and maps");
2523
+ return fail(process.env.NODE_ENV !== "production" &&
2524
+ "'set()' can only be used on observable objects, arrays and maps");
2491
2525
  }
2492
2526
  }
2493
2527
  function remove(obj, key) {
@@ -2507,7 +2541,8 @@ function remove(obj, key) {
2507
2541
  obj.splice(key, 1);
2508
2542
  }
2509
2543
  else {
2510
- return fail("'remove()' can only be used on observable objects, arrays and maps");
2544
+ return fail(process.env.NODE_ENV !== "production" &&
2545
+ "'remove()' can only be used on observable objects, arrays and maps");
2511
2546
  }
2512
2547
  }
2513
2548
  function has(obj, key) {
@@ -2526,7 +2561,8 @@ function has(obj, key) {
2526
2561
  return key >= 0 && key < obj.length;
2527
2562
  }
2528
2563
  else {
2529
- return fail("'has()' can only be used on observable objects, arrays and maps");
2564
+ return fail(process.env.NODE_ENV !== "production" &&
2565
+ "'has()' can only be used on observable objects, arrays and maps");
2530
2566
  }
2531
2567
  }
2532
2568
  function get(obj, key) {
@@ -2542,7 +2578,8 @@ function get(obj, key) {
2542
2578
  return obj[key];
2543
2579
  }
2544
2580
  else {
2545
- return fail("'get()' can only be used on observable objects, arrays and maps");
2581
+ return fail(process.env.NODE_ENV !== "production" &&
2582
+ "'get()' can only be used on observable objects, arrays and maps");
2546
2583
  }
2547
2584
  }
2548
2585
 
@@ -2658,7 +2695,8 @@ function trace(...args) {
2658
2695
  enterBreakPoint = args.pop();
2659
2696
  const derivation = getAtomFromArgs(args);
2660
2697
  if (!derivation) {
2661
- 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`);
2698
+ return fail(process.env.NODE_ENV !== "production" &&
2699
+ `'trace(break?)' can only be used inside a tracked computed value or a Reaction. Consider passing in the computed value or reaction explicitly`);
2662
2700
  }
2663
2701
  if (derivation.isTracing === TraceMode.NONE) {
2664
2702
  console.log(`[mobx.trace] '${derivation.name}' tracing enabled`);
@@ -2725,7 +2763,7 @@ function _when(predicate, effect, opts) {
2725
2763
  return disposer;
2726
2764
  }
2727
2765
  function whenPromise(predicate, opts) {
2728
- if (opts && opts.onError)
2766
+ if (process.env.NODE_ENV !== "production" && opts && opts.onError)
2729
2767
  return fail(`the options 'onError' and 'promise' cannot be combined`);
2730
2768
  let cancel;
2731
2769
  const res = new Promise((resolve, reject) => {
@@ -3005,7 +3043,7 @@ class ObservableArrayAdministration {
3005
3043
  newItems = change.added;
3006
3044
  }
3007
3045
  newItems = newItems.length === 0 ? newItems : newItems.map(v => this.enhancer(v, undefined));
3008
- {
3046
+ if (process.env.NODE_ENV !== "production") {
3009
3047
  const lengthDelta = newItems.length - deleteCount;
3010
3048
  this.updateArrayLength(length, lengthDelta); // checks if internal array wasn't modified
3011
3049
  }
@@ -3040,12 +3078,12 @@ class ObservableArrayAdministration {
3040
3078
  : null;
3041
3079
  // The reason why this is on right hand side here (and not above), is this way the uglifier will drop it, but it won't
3042
3080
  // cause any runtime overhead in development mode without NODE_ENV set, unless spying is enabled
3043
- if (notifySpy && "development" !== "production")
3081
+ if (notifySpy && process.env.NODE_ENV !== "production")
3044
3082
  spyReportStart(Object.assign(Object.assign({}, change), { name: this.atom.name }));
3045
3083
  this.atom.reportChanged();
3046
3084
  if (notify)
3047
3085
  notifyListeners(this, change);
3048
- if (notifySpy && "development" !== "production")
3086
+ if (notifySpy && process.env.NODE_ENV !== "production")
3049
3087
  spyReportEnd();
3050
3088
  }
3051
3089
  notifyArraySplice(index, added, removed) {
@@ -3062,13 +3100,13 @@ class ObservableArrayAdministration {
3062
3100
  addedCount: added.length
3063
3101
  }
3064
3102
  : null;
3065
- if (notifySpy && "development" !== "production")
3103
+ if (notifySpy && process.env.NODE_ENV !== "production")
3066
3104
  spyReportStart(Object.assign(Object.assign({}, change), { name: this.atom.name }));
3067
3105
  this.atom.reportChanged();
3068
3106
  // conform: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/observe
3069
3107
  if (notify)
3070
3108
  notifyListeners(this, change);
3071
- if (notifySpy && "development" !== "production")
3109
+ if (notifySpy && process.env.NODE_ENV !== "production")
3072
3110
  spyReportEnd();
3073
3111
  }
3074
3112
  }
@@ -3140,7 +3178,7 @@ const arrayExtensions = {
3140
3178
  // reverse by default mutates in place before returning the result
3141
3179
  // which makes it both a 'derivation' and a 'mutation'.
3142
3180
  // so we deviate from the default and just make it an dervitation
3143
- {
3181
+ if (process.env.NODE_ENV !== "production") {
3144
3182
  console.warn("[mobx] `observableArray.reverse()` will not update the array in place. Use `observableArray.slice().reverse()` to suppress this warning and perform the operation on a copy, or `observableArray.replace(observableArray.slice().reverse())` to reverse & update in place");
3145
3183
  }
3146
3184
  const clone = this.slice();
@@ -3149,7 +3187,7 @@ const arrayExtensions = {
3149
3187
  sort(compareFn) {
3150
3188
  // sort by default mutates in place before returning the result
3151
3189
  // which goes against all good practices. Let's not change the array in place!
3152
- {
3190
+ if (process.env.NODE_ENV !== "production") {
3153
3191
  console.warn("[mobx] `observableArray.sort()` will not update the array in place. Use `observableArray.slice().sort()` to suppress this warning and perform the operation on a copy, or `observableArray.replace(observableArray.slice().sort())` to sort & update in place");
3154
3192
  }
3155
3193
  const clone = this.slice();
@@ -3313,7 +3351,7 @@ class ObservableMap {
3313
3351
  name: key
3314
3352
  }
3315
3353
  : null;
3316
- if (notifySpy && "development" !== "production")
3354
+ if (notifySpy && process.env.NODE_ENV !== "production")
3317
3355
  spyReportStart(Object.assign(Object.assign({}, change), { name: this.name, key }));
3318
3356
  transaction(() => {
3319
3357
  this._keysAtom.reportChanged();
@@ -3324,7 +3362,7 @@ class ObservableMap {
3324
3362
  });
3325
3363
  if (notify)
3326
3364
  notifyListeners(this, change);
3327
- if (notifySpy && "development" !== "production")
3365
+ if (notifySpy && process.env.NODE_ENV !== "production")
3328
3366
  spyReportEnd();
3329
3367
  return true;
3330
3368
  }
@@ -3351,12 +3389,12 @@ class ObservableMap {
3351
3389
  newValue
3352
3390
  }
3353
3391
  : null;
3354
- if (notifySpy && "development" !== "production")
3392
+ if (notifySpy && process.env.NODE_ENV !== "production")
3355
3393
  spyReportStart(Object.assign(Object.assign({}, change), { name: this.name, key }));
3356
3394
  observable.setNewValue(newValue);
3357
3395
  if (notify)
3358
3396
  notifyListeners(this, change);
3359
- if (notifySpy && "development" !== "production")
3397
+ if (notifySpy && process.env.NODE_ENV !== "production")
3360
3398
  spyReportEnd();
3361
3399
  }
3362
3400
  }
@@ -3379,11 +3417,11 @@ class ObservableMap {
3379
3417
  newValue
3380
3418
  }
3381
3419
  : null;
3382
- if (notifySpy && "development" !== "production")
3420
+ if (notifySpy && process.env.NODE_ENV !== "production")
3383
3421
  spyReportStart(Object.assign(Object.assign({}, change), { name: this.name, key }));
3384
3422
  if (notify)
3385
3423
  notifyListeners(this, change);
3386
- if (notifySpy && "development" !== "production")
3424
+ if (notifySpy && process.env.NODE_ENV !== "production")
3387
3425
  spyReportEnd();
3388
3426
  }
3389
3427
  get(key) {
@@ -3520,7 +3558,8 @@ class ObservableMap {
3520
3558
  * for callback details
3521
3559
  */
3522
3560
  observe(listener, fireImmediately) {
3523
- invariant(fireImmediately !== true, "`observe` doesn't support fireImmediately=true in combination with maps.");
3561
+ process.env.NODE_ENV !== "production" &&
3562
+ invariant(fireImmediately !== true, "`observe` doesn't support fireImmediately=true in combination with maps.");
3524
3563
  return registerListener(this, listener);
3525
3564
  }
3526
3565
  intercept(handler) {
@@ -3597,11 +3636,11 @@ class ObservableSet {
3597
3636
  newValue: value
3598
3637
  }
3599
3638
  : null;
3600
- if (notifySpy && "development" !== "production")
3639
+ if (notifySpy && process.env.NODE_ENV !== "production")
3601
3640
  spyReportStart(change);
3602
3641
  if (notify)
3603
3642
  notifyListeners(this, change);
3604
- if (notifySpy && "development" !== "production")
3643
+ if (notifySpy && process.env.NODE_ENV !== "production")
3605
3644
  spyReportEnd();
3606
3645
  }
3607
3646
  return this;
@@ -3626,7 +3665,7 @@ class ObservableSet {
3626
3665
  oldValue: value
3627
3666
  }
3628
3667
  : null;
3629
- if (notifySpy && "development" !== "production")
3668
+ if (notifySpy && process.env.NODE_ENV !== "production")
3630
3669
  spyReportStart(Object.assign(Object.assign({}, change), { name: this.name }));
3631
3670
  transaction(() => {
3632
3671
  this._atom.reportChanged();
@@ -3634,7 +3673,7 @@ class ObservableSet {
3634
3673
  });
3635
3674
  if (notify)
3636
3675
  notifyListeners(this, change);
3637
- if (notifySpy && "development" !== "production")
3676
+ if (notifySpy && process.env.NODE_ENV !== "production")
3638
3677
  spyReportEnd();
3639
3678
  return true;
3640
3679
  }
@@ -3695,7 +3734,8 @@ class ObservableSet {
3695
3734
  }
3696
3735
  observe(listener, fireImmediately) {
3697
3736
  // TODO 'fireImmediately' can be true?
3698
- invariant(fireImmediately !== true, "`observe` doesn't support fireImmediately=true in combination with sets.");
3737
+ process.env.NODE_ENV !== "production" &&
3738
+ invariant(fireImmediately !== true, "`observe` doesn't support fireImmediately=true in combination with sets.");
3699
3739
  return registerListener(this, listener);
3700
3740
  }
3701
3741
  intercept(handler) {
@@ -3757,12 +3797,12 @@ class ObservableObjectAdministration {
3757
3797
  newValue
3758
3798
  }
3759
3799
  : null;
3760
- if (notifySpy && "development" !== "production")
3800
+ if (notifySpy && process.env.NODE_ENV !== "production")
3761
3801
  spyReportStart(Object.assign(Object.assign({}, change), { name: this.name, key }));
3762
3802
  observable.setNewValue(newValue);
3763
3803
  if (notify)
3764
3804
  notifyListeners(this, change);
3765
- if (notifySpy && "development" !== "production")
3805
+ if (notifySpy && process.env.NODE_ENV !== "production")
3766
3806
  spyReportEnd();
3767
3807
  }
3768
3808
  }
@@ -3846,11 +3886,11 @@ class ObservableObjectAdministration {
3846
3886
  name: key
3847
3887
  }
3848
3888
  : null;
3849
- if (notifySpy && "development" !== "production")
3889
+ if (notifySpy && process.env.NODE_ENV !== "production")
3850
3890
  spyReportStart(Object.assign(Object.assign({}, change), { name: this.name, key }));
3851
3891
  if (notify)
3852
3892
  notifyListeners(this, change);
3853
- if (notifySpy && "development" !== "production")
3893
+ if (notifySpy && process.env.NODE_ENV !== "production")
3854
3894
  spyReportEnd();
3855
3895
  }
3856
3896
  finally {
@@ -3885,7 +3925,8 @@ class ObservableObjectAdministration {
3885
3925
  * for callback details
3886
3926
  */
3887
3927
  observe(callback, fireImmediately) {
3888
- invariant(fireImmediately !== true, "`observe` doesn't support the fire immediately property for observable objects.");
3928
+ process.env.NODE_ENV !== "production" &&
3929
+ invariant(fireImmediately !== true, "`observe` doesn't support the fire immediately property for observable objects.");
3889
3930
  return registerListener(this, callback);
3890
3931
  }
3891
3932
  intercept(handler) {
@@ -3902,11 +3943,11 @@ class ObservableObjectAdministration {
3902
3943
  newValue
3903
3944
  }
3904
3945
  : null;
3905
- if (notifySpy && "development" !== "production")
3946
+ if (notifySpy && process.env.NODE_ENV !== "production")
3906
3947
  spyReportStart(Object.assign(Object.assign({}, change), { name: this.name, key }));
3907
3948
  if (notify)
3908
3949
  notifyListeners(this, change);
3909
- if (notifySpy && "development" !== "production")
3950
+ if (notifySpy && process.env.NODE_ENV !== "production")
3910
3951
  spyReportEnd();
3911
3952
  if (this.pendingKeys) {
3912
3953
  const entry = this.pendingKeys.get(key);
@@ -3928,7 +3969,8 @@ class ObservableObjectAdministration {
3928
3969
  function asObservableObject(target, name = "", defaultEnhancer = deepEnhancer) {
3929
3970
  if (Object.prototype.hasOwnProperty.call(target, $mobx))
3930
3971
  return target[$mobx];
3931
- invariant(Object.isExtensible(target), "Cannot make the designated object observable; it is not extensible");
3972
+ process.env.NODE_ENV !== "production" &&
3973
+ invariant(Object.isExtensible(target), "Cannot make the designated object observable; it is not extensible");
3932
3974
  if (!isPlainObject(target))
3933
3975
  name = (target.constructor.name || "ObservableObject") + "@" + getNextId();
3934
3976
  if (!name)
@@ -3989,7 +4031,8 @@ function getAtom(thing, property) {
3989
4031
  if (typeof thing === "object" && thing !== null) {
3990
4032
  if (isObservableArray(thing)) {
3991
4033
  if (property !== undefined)
3992
- fail("It is not possible to get index atoms from arrays");
4034
+ fail(process.env.NODE_ENV !== "production" &&
4035
+ "It is not possible to get index atoms from arrays");
3993
4036
  return thing[$mobx].atom;
3994
4037
  }
3995
4038
  if (isObservableSet(thing)) {
@@ -4001,7 +4044,8 @@ function getAtom(thing, property) {
4001
4044
  return anyThing._keysAtom;
4002
4045
  const observable = anyThing._data.get(property) || anyThing._hasMap.get(property);
4003
4046
  if (!observable)
4004
- fail(`the entry '${property}' does not exist in the observable map '${getDebugName(thing)}'`);
4047
+ fail(process.env.NODE_ENV !== "production" &&
4048
+ `the entry '${property}' does not exist in the observable map '${getDebugName(thing)}'`);
4005
4049
  return observable;
4006
4050
  }
4007
4051
  // Initializers run lazily when transpiling to babel, so make sure they are run...
@@ -4010,10 +4054,11 @@ function getAtom(thing, property) {
4010
4054
  thing[property]; // See #1072
4011
4055
  if (isObservableObject(thing)) {
4012
4056
  if (!property)
4013
- return fail(`please specify a property`);
4057
+ return fail(process.env.NODE_ENV !== "production" && `please specify a property`);
4014
4058
  const observable = thing[$mobx].values.get(property);
4015
4059
  if (!observable)
4016
- fail(`no observable property '${property}' found on the observable object '${getDebugName(thing)}'`);
4060
+ fail(process.env.NODE_ENV !== "production" &&
4061
+ `no observable property '${property}' found on the observable object '${getDebugName(thing)}'`);
4017
4062
  return observable;
4018
4063
  }
4019
4064
  if (isAtom(thing) || isComputedValue(thing) || isReaction(thing)) {
@@ -4026,7 +4071,7 @@ function getAtom(thing, property) {
4026
4071
  return thing[$mobx];
4027
4072
  }
4028
4073
  }
4029
- return fail("Cannot obtain atom from " + thing);
4074
+ return fail(process.env.NODE_ENV !== "production" && "Cannot obtain atom from " + thing);
4030
4075
  }
4031
4076
  function getAdministration(thing, property) {
4032
4077
  if (!thing)
@@ -4041,7 +4086,7 @@ function getAdministration(thing, property) {
4041
4086
  initializeInstance(thing);
4042
4087
  if (thing[$mobx])
4043
4088
  return thing[$mobx];
4044
- fail("Cannot obtain administration from " + thing);
4089
+ fail(process.env.NODE_ENV !== "production" && "Cannot obtain administration from " + thing);
4045
4090
  }
4046
4091
  function getDebugName(thing, property) {
4047
4092
  let named;
@@ -4234,6 +4279,10 @@ if (typeof Proxy === "undefined" || typeof Symbol === "undefined") {
4234
4279
  throw new Error("[mobx] MobX 5+ requires Proxy and Symbol objects. If your environment doesn't support Symbol or Proxy objects, please downgrade to MobX 4. For React Native Android, consider upgrading JSCore.");
4235
4280
  }
4236
4281
  try {
4282
+ // define process.env if needed
4283
+ // if this is not a production build in the first place
4284
+ // (in which case the expression below would be substituted with 'production')
4285
+ process.env.NODE_ENV;
4237
4286
  }
4238
4287
  catch (e) {
4239
4288
  const g = getGlobal();
@@ -4244,8 +4293,8 @@ catch (e) {
4244
4293
  (() => {
4245
4294
  function testCodeMinification() { }
4246
4295
  if (testCodeMinification.name !== "testCodeMinification" &&
4247
- "development" !== "production" &&
4248
- process.env.IGNORE_MOBX_MINIFY_WARNING !== "true") {
4296
+ process.env.NODE_ENV !== "production" &&
4297
+ typeof process !== 'undefined' && process.env.IGNORE_MOBX_MINIFY_WARNING !== "true") {
4249
4298
  // trick so it doesn't get replaced
4250
4299
  const varName = ["process", "env", "NODE_ENV"].join(".");
4251
4300
  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`);