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/CHANGELOG.md +4 -0
- package/lib/index.js +7 -0
- package/lib/mobx.es6.js +142 -93
- package/lib/mobx.js +1 -1
- package/lib/mobx.module.js +142 -93
- package/lib/mobx.umd.js +142 -93
- package/package.json +3 -3
package/lib/mobx.module.js
CHANGED
|
@@ -95,6 +95,8 @@ function invariant(check, message) {
|
|
|
95
95
|
*/
|
|
96
96
|
var deprecatedMessages = [];
|
|
97
97
|
function deprecated(msg, thing) {
|
|
98
|
+
if (process.env.NODE_ENV === "production")
|
|
99
|
+
return false;
|
|
98
100
|
if (thing) {
|
|
99
101
|
return deprecated("'" + msg + "', use '" + thing + "' instead.");
|
|
100
102
|
}
|
|
@@ -155,7 +157,7 @@ function isPropertyConfigurable(object, prop) {
|
|
|
155
157
|
return !descriptor || (descriptor.configurable !== false && descriptor.writable !== false);
|
|
156
158
|
}
|
|
157
159
|
function assertPropertyConfigurable(object, prop) {
|
|
158
|
-
if (!isPropertyConfigurable(object, prop))
|
|
160
|
+
if (process.env.NODE_ENV !== "production" && !isPropertyConfigurable(object, prop))
|
|
159
161
|
fail("Cannot make property '" + prop.toString() + "' observable, it is not configurable and writable in the target object");
|
|
160
162
|
}
|
|
161
163
|
function createInstanceofPredicate(name, clazz) {
|
|
@@ -350,7 +352,7 @@ function createPropDecorator(propertyInitiallyEnumerable, propertyCreator) {
|
|
|
350
352
|
propertyCreator(target, prop, descriptor, target, decoratorArguments);
|
|
351
353
|
return null;
|
|
352
354
|
}
|
|
353
|
-
if (!quacksLikeADecorator(arguments))
|
|
355
|
+
if (process.env.NODE_ENV !== "production" && !quacksLikeADecorator(arguments))
|
|
354
356
|
fail("This function is a decorator, but it wasn't invoked like a decorator");
|
|
355
357
|
if (!Object.prototype.hasOwnProperty.call(target, mobxPendingDecorators)) {
|
|
356
358
|
var inheritedDecorators = target[mobxPendingDecorators];
|
|
@@ -411,14 +413,15 @@ function shallowEnhancer(v, _, name) {
|
|
|
411
413
|
return observable.map(v, { name: name, deep: false });
|
|
412
414
|
if (isES6Set(v))
|
|
413
415
|
return observable.set(v, { name: name, deep: false });
|
|
414
|
-
return fail(
|
|
416
|
+
return fail(process.env.NODE_ENV !== "production" &&
|
|
417
|
+
"The shallow modifier / decorator can only used in combination with arrays, objects, maps and sets");
|
|
415
418
|
}
|
|
416
419
|
function referenceEnhancer(newValue) {
|
|
417
420
|
// never turn into an observable
|
|
418
421
|
return newValue;
|
|
419
422
|
}
|
|
420
423
|
function refStructEnhancer(v, oldValue, name) {
|
|
421
|
-
if (isObservable(v))
|
|
424
|
+
if (process.env.NODE_ENV !== "production" && isObservable(v))
|
|
422
425
|
throw "observable.struct should not be used with observable values";
|
|
423
426
|
if (deepEqual(v, oldValue))
|
|
424
427
|
return oldValue;
|
|
@@ -428,7 +431,7 @@ function refStructEnhancer(v, oldValue, name) {
|
|
|
428
431
|
function createDecoratorForEnhancer(enhancer) {
|
|
429
432
|
invariant(enhancer);
|
|
430
433
|
var decorator = createPropDecorator(true, function (target, propertyName, descriptor, _decoratorTarget, decoratorArgs) {
|
|
431
|
-
{
|
|
434
|
+
if (process.env.NODE_ENV !== "production") {
|
|
432
435
|
invariant(!descriptor || !descriptor.get, "@observable cannot be used on getter (property \"" + stringifyKey(propertyName) + "\"), use @computed instead.");
|
|
433
436
|
}
|
|
434
437
|
var initialValue = descriptor
|
|
@@ -440,7 +443,7 @@ function createDecoratorForEnhancer(enhancer) {
|
|
|
440
443
|
});
|
|
441
444
|
var res =
|
|
442
445
|
// Extra process checks, as this happens during module initialization
|
|
443
|
-
typeof process !== "undefined" && process.env &&
|
|
446
|
+
typeof process !== "undefined" && process.env && process.env.NODE_ENV !== "production"
|
|
444
447
|
? function observableDecorator() {
|
|
445
448
|
// This wrapper function is just to detect illegal decorator invocations, deprecate in a next version
|
|
446
449
|
// and simply return the created prop decorator
|
|
@@ -471,7 +474,7 @@ function asCreateObservableOptions(thing) {
|
|
|
471
474
|
return defaultCreateObservableOptions;
|
|
472
475
|
if (typeof thing === "string")
|
|
473
476
|
return { name: thing, deep: true, proxy: true };
|
|
474
|
-
{
|
|
477
|
+
if (process.env.NODE_ENV !== "production") {
|
|
475
478
|
if (typeof thing !== "object")
|
|
476
479
|
return fail("expected options object");
|
|
477
480
|
Object.keys(thing).forEach(assertValidOption);
|
|
@@ -515,7 +518,8 @@ function createObservable(v, arg2, arg3) {
|
|
|
515
518
|
if (res !== v)
|
|
516
519
|
return res;
|
|
517
520
|
// otherwise, just box it
|
|
518
|
-
fail(
|
|
521
|
+
fail(process.env.NODE_ENV !== "production" &&
|
|
522
|
+
"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)'");
|
|
519
523
|
}
|
|
520
524
|
var observableFactories = {
|
|
521
525
|
box: function (value, options) {
|
|
@@ -567,7 +571,7 @@ var observable = createObservable;
|
|
|
567
571
|
Object.keys(observableFactories).forEach(function (name) { return (observable[name] = observableFactories[name]); });
|
|
568
572
|
function incorrectlyUsedAsDecorator(methodName) {
|
|
569
573
|
fail(
|
|
570
|
-
//
|
|
574
|
+
// process.env.NODE_ENV !== "production" &&
|
|
571
575
|
"Expected one or two arguments to observable." + methodName + ". Did you accidentally try to use observable." + methodName + " as decorator?");
|
|
572
576
|
}
|
|
573
577
|
|
|
@@ -595,7 +599,7 @@ var computed = function computed(arg1, arg2, arg3) {
|
|
|
595
599
|
return computedDecorator.apply(null, arguments);
|
|
596
600
|
}
|
|
597
601
|
// computed(expr, options?)
|
|
598
|
-
{
|
|
602
|
+
if (process.env.NODE_ENV !== "production") {
|
|
599
603
|
invariant(typeof arg1 === "function", "First argument to `computed` should be an expression.");
|
|
600
604
|
invariant(arguments.length < 3, "Computed takes one or two arguments if used as function");
|
|
601
605
|
}
|
|
@@ -703,7 +707,7 @@ function shouldCompute(derivation) {
|
|
|
703
707
|
// function invariantShouldCompute(derivation: IDerivation) {
|
|
704
708
|
// const newDepState = (derivation as any).dependenciesState
|
|
705
709
|
// if (
|
|
706
|
-
//
|
|
710
|
+
// process.env.NODE_ENV === "production" &&
|
|
707
711
|
// (newDepState === IDerivationState.POSSIBLY_STALE ||
|
|
708
712
|
// newDepState === IDerivationState.NOT_TRACKING)
|
|
709
713
|
// )
|
|
@@ -716,16 +720,19 @@ function checkIfStateModificationsAreAllowed(atom) {
|
|
|
716
720
|
var hasObservers = atom.observers.size > 0;
|
|
717
721
|
// Should never be possible to change an observed observable from inside computed, see #798
|
|
718
722
|
if (globalState.computationDepth > 0 && hasObservers)
|
|
719
|
-
fail(
|
|
723
|
+
fail(process.env.NODE_ENV !== "production" &&
|
|
724
|
+
"Computed values are not allowed to cause side effects by changing observables that are already being observed. Tried to modify: " + atom.name);
|
|
720
725
|
// Should not be possible to change observed state outside strict mode, except during initialization, see #563
|
|
721
726
|
if (!globalState.allowStateChanges && (hasObservers || globalState.enforceActions === "strict"))
|
|
722
|
-
fail(
|
|
727
|
+
fail(process.env.NODE_ENV !== "production" &&
|
|
728
|
+
(globalState.enforceActions
|
|
723
729
|
? "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: "
|
|
724
730
|
: "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: ") +
|
|
725
731
|
atom.name);
|
|
726
732
|
}
|
|
727
733
|
function checkIfStateReadsAreAllowed(observable) {
|
|
728
|
-
if (
|
|
734
|
+
if (process.env.NODE_ENV !== "production" &&
|
|
735
|
+
!globalState.allowStateReads &&
|
|
729
736
|
globalState.observableRequiresReaction) {
|
|
730
737
|
console.warn("[mobx] Observable " + observable.name + " being read outside a reactive context");
|
|
731
738
|
}
|
|
@@ -764,6 +771,8 @@ function trackDerivedFunction(derivation, f, context) {
|
|
|
764
771
|
return result;
|
|
765
772
|
}
|
|
766
773
|
function warnAboutDerivationWithoutDependencies(derivation) {
|
|
774
|
+
if (process.env.NODE_ENV === "production")
|
|
775
|
+
return;
|
|
767
776
|
if (derivation.observing.length !== 0)
|
|
768
777
|
return;
|
|
769
778
|
if (globalState.reactionRequiresObservable || derivation.requiresObservable) {
|
|
@@ -883,7 +892,7 @@ var nextActionId = 1;
|
|
|
883
892
|
var functionNameDescriptor = Object.getOwnPropertyDescriptor(function () { }, "name");
|
|
884
893
|
var isFunctionNameConfigurable = functionNameDescriptor && functionNameDescriptor.configurable;
|
|
885
894
|
function createAction(actionName, fn, ref) {
|
|
886
|
-
{
|
|
895
|
+
if (process.env.NODE_ENV !== "production") {
|
|
887
896
|
invariant(typeof fn === "function", "`action` can only be invoked on functions");
|
|
888
897
|
if (typeof actionName !== "string" || !actionName)
|
|
889
898
|
fail("actions should have valid names, got: '" + actionName + "'");
|
|
@@ -892,7 +901,7 @@ function createAction(actionName, fn, ref) {
|
|
|
892
901
|
return executeAction(actionName, fn, ref || this, arguments);
|
|
893
902
|
};
|
|
894
903
|
res.isMobxAction = true;
|
|
895
|
-
{
|
|
904
|
+
if (process.env.NODE_ENV !== "production") {
|
|
896
905
|
if (isFunctionNameConfigurable) {
|
|
897
906
|
Object.defineProperty(res, "name", { value: actionName });
|
|
898
907
|
}
|
|
@@ -915,7 +924,7 @@ function executeAction(actionName, fn, scope, args) {
|
|
|
915
924
|
function _startAction(actionName, scope, args) {
|
|
916
925
|
var notifySpy = isSpyEnabled() && !!actionName;
|
|
917
926
|
var startTime = 0;
|
|
918
|
-
if (notifySpy &&
|
|
927
|
+
if (notifySpy && process.env.NODE_ENV !== "production") {
|
|
919
928
|
startTime = Date.now();
|
|
920
929
|
var l = (args && args.length) || 0;
|
|
921
930
|
var flattendArgs = new Array(l);
|
|
@@ -957,7 +966,7 @@ function _endAction(runInfo) {
|
|
|
957
966
|
allowStateReadsEnd(runInfo.prevAllowStateReads);
|
|
958
967
|
endBatch();
|
|
959
968
|
untrackedEnd(runInfo.prevDerivation);
|
|
960
|
-
if (runInfo.notifySpy &&
|
|
969
|
+
if (runInfo.notifySpy && process.env.NODE_ENV !== "production") {
|
|
961
970
|
spyReportEnd({ time: Date.now() - runInfo.startTime });
|
|
962
971
|
}
|
|
963
972
|
globalState.suppressReactionErrors = false;
|
|
@@ -1006,7 +1015,7 @@ var ObservableValue = /** @class */ (function (_super) {
|
|
|
1006
1015
|
_this.equals = equals;
|
|
1007
1016
|
_this.hasUnreportedChange = false;
|
|
1008
1017
|
_this.value = enhancer(value, undefined, name);
|
|
1009
|
-
if (notifySpy && isSpyEnabled() &&
|
|
1018
|
+
if (notifySpy && isSpyEnabled() && process.env.NODE_ENV !== "production") {
|
|
1010
1019
|
// only notify spy if this is a stand-alone observable
|
|
1011
1020
|
spyReport({ type: "create", name: _this.name, newValue: "" + _this.value });
|
|
1012
1021
|
}
|
|
@@ -1022,7 +1031,7 @@ var ObservableValue = /** @class */ (function (_super) {
|
|
|
1022
1031
|
newValue = this.prepareNewValue(newValue);
|
|
1023
1032
|
if (newValue !== globalState.UNCHANGED) {
|
|
1024
1033
|
var notifySpy = isSpyEnabled();
|
|
1025
|
-
if (notifySpy &&
|
|
1034
|
+
if (notifySpy && process.env.NODE_ENV !== "production") {
|
|
1026
1035
|
spyReportStart({
|
|
1027
1036
|
type: "update",
|
|
1028
1037
|
name: this.name,
|
|
@@ -1031,7 +1040,7 @@ var ObservableValue = /** @class */ (function (_super) {
|
|
|
1031
1040
|
});
|
|
1032
1041
|
}
|
|
1033
1042
|
this.setNewValue(newValue);
|
|
1034
|
-
if (notifySpy &&
|
|
1043
|
+
if (notifySpy && process.env.NODE_ENV !== "production")
|
|
1035
1044
|
spyReportEnd();
|
|
1036
1045
|
}
|
|
1037
1046
|
};
|
|
@@ -1217,10 +1226,11 @@ var ComputedValue = /** @class */ (function () {
|
|
|
1217
1226
|
}
|
|
1218
1227
|
}
|
|
1219
1228
|
else
|
|
1220
|
-
invariant(false,
|
|
1229
|
+
invariant(false, process.env.NODE_ENV !== "production" &&
|
|
1230
|
+
"[ComputedValue '" + this.name + "'] It is not possible to assign a new value to a computed value.");
|
|
1221
1231
|
};
|
|
1222
1232
|
ComputedValue.prototype.trackAndCompute = function () {
|
|
1223
|
-
if (isSpyEnabled() &&
|
|
1233
|
+
if (isSpyEnabled() && process.env.NODE_ENV !== "production") {
|
|
1224
1234
|
spyReport({
|
|
1225
1235
|
object: this.scope,
|
|
1226
1236
|
type: "compute",
|
|
@@ -1291,6 +1301,8 @@ var ComputedValue = /** @class */ (function () {
|
|
|
1291
1301
|
});
|
|
1292
1302
|
};
|
|
1293
1303
|
ComputedValue.prototype.warnAboutUntrackedRead = function () {
|
|
1304
|
+
if (process.env.NODE_ENV === "production")
|
|
1305
|
+
return;
|
|
1294
1306
|
if (this.requiresReaction === true) {
|
|
1295
1307
|
fail("[mobx] Computed value " + this.name + " is read outside a reactive context");
|
|
1296
1308
|
}
|
|
@@ -1749,7 +1761,7 @@ var Reaction = /** @class */ (function () {
|
|
|
1749
1761
|
this.onInvalidate();
|
|
1750
1762
|
if (this._isTrackPending &&
|
|
1751
1763
|
isSpyEnabled() &&
|
|
1752
|
-
|
|
1764
|
+
process.env.NODE_ENV !== "production") {
|
|
1753
1765
|
// onInvalidate didn't trigger track right away..
|
|
1754
1766
|
spyReport({
|
|
1755
1767
|
name: this.name,
|
|
@@ -1772,7 +1784,7 @@ var Reaction = /** @class */ (function () {
|
|
|
1772
1784
|
startBatch();
|
|
1773
1785
|
var notify = isSpyEnabled();
|
|
1774
1786
|
var startTime;
|
|
1775
|
-
if (notify &&
|
|
1787
|
+
if (notify && process.env.NODE_ENV !== "production") {
|
|
1776
1788
|
startTime = Date.now();
|
|
1777
1789
|
spyReportStart({
|
|
1778
1790
|
name: this.name,
|
|
@@ -1789,7 +1801,7 @@ var Reaction = /** @class */ (function () {
|
|
|
1789
1801
|
}
|
|
1790
1802
|
if (isCaughtException(result))
|
|
1791
1803
|
this.reportExceptionInDerivation(result.cause);
|
|
1792
|
-
if (notify &&
|
|
1804
|
+
if (notify && process.env.NODE_ENV !== "production") {
|
|
1793
1805
|
spyReportEnd({
|
|
1794
1806
|
time: Date.now() - startTime
|
|
1795
1807
|
});
|
|
@@ -1894,9 +1906,11 @@ function setReactionScheduler(fn) {
|
|
|
1894
1906
|
}
|
|
1895
1907
|
|
|
1896
1908
|
function isSpyEnabled() {
|
|
1897
|
-
return !!globalState.spyListeners.length;
|
|
1909
|
+
return process.env.NODE_ENV !== "production" && !!globalState.spyListeners.length;
|
|
1898
1910
|
}
|
|
1899
1911
|
function spyReport(event) {
|
|
1912
|
+
if (process.env.NODE_ENV === "production")
|
|
1913
|
+
return; // dead code elimination can do the rest
|
|
1900
1914
|
if (!globalState.spyListeners.length)
|
|
1901
1915
|
return;
|
|
1902
1916
|
var listeners = globalState.spyListeners;
|
|
@@ -1904,18 +1918,26 @@ function spyReport(event) {
|
|
|
1904
1918
|
listeners[i](event);
|
|
1905
1919
|
}
|
|
1906
1920
|
function spyReportStart(event) {
|
|
1921
|
+
if (process.env.NODE_ENV === "production")
|
|
1922
|
+
return;
|
|
1907
1923
|
var change = __assign(__assign({}, event), { spyReportStart: true });
|
|
1908
1924
|
spyReport(change);
|
|
1909
1925
|
}
|
|
1910
1926
|
var END_EVENT = { spyReportEnd: true };
|
|
1911
1927
|
function spyReportEnd(change) {
|
|
1928
|
+
if (process.env.NODE_ENV === "production")
|
|
1929
|
+
return;
|
|
1912
1930
|
if (change)
|
|
1913
1931
|
spyReport(__assign(__assign({}, change), { spyReportEnd: true }));
|
|
1914
1932
|
else
|
|
1915
1933
|
spyReport(END_EVENT);
|
|
1916
1934
|
}
|
|
1917
1935
|
function spy(listener) {
|
|
1918
|
-
{
|
|
1936
|
+
if (process.env.NODE_ENV === "production") {
|
|
1937
|
+
console.warn("[mobx.spy] Is a no-op in production builds");
|
|
1938
|
+
return function () { };
|
|
1939
|
+
}
|
|
1940
|
+
else {
|
|
1919
1941
|
globalState.spyListeners.push(listener);
|
|
1920
1942
|
return once(function () {
|
|
1921
1943
|
globalState.spyListeners = globalState.spyListeners.filter(function (l) { return l !== listener; });
|
|
@@ -1924,12 +1946,12 @@ function spy(listener) {
|
|
|
1924
1946
|
}
|
|
1925
1947
|
|
|
1926
1948
|
function dontReassignFields() {
|
|
1927
|
-
fail("@action fields are not reassignable");
|
|
1949
|
+
fail(process.env.NODE_ENV !== "production" && "@action fields are not reassignable");
|
|
1928
1950
|
}
|
|
1929
1951
|
function namedActionDecorator(name) {
|
|
1930
1952
|
return function (target, prop, descriptor) {
|
|
1931
1953
|
if (descriptor) {
|
|
1932
|
-
if (descriptor.get !== undefined) {
|
|
1954
|
+
if (process.env.NODE_ENV !== "production" && descriptor.get !== undefined) {
|
|
1933
1955
|
return fail("@action cannot be used with getters");
|
|
1934
1956
|
}
|
|
1935
1957
|
// babel / typescript
|
|
@@ -2029,7 +2051,7 @@ action.bound = boundActionDecorator;
|
|
|
2029
2051
|
function runInAction(arg1, arg2) {
|
|
2030
2052
|
var actionName = typeof arg1 === "string" ? arg1 : arg1.name || "<unnamed action>";
|
|
2031
2053
|
var fn = typeof arg1 === "function" ? arg1 : arg2;
|
|
2032
|
-
{
|
|
2054
|
+
if (process.env.NODE_ENV !== "production") {
|
|
2033
2055
|
invariant(typeof fn === "function" && fn.length === 0, "`runInAction` expects a function without arguments");
|
|
2034
2056
|
if (typeof actionName !== "string" || !actionName)
|
|
2035
2057
|
fail("actions should have valid names, got: '" + actionName + "'");
|
|
@@ -2051,7 +2073,7 @@ function defineBoundAction(target, propertyName, fn) {
|
|
|
2051
2073
|
*/
|
|
2052
2074
|
function autorun(view, opts) {
|
|
2053
2075
|
if (opts === void 0) { opts = EMPTY_OBJECT; }
|
|
2054
|
-
{
|
|
2076
|
+
if (process.env.NODE_ENV !== "production") {
|
|
2055
2077
|
invariant(typeof view === "function", "Autorun expects a function as first argument");
|
|
2056
2078
|
invariant(isAction(view) === false, "Autorun does not accept actions since actions are untrackable");
|
|
2057
2079
|
}
|
|
@@ -2095,7 +2117,7 @@ function createSchedulerFromOptions(opts) {
|
|
|
2095
2117
|
}
|
|
2096
2118
|
function reaction(expression, effect, opts) {
|
|
2097
2119
|
if (opts === void 0) { opts = EMPTY_OBJECT; }
|
|
2098
|
-
{
|
|
2120
|
+
if (process.env.NODE_ENV !== "production") {
|
|
2099
2121
|
invariant(typeof expression === "function", "First argument to reaction should be a function");
|
|
2100
2122
|
invariant(typeof opts === "object", "Third argument of reactions should be an object");
|
|
2101
2123
|
}
|
|
@@ -2167,7 +2189,7 @@ function interceptHook(hook, thing, arg2, arg3) {
|
|
|
2167
2189
|
}
|
|
2168
2190
|
var orig = atom[hook];
|
|
2169
2191
|
if (typeof orig !== "function")
|
|
2170
|
-
return fail("Not an atom that can be (un)observed");
|
|
2192
|
+
return fail(process.env.NODE_ENV !== "production" && "Not an atom that can be (un)observed");
|
|
2171
2193
|
return function () {
|
|
2172
2194
|
var hookListeners = atom[listenersKey];
|
|
2173
2195
|
if (hookListeners) {
|
|
@@ -2231,14 +2253,16 @@ function configure(options) {
|
|
|
2231
2253
|
}
|
|
2232
2254
|
|
|
2233
2255
|
function decorate(thing, decorators) {
|
|
2234
|
-
|
|
2256
|
+
process.env.NODE_ENV !== "production" &&
|
|
2257
|
+
invariant(isPlainObject(decorators), "Decorators should be a key value map");
|
|
2235
2258
|
var target = typeof thing === "function" ? thing.prototype : thing;
|
|
2236
2259
|
var _loop_1 = function (prop) {
|
|
2237
2260
|
var propertyDecorators = decorators[prop];
|
|
2238
2261
|
if (!Array.isArray(propertyDecorators)) {
|
|
2239
2262
|
propertyDecorators = [propertyDecorators];
|
|
2240
2263
|
}
|
|
2241
|
-
|
|
2264
|
+
process.env.NODE_ENV !== "production" &&
|
|
2265
|
+
invariant(propertyDecorators.every(function (decorator) { return typeof decorator === "function"; }), "Decorate: expected a decorator function or array of decorator functions for '" + prop + "'");
|
|
2242
2266
|
var descriptor = Object.getOwnPropertyDescriptor(target, prop);
|
|
2243
2267
|
var newDescriptor = propertyDecorators.reduce(function (accDescriptor, decorator) { return decorator(target, prop, accDescriptor); }, descriptor);
|
|
2244
2268
|
if (newDescriptor)
|
|
@@ -2251,7 +2275,7 @@ function decorate(thing, decorators) {
|
|
|
2251
2275
|
}
|
|
2252
2276
|
|
|
2253
2277
|
function extendObservable(target, properties, decorators, options) {
|
|
2254
|
-
{
|
|
2278
|
+
if (process.env.NODE_ENV !== "production") {
|
|
2255
2279
|
invariant(arguments.length >= 2 && arguments.length <= 4, "'extendObservable' expected 2-4 arguments");
|
|
2256
2280
|
invariant(typeof target === "object", "'extendObservable' expects an object as first argument");
|
|
2257
2281
|
invariant(!isObservableMap(target), "'extendObservable' should not be used on maps, use map.merge instead");
|
|
@@ -2269,7 +2293,7 @@ function getDefaultDecoratorFromObjectOptions(options) {
|
|
|
2269
2293
|
}
|
|
2270
2294
|
function extendObservableObjectWithProperties(target, properties, decorators, defaultDecorator) {
|
|
2271
2295
|
var e_1, _a, e_2, _b;
|
|
2272
|
-
{
|
|
2296
|
+
if (process.env.NODE_ENV !== "production") {
|
|
2273
2297
|
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");
|
|
2274
2298
|
if (decorators) {
|
|
2275
2299
|
var keys = getPlainObjectKeys(decorators);
|
|
@@ -2296,7 +2320,7 @@ function extendObservableObjectWithProperties(target, properties, decorators, de
|
|
|
2296
2320
|
for (var keys_2 = __values(keys), keys_2_1 = keys_2.next(); !keys_2_1.done; keys_2_1 = keys_2.next()) {
|
|
2297
2321
|
var key = keys_2_1.value;
|
|
2298
2322
|
var descriptor = Object.getOwnPropertyDescriptor(properties, key);
|
|
2299
|
-
{
|
|
2323
|
+
if (process.env.NODE_ENV !== "production") {
|
|
2300
2324
|
if (!isPlainObject(properties))
|
|
2301
2325
|
fail("'extendObservabe' only accepts plain objects as second argument");
|
|
2302
2326
|
if (isComputed(descriptor.value))
|
|
@@ -2307,7 +2331,7 @@ function extendObservableObjectWithProperties(target, properties, decorators, de
|
|
|
2307
2331
|
: descriptor.get
|
|
2308
2332
|
? computedDecorator
|
|
2309
2333
|
: defaultDecorator;
|
|
2310
|
-
if (typeof decorator !== "function")
|
|
2334
|
+
if (process.env.NODE_ENV !== "production" && typeof decorator !== "function")
|
|
2311
2335
|
fail("Not a valid decorator for '" + stringifyKey(key) + "', got: " + decorator);
|
|
2312
2336
|
var resultDescriptor = decorator(target, key, descriptor, true);
|
|
2313
2337
|
if (resultDescriptor // otherwise, assume already applied, due to `applyToInstance`
|
|
@@ -2361,7 +2385,7 @@ function isFlowCancellationError(error) {
|
|
|
2361
2385
|
}
|
|
2362
2386
|
function flow(generator) {
|
|
2363
2387
|
if (arguments.length !== 1)
|
|
2364
|
-
fail("Flow expects 1 argument and cannot be used as decorator");
|
|
2388
|
+
fail(!!process.env.NODE_ENV && "Flow expects 1 argument and cannot be used as decorator");
|
|
2365
2389
|
var name = generator.name || "<unnamed flow>";
|
|
2366
2390
|
// Implementation based on https://github.com/tj/co/blob/master/index.js
|
|
2367
2391
|
return function () {
|
|
@@ -2441,14 +2465,16 @@ function interceptReads(thing, propOrHandler, handler) {
|
|
|
2441
2465
|
}
|
|
2442
2466
|
else if (isObservableObject(thing)) {
|
|
2443
2467
|
if (typeof propOrHandler !== "string")
|
|
2444
|
-
return fail(
|
|
2468
|
+
return fail(process.env.NODE_ENV !== "production" &&
|
|
2469
|
+
"InterceptReads can only be used with a specific property, not with an object in general");
|
|
2445
2470
|
target = getAdministration(thing, propOrHandler);
|
|
2446
2471
|
}
|
|
2447
2472
|
else {
|
|
2448
|
-
return fail(
|
|
2473
|
+
return fail(process.env.NODE_ENV !== "production" &&
|
|
2474
|
+
"Expected observable map, object or array as first array");
|
|
2449
2475
|
}
|
|
2450
2476
|
if (target.dehancer !== undefined)
|
|
2451
|
-
return fail("An intercept reader was already established");
|
|
2477
|
+
return fail(process.env.NODE_ENV !== "production" && "An intercept reader was already established");
|
|
2452
2478
|
target.dehancer = typeof propOrHandler === "function" ? propOrHandler : handler;
|
|
2453
2479
|
return function () {
|
|
2454
2480
|
target.dehancer = undefined;
|
|
@@ -2483,12 +2509,14 @@ function _isComputed(value, property) {
|
|
|
2483
2509
|
}
|
|
2484
2510
|
function isComputed(value) {
|
|
2485
2511
|
if (arguments.length > 1)
|
|
2486
|
-
return fail(
|
|
2512
|
+
return fail(process.env.NODE_ENV !== "production" &&
|
|
2513
|
+
"isComputed expects only 1 argument. Use isObservableProp to inspect the observability of a property");
|
|
2487
2514
|
return _isComputed(value);
|
|
2488
2515
|
}
|
|
2489
2516
|
function isComputedProp(value, propName) {
|
|
2490
2517
|
if (typeof propName !== "string")
|
|
2491
|
-
return fail(
|
|
2518
|
+
return fail(process.env.NODE_ENV !== "production" &&
|
|
2519
|
+
"isComputed expected a property name as second argument");
|
|
2492
2520
|
return _isComputed(value, propName);
|
|
2493
2521
|
}
|
|
2494
2522
|
|
|
@@ -2496,7 +2524,8 @@ function _isObservable(value, property) {
|
|
|
2496
2524
|
if (value === null || value === undefined)
|
|
2497
2525
|
return false;
|
|
2498
2526
|
if (property !== undefined) {
|
|
2499
|
-
if (
|
|
2527
|
+
if (process.env.NODE_ENV !== "production" &&
|
|
2528
|
+
(isObservableMap(value) || isObservableArray(value)))
|
|
2500
2529
|
return fail("isObservable(object, propertyName) is not supported for arrays and maps. Use map.has or array.length instead.");
|
|
2501
2530
|
if (isObservableObject(value)) {
|
|
2502
2531
|
return value[$mobx].values.has(property);
|
|
@@ -2512,12 +2541,13 @@ function _isObservable(value, property) {
|
|
|
2512
2541
|
}
|
|
2513
2542
|
function isObservable(value) {
|
|
2514
2543
|
if (arguments.length !== 1)
|
|
2515
|
-
fail(
|
|
2544
|
+
fail(process.env.NODE_ENV !== "production" &&
|
|
2545
|
+
"isObservable expects only 1 argument. Use isObservableProp to inspect the observability of a property");
|
|
2516
2546
|
return _isObservable(value);
|
|
2517
2547
|
}
|
|
2518
2548
|
function isObservableProp(value, propName) {
|
|
2519
2549
|
if (typeof propName !== "string")
|
|
2520
|
-
return fail("expected a property name as second argument");
|
|
2550
|
+
return fail(process.env.NODE_ENV !== "production" && "expected a property name as second argument");
|
|
2521
2551
|
return _isObservable(value, propName);
|
|
2522
2552
|
}
|
|
2523
2553
|
|
|
@@ -2534,7 +2564,8 @@ function keys(obj) {
|
|
|
2534
2564
|
if (isObservableArray(obj)) {
|
|
2535
2565
|
return obj.map(function (_, index) { return index; });
|
|
2536
2566
|
}
|
|
2537
|
-
return fail(
|
|
2567
|
+
return fail(process.env.NODE_ENV !== "production" &&
|
|
2568
|
+
"'keys()' can only be used on observable objects, arrays, sets and maps");
|
|
2538
2569
|
}
|
|
2539
2570
|
function values(obj) {
|
|
2540
2571
|
if (isObservableObject(obj)) {
|
|
@@ -2549,7 +2580,8 @@ function values(obj) {
|
|
|
2549
2580
|
if (isObservableArray(obj)) {
|
|
2550
2581
|
return obj.slice();
|
|
2551
2582
|
}
|
|
2552
|
-
return fail(
|
|
2583
|
+
return fail(process.env.NODE_ENV !== "production" &&
|
|
2584
|
+
"'values()' can only be used on observable objects, arrays, sets and maps");
|
|
2553
2585
|
}
|
|
2554
2586
|
function entries(obj) {
|
|
2555
2587
|
if (isObservableObject(obj)) {
|
|
@@ -2564,7 +2596,8 @@ function entries(obj) {
|
|
|
2564
2596
|
if (isObservableArray(obj)) {
|
|
2565
2597
|
return obj.map(function (key, index) { return [index, key]; });
|
|
2566
2598
|
}
|
|
2567
|
-
return fail(
|
|
2599
|
+
return fail(process.env.NODE_ENV !== "production" &&
|
|
2600
|
+
"'entries()' can only be used on observable objects, arrays and maps");
|
|
2568
2601
|
}
|
|
2569
2602
|
function set(obj, key, value) {
|
|
2570
2603
|
if (arguments.length === 2 && !isObservableSet(obj)) {
|
|
@@ -2606,7 +2639,8 @@ function set(obj, key, value) {
|
|
|
2606
2639
|
endBatch();
|
|
2607
2640
|
}
|
|
2608
2641
|
else {
|
|
2609
|
-
return fail(
|
|
2642
|
+
return fail(process.env.NODE_ENV !== "production" &&
|
|
2643
|
+
"'set()' can only be used on observable objects, arrays and maps");
|
|
2610
2644
|
}
|
|
2611
2645
|
}
|
|
2612
2646
|
function remove(obj, key) {
|
|
@@ -2626,7 +2660,8 @@ function remove(obj, key) {
|
|
|
2626
2660
|
obj.splice(key, 1);
|
|
2627
2661
|
}
|
|
2628
2662
|
else {
|
|
2629
|
-
return fail(
|
|
2663
|
+
return fail(process.env.NODE_ENV !== "production" &&
|
|
2664
|
+
"'remove()' can only be used on observable objects, arrays and maps");
|
|
2630
2665
|
}
|
|
2631
2666
|
}
|
|
2632
2667
|
function has(obj, key) {
|
|
@@ -2645,7 +2680,8 @@ function has(obj, key) {
|
|
|
2645
2680
|
return key >= 0 && key < obj.length;
|
|
2646
2681
|
}
|
|
2647
2682
|
else {
|
|
2648
|
-
return fail(
|
|
2683
|
+
return fail(process.env.NODE_ENV !== "production" &&
|
|
2684
|
+
"'has()' can only be used on observable objects, arrays and maps");
|
|
2649
2685
|
}
|
|
2650
2686
|
}
|
|
2651
2687
|
function get(obj, key) {
|
|
@@ -2661,7 +2697,8 @@ function get(obj, key) {
|
|
|
2661
2697
|
return obj[key];
|
|
2662
2698
|
}
|
|
2663
2699
|
else {
|
|
2664
|
-
return fail(
|
|
2700
|
+
return fail(process.env.NODE_ENV !== "production" &&
|
|
2701
|
+
"'get()' can only be used on observable objects, arrays and maps");
|
|
2665
2702
|
}
|
|
2666
2703
|
}
|
|
2667
2704
|
|
|
@@ -2781,7 +2818,8 @@ function trace() {
|
|
|
2781
2818
|
enterBreakPoint = args.pop();
|
|
2782
2819
|
var derivation = getAtomFromArgs(args);
|
|
2783
2820
|
if (!derivation) {
|
|
2784
|
-
return fail(
|
|
2821
|
+
return fail(process.env.NODE_ENV !== "production" &&
|
|
2822
|
+
"'trace(break?)' can only be used inside a tracked computed value or a Reaction. Consider passing in the computed value or reaction explicitly");
|
|
2785
2823
|
}
|
|
2786
2824
|
if (derivation.isTracing === TraceMode.NONE) {
|
|
2787
2825
|
console.log("[mobx.trace] '" + derivation.name + "' tracing enabled");
|
|
@@ -2849,7 +2887,7 @@ function _when(predicate, effect, opts) {
|
|
|
2849
2887
|
return disposer;
|
|
2850
2888
|
}
|
|
2851
2889
|
function whenPromise(predicate, opts) {
|
|
2852
|
-
if (opts && opts.onError)
|
|
2890
|
+
if (process.env.NODE_ENV !== "production" && opts && opts.onError)
|
|
2853
2891
|
return fail("the options 'onError' and 'promise' cannot be combined");
|
|
2854
2892
|
var cancel;
|
|
2855
2893
|
var res = new Promise(function (resolve, reject) {
|
|
@@ -3133,7 +3171,7 @@ var ObservableArrayAdministration = /** @class */ (function () {
|
|
|
3133
3171
|
newItems = change.added;
|
|
3134
3172
|
}
|
|
3135
3173
|
newItems = newItems.length === 0 ? newItems : newItems.map(function (v) { return _this.enhancer(v, undefined); });
|
|
3136
|
-
{
|
|
3174
|
+
if (process.env.NODE_ENV !== "production") {
|
|
3137
3175
|
var lengthDelta = newItems.length - deleteCount;
|
|
3138
3176
|
this.updateArrayLength(length, lengthDelta); // checks if internal array wasn't modified
|
|
3139
3177
|
}
|
|
@@ -3169,12 +3207,12 @@ var ObservableArrayAdministration = /** @class */ (function () {
|
|
|
3169
3207
|
: null;
|
|
3170
3208
|
// 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
|
|
3171
3209
|
// cause any runtime overhead in development mode without NODE_ENV set, unless spying is enabled
|
|
3172
|
-
if (notifySpy &&
|
|
3210
|
+
if (notifySpy && process.env.NODE_ENV !== "production")
|
|
3173
3211
|
spyReportStart(__assign(__assign({}, change), { name: this.atom.name }));
|
|
3174
3212
|
this.atom.reportChanged();
|
|
3175
3213
|
if (notify)
|
|
3176
3214
|
notifyListeners(this, change);
|
|
3177
|
-
if (notifySpy &&
|
|
3215
|
+
if (notifySpy && process.env.NODE_ENV !== "production")
|
|
3178
3216
|
spyReportEnd();
|
|
3179
3217
|
};
|
|
3180
3218
|
ObservableArrayAdministration.prototype.notifyArraySplice = function (index, added, removed) {
|
|
@@ -3191,13 +3229,13 @@ var ObservableArrayAdministration = /** @class */ (function () {
|
|
|
3191
3229
|
addedCount: added.length
|
|
3192
3230
|
}
|
|
3193
3231
|
: null;
|
|
3194
|
-
if (notifySpy &&
|
|
3232
|
+
if (notifySpy && process.env.NODE_ENV !== "production")
|
|
3195
3233
|
spyReportStart(__assign(__assign({}, change), { name: this.atom.name }));
|
|
3196
3234
|
this.atom.reportChanged();
|
|
3197
3235
|
// conform: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/observe
|
|
3198
3236
|
if (notify)
|
|
3199
3237
|
notifyListeners(this, change);
|
|
3200
|
-
if (notifySpy &&
|
|
3238
|
+
if (notifySpy && process.env.NODE_ENV !== "production")
|
|
3201
3239
|
spyReportEnd();
|
|
3202
3240
|
};
|
|
3203
3241
|
return ObservableArrayAdministration;
|
|
@@ -3283,7 +3321,7 @@ var arrayExtensions = {
|
|
|
3283
3321
|
// reverse by default mutates in place before returning the result
|
|
3284
3322
|
// which makes it both a 'derivation' and a 'mutation'.
|
|
3285
3323
|
// so we deviate from the default and just make it an dervitation
|
|
3286
|
-
{
|
|
3324
|
+
if (process.env.NODE_ENV !== "production") {
|
|
3287
3325
|
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");
|
|
3288
3326
|
}
|
|
3289
3327
|
var clone = this.slice();
|
|
@@ -3292,7 +3330,7 @@ var arrayExtensions = {
|
|
|
3292
3330
|
sort: function (compareFn) {
|
|
3293
3331
|
// sort by default mutates in place before returning the result
|
|
3294
3332
|
// which goes against all good practices. Let's not change the array in place!
|
|
3295
|
-
{
|
|
3333
|
+
if (process.env.NODE_ENV !== "production") {
|
|
3296
3334
|
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");
|
|
3297
3335
|
}
|
|
3298
3336
|
var clone = this.slice();
|
|
@@ -3460,7 +3498,7 @@ var ObservableMap = /** @class */ (function () {
|
|
|
3460
3498
|
name: key
|
|
3461
3499
|
}
|
|
3462
3500
|
: null;
|
|
3463
|
-
if (notifySpy &&
|
|
3501
|
+
if (notifySpy && process.env.NODE_ENV !== "production")
|
|
3464
3502
|
spyReportStart(__assign(__assign({}, change), { name: this.name, key: key }));
|
|
3465
3503
|
transaction(function () {
|
|
3466
3504
|
_this._keysAtom.reportChanged();
|
|
@@ -3471,7 +3509,7 @@ var ObservableMap = /** @class */ (function () {
|
|
|
3471
3509
|
});
|
|
3472
3510
|
if (notify)
|
|
3473
3511
|
notifyListeners(this, change);
|
|
3474
|
-
if (notifySpy &&
|
|
3512
|
+
if (notifySpy && process.env.NODE_ENV !== "production")
|
|
3475
3513
|
spyReportEnd();
|
|
3476
3514
|
return true;
|
|
3477
3515
|
}
|
|
@@ -3498,12 +3536,12 @@ var ObservableMap = /** @class */ (function () {
|
|
|
3498
3536
|
newValue: newValue
|
|
3499
3537
|
}
|
|
3500
3538
|
: null;
|
|
3501
|
-
if (notifySpy &&
|
|
3539
|
+
if (notifySpy && process.env.NODE_ENV !== "production")
|
|
3502
3540
|
spyReportStart(__assign(__assign({}, change), { name: this.name, key: key }));
|
|
3503
3541
|
observable.setNewValue(newValue);
|
|
3504
3542
|
if (notify)
|
|
3505
3543
|
notifyListeners(this, change);
|
|
3506
|
-
if (notifySpy &&
|
|
3544
|
+
if (notifySpy && process.env.NODE_ENV !== "production")
|
|
3507
3545
|
spyReportEnd();
|
|
3508
3546
|
}
|
|
3509
3547
|
};
|
|
@@ -3527,11 +3565,11 @@ var ObservableMap = /** @class */ (function () {
|
|
|
3527
3565
|
newValue: newValue
|
|
3528
3566
|
}
|
|
3529
3567
|
: null;
|
|
3530
|
-
if (notifySpy &&
|
|
3568
|
+
if (notifySpy && process.env.NODE_ENV !== "production")
|
|
3531
3569
|
spyReportStart(__assign(__assign({}, change), { name: this.name, key: key }));
|
|
3532
3570
|
if (notify)
|
|
3533
3571
|
notifyListeners(this, change);
|
|
3534
|
-
if (notifySpy &&
|
|
3572
|
+
if (notifySpy && process.env.NODE_ENV !== "production")
|
|
3535
3573
|
spyReportEnd();
|
|
3536
3574
|
};
|
|
3537
3575
|
ObservableMap.prototype.get = function (key) {
|
|
@@ -3714,7 +3752,8 @@ var ObservableMap = /** @class */ (function () {
|
|
|
3714
3752
|
* for callback details
|
|
3715
3753
|
*/
|
|
3716
3754
|
ObservableMap.prototype.observe = function (listener, fireImmediately) {
|
|
3717
|
-
|
|
3755
|
+
process.env.NODE_ENV !== "production" &&
|
|
3756
|
+
invariant(fireImmediately !== true, "`observe` doesn't support fireImmediately=true in combination with maps.");
|
|
3718
3757
|
return registerListener(this, listener);
|
|
3719
3758
|
};
|
|
3720
3759
|
ObservableMap.prototype.intercept = function (handler) {
|
|
@@ -3823,11 +3862,11 @@ var ObservableSet = /** @class */ (function () {
|
|
|
3823
3862
|
newValue: value
|
|
3824
3863
|
}
|
|
3825
3864
|
: null;
|
|
3826
|
-
if (notifySpy &&
|
|
3865
|
+
if (notifySpy && process.env.NODE_ENV !== "production")
|
|
3827
3866
|
spyReportStart(change);
|
|
3828
3867
|
if (notify)
|
|
3829
3868
|
notifyListeners(this, change);
|
|
3830
|
-
if (notifySpy &&
|
|
3869
|
+
if (notifySpy && process.env.NODE_ENV !== "production")
|
|
3831
3870
|
spyReportEnd();
|
|
3832
3871
|
}
|
|
3833
3872
|
return this;
|
|
@@ -3853,7 +3892,7 @@ var ObservableSet = /** @class */ (function () {
|
|
|
3853
3892
|
oldValue: value
|
|
3854
3893
|
}
|
|
3855
3894
|
: null;
|
|
3856
|
-
if (notifySpy &&
|
|
3895
|
+
if (notifySpy && process.env.NODE_ENV !== "production")
|
|
3857
3896
|
spyReportStart(__assign(__assign({}, change), { name: this.name }));
|
|
3858
3897
|
transaction(function () {
|
|
3859
3898
|
_this._atom.reportChanged();
|
|
@@ -3861,7 +3900,7 @@ var ObservableSet = /** @class */ (function () {
|
|
|
3861
3900
|
});
|
|
3862
3901
|
if (notify)
|
|
3863
3902
|
notifyListeners(this, change);
|
|
3864
|
-
if (notifySpy &&
|
|
3903
|
+
if (notifySpy && process.env.NODE_ENV !== "production")
|
|
3865
3904
|
spyReportEnd();
|
|
3866
3905
|
return true;
|
|
3867
3906
|
}
|
|
@@ -3923,7 +3962,8 @@ var ObservableSet = /** @class */ (function () {
|
|
|
3923
3962
|
};
|
|
3924
3963
|
ObservableSet.prototype.observe = function (listener, fireImmediately) {
|
|
3925
3964
|
// TODO 'fireImmediately' can be true?
|
|
3926
|
-
|
|
3965
|
+
process.env.NODE_ENV !== "production" &&
|
|
3966
|
+
invariant(fireImmediately !== true, "`observe` doesn't support fireImmediately=true in combination with sets.");
|
|
3927
3967
|
return registerListener(this, listener);
|
|
3928
3968
|
};
|
|
3929
3969
|
ObservableSet.prototype.intercept = function (handler) {
|
|
@@ -3987,12 +4027,12 @@ var ObservableObjectAdministration = /** @class */ (function () {
|
|
|
3987
4027
|
newValue: newValue
|
|
3988
4028
|
}
|
|
3989
4029
|
: null;
|
|
3990
|
-
if (notifySpy &&
|
|
4030
|
+
if (notifySpy && process.env.NODE_ENV !== "production")
|
|
3991
4031
|
spyReportStart(__assign(__assign({}, change), { name: this.name, key: key }));
|
|
3992
4032
|
observable.setNewValue(newValue);
|
|
3993
4033
|
if (notify)
|
|
3994
4034
|
notifyListeners(this, change);
|
|
3995
|
-
if (notifySpy &&
|
|
4035
|
+
if (notifySpy && process.env.NODE_ENV !== "production")
|
|
3996
4036
|
spyReportEnd();
|
|
3997
4037
|
}
|
|
3998
4038
|
};
|
|
@@ -4077,11 +4117,11 @@ var ObservableObjectAdministration = /** @class */ (function () {
|
|
|
4077
4117
|
name: key
|
|
4078
4118
|
}
|
|
4079
4119
|
: null;
|
|
4080
|
-
if (notifySpy &&
|
|
4120
|
+
if (notifySpy && process.env.NODE_ENV !== "production")
|
|
4081
4121
|
spyReportStart(__assign(__assign({}, change), { name: this.name, key: key }));
|
|
4082
4122
|
if (notify)
|
|
4083
4123
|
notifyListeners(this, change);
|
|
4084
|
-
if (notifySpy &&
|
|
4124
|
+
if (notifySpy && process.env.NODE_ENV !== "production")
|
|
4085
4125
|
spyReportEnd();
|
|
4086
4126
|
}
|
|
4087
4127
|
finally {
|
|
@@ -4116,7 +4156,8 @@ var ObservableObjectAdministration = /** @class */ (function () {
|
|
|
4116
4156
|
* for callback details
|
|
4117
4157
|
*/
|
|
4118
4158
|
ObservableObjectAdministration.prototype.observe = function (callback, fireImmediately) {
|
|
4119
|
-
|
|
4159
|
+
process.env.NODE_ENV !== "production" &&
|
|
4160
|
+
invariant(fireImmediately !== true, "`observe` doesn't support the fire immediately property for observable objects.");
|
|
4120
4161
|
return registerListener(this, callback);
|
|
4121
4162
|
};
|
|
4122
4163
|
ObservableObjectAdministration.prototype.intercept = function (handler) {
|
|
@@ -4133,11 +4174,11 @@ var ObservableObjectAdministration = /** @class */ (function () {
|
|
|
4133
4174
|
newValue: newValue
|
|
4134
4175
|
}
|
|
4135
4176
|
: null;
|
|
4136
|
-
if (notifySpy &&
|
|
4177
|
+
if (notifySpy && process.env.NODE_ENV !== "production")
|
|
4137
4178
|
spyReportStart(__assign(__assign({}, change), { name: this.name, key: key }));
|
|
4138
4179
|
if (notify)
|
|
4139
4180
|
notifyListeners(this, change);
|
|
4140
|
-
if (notifySpy &&
|
|
4181
|
+
if (notifySpy && process.env.NODE_ENV !== "production")
|
|
4141
4182
|
spyReportEnd();
|
|
4142
4183
|
if (this.pendingKeys) {
|
|
4143
4184
|
var entry = this.pendingKeys.get(key);
|
|
@@ -4174,7 +4215,8 @@ function asObservableObject(target, name, defaultEnhancer) {
|
|
|
4174
4215
|
if (defaultEnhancer === void 0) { defaultEnhancer = deepEnhancer; }
|
|
4175
4216
|
if (Object.prototype.hasOwnProperty.call(target, $mobx))
|
|
4176
4217
|
return target[$mobx];
|
|
4177
|
-
|
|
4218
|
+
process.env.NODE_ENV !== "production" &&
|
|
4219
|
+
invariant(Object.isExtensible(target), "Cannot make the designated object observable; it is not extensible");
|
|
4178
4220
|
if (!isPlainObject(target))
|
|
4179
4221
|
name = (target.constructor.name || "ObservableObject") + "@" + getNextId();
|
|
4180
4222
|
if (!name)
|
|
@@ -4235,7 +4277,8 @@ function getAtom(thing, property) {
|
|
|
4235
4277
|
if (typeof thing === "object" && thing !== null) {
|
|
4236
4278
|
if (isObservableArray(thing)) {
|
|
4237
4279
|
if (property !== undefined)
|
|
4238
|
-
fail(
|
|
4280
|
+
fail(process.env.NODE_ENV !== "production" &&
|
|
4281
|
+
"It is not possible to get index atoms from arrays");
|
|
4239
4282
|
return thing[$mobx].atom;
|
|
4240
4283
|
}
|
|
4241
4284
|
if (isObservableSet(thing)) {
|
|
@@ -4247,7 +4290,8 @@ function getAtom(thing, property) {
|
|
|
4247
4290
|
return anyThing._keysAtom;
|
|
4248
4291
|
var observable = anyThing._data.get(property) || anyThing._hasMap.get(property);
|
|
4249
4292
|
if (!observable)
|
|
4250
|
-
fail(
|
|
4293
|
+
fail(process.env.NODE_ENV !== "production" &&
|
|
4294
|
+
"the entry '" + property + "' does not exist in the observable map '" + getDebugName(thing) + "'");
|
|
4251
4295
|
return observable;
|
|
4252
4296
|
}
|
|
4253
4297
|
// Initializers run lazily when transpiling to babel, so make sure they are run...
|
|
@@ -4256,10 +4300,11 @@ function getAtom(thing, property) {
|
|
|
4256
4300
|
thing[property]; // See #1072
|
|
4257
4301
|
if (isObservableObject(thing)) {
|
|
4258
4302
|
if (!property)
|
|
4259
|
-
return fail("please specify a property");
|
|
4303
|
+
return fail(process.env.NODE_ENV !== "production" && "please specify a property");
|
|
4260
4304
|
var observable = thing[$mobx].values.get(property);
|
|
4261
4305
|
if (!observable)
|
|
4262
|
-
fail(
|
|
4306
|
+
fail(process.env.NODE_ENV !== "production" &&
|
|
4307
|
+
"no observable property '" + property + "' found on the observable object '" + getDebugName(thing) + "'");
|
|
4263
4308
|
return observable;
|
|
4264
4309
|
}
|
|
4265
4310
|
if (isAtom(thing) || isComputedValue(thing) || isReaction(thing)) {
|
|
@@ -4272,7 +4317,7 @@ function getAtom(thing, property) {
|
|
|
4272
4317
|
return thing[$mobx];
|
|
4273
4318
|
}
|
|
4274
4319
|
}
|
|
4275
|
-
return fail("Cannot obtain atom from " + thing);
|
|
4320
|
+
return fail(process.env.NODE_ENV !== "production" && "Cannot obtain atom from " + thing);
|
|
4276
4321
|
}
|
|
4277
4322
|
function getAdministration(thing, property) {
|
|
4278
4323
|
if (!thing)
|
|
@@ -4287,7 +4332,7 @@ function getAdministration(thing, property) {
|
|
|
4287
4332
|
initializeInstance(thing);
|
|
4288
4333
|
if (thing[$mobx])
|
|
4289
4334
|
return thing[$mobx];
|
|
4290
|
-
fail("Cannot obtain administration from " + thing);
|
|
4335
|
+
fail(process.env.NODE_ENV !== "production" && "Cannot obtain administration from " + thing);
|
|
4291
4336
|
}
|
|
4292
4337
|
function getDebugName(thing, property) {
|
|
4293
4338
|
var named;
|
|
@@ -4481,6 +4526,10 @@ if (typeof Proxy === "undefined" || typeof Symbol === "undefined") {
|
|
|
4481
4526
|
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.");
|
|
4482
4527
|
}
|
|
4483
4528
|
try {
|
|
4529
|
+
// define process.env if needed
|
|
4530
|
+
// if this is not a production build in the first place
|
|
4531
|
+
// (in which case the expression below would be substituted with 'production')
|
|
4532
|
+
process.env.NODE_ENV;
|
|
4484
4533
|
}
|
|
4485
4534
|
catch (e) {
|
|
4486
4535
|
var g = getGlobal();
|
|
@@ -4491,8 +4540,8 @@ catch (e) {
|
|
|
4491
4540
|
(function () {
|
|
4492
4541
|
function testCodeMinification() { }
|
|
4493
4542
|
if (testCodeMinification.name !== "testCodeMinification" &&
|
|
4494
|
-
|
|
4495
|
-
process.env.IGNORE_MOBX_MINIFY_WARNING !== "true") {
|
|
4543
|
+
process.env.NODE_ENV !== "production" &&
|
|
4544
|
+
typeof process !== 'undefined' && process.env.IGNORE_MOBX_MINIFY_WARNING !== "true") {
|
|
4496
4545
|
// trick so it doesn't get replaced
|
|
4497
4546
|
var varName = ["process", "env", "NODE_ENV"].join(".");
|
|
4498
4547
|
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");
|