mobx 6.3.2 → 6.3.6
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 +37 -0
- package/README.md +4 -4
- package/dist/api/autorun.d.ts +4 -4
- package/dist/mobx.cjs.development.js +59 -54
- package/dist/mobx.cjs.development.js.map +1 -1
- package/dist/mobx.cjs.production.min.js +1 -1
- package/dist/mobx.cjs.production.min.js.map +1 -1
- package/dist/mobx.esm.development.js +59 -54
- package/dist/mobx.esm.development.js.map +1 -1
- package/dist/mobx.esm.js +59 -54
- package/dist/mobx.esm.js.map +1 -1
- package/dist/mobx.esm.production.min.js +1 -1
- package/dist/mobx.esm.production.min.js.map +1 -1
- package/dist/mobx.umd.development.js +59 -54
- package/dist/mobx.umd.development.js.map +1 -1
- package/dist/mobx.umd.production.min.js +1 -1
- package/dist/mobx.umd.production.min.js.map +1 -1
- package/dist/types/observablemap.d.ts +0 -1
- package/package.json +1 -1
- package/src/api/autorun.ts +18 -11
- package/src/api/extendobservable.ts +1 -1
- package/src/api/iscomputed.ts +6 -6
- package/src/api/makeObservable.ts +7 -1
- package/src/api/observable.ts +4 -4
- package/src/api/when.ts +2 -2
- package/src/core/computedvalue.ts +19 -17
- package/src/core/derivation.ts +4 -2
- package/src/core/globalstate.ts +2 -0
- package/src/core/observable.ts +1 -1
- package/src/mobx.ts +1 -1
- package/src/types/actionannotation.ts +4 -2
- package/src/types/observablearray.ts +1 -1
- package/src/types/observablemap.ts +2 -9
- package/src/utils/comparer.ts +5 -1
|
@@ -510,7 +510,8 @@ function shallowComparer(a, b) {
|
|
|
510
510
|
}
|
|
511
511
|
|
|
512
512
|
function defaultComparer(a, b) {
|
|
513
|
-
return Object.is(a, b);
|
|
513
|
+
if (Object.is) return Object.is(a, b);
|
|
514
|
+
return a === b ? a !== 0 || 1 / a === 1 / b : a !== a && b !== b;
|
|
514
515
|
}
|
|
515
516
|
|
|
516
517
|
var comparer = {
|
|
@@ -670,7 +671,7 @@ function assertActionDescriptor(adm, _ref, key, _ref2) {
|
|
|
670
671
|
|
|
671
672
|
function createActionDescriptor(adm, annotation, key, descriptor, // provides ability to disable safeDescriptors for prototypes
|
|
672
673
|
safeDescriptors) {
|
|
673
|
-
var _annotation$options_, _annotation$options_$, _annotation$options_2, _annotation$options_$2, _annotation$options_3;
|
|
674
|
+
var _annotation$options_, _annotation$options_$, _annotation$options_2, _annotation$options_$2, _annotation$options_3, _annotation$options_4, _adm$proxy_2;
|
|
674
675
|
|
|
675
676
|
if (safeDescriptors === void 0) {
|
|
676
677
|
safeDescriptors = globalState.safeDescriptors;
|
|
@@ -686,7 +687,8 @@ safeDescriptors) {
|
|
|
686
687
|
}
|
|
687
688
|
|
|
688
689
|
return {
|
|
689
|
-
value: createAction((_annotation$options_$ = (_annotation$options_2 = annotation.options_) == null ? void 0 : _annotation$options_2.name) != null ? _annotation$options_$ : key.toString(), value, (_annotation$options_$2 = (_annotation$options_3 = annotation.options_) == null ? void 0 : _annotation$options_3.autoAction) != null ? _annotation$options_$2 : false
|
|
690
|
+
value: createAction((_annotation$options_$ = (_annotation$options_2 = annotation.options_) == null ? void 0 : _annotation$options_2.name) != null ? _annotation$options_$ : key.toString(), value, (_annotation$options_$2 = (_annotation$options_3 = annotation.options_) == null ? void 0 : _annotation$options_3.autoAction) != null ? _annotation$options_$2 : false, // https://github.com/mobxjs/mobx/discussions/3140
|
|
691
|
+
((_annotation$options_4 = annotation.options_) == null ? void 0 : _annotation$options_4.bound) ? (_adm$proxy_2 = adm.proxy_) != null ? _adm$proxy_2 : adm.target_ : undefined),
|
|
690
692
|
// Non-configurable for classes
|
|
691
693
|
// prevents accidental field redefinition in subclass
|
|
692
694
|
configurable: safeDescriptors ? adm.isPlainObject_ : true,
|
|
@@ -955,6 +957,10 @@ function extend_$5(adm, key, descriptor, proxyTrap) {
|
|
|
955
957
|
return observableAnnotation.extend_(adm, key, descriptor, proxyTrap);
|
|
956
958
|
}
|
|
957
959
|
|
|
960
|
+
var OBSERVABLE = "observable";
|
|
961
|
+
var OBSERVABLE_REF = "observable.ref";
|
|
962
|
+
var OBSERVABLE_SHALLOW = "observable.shallow";
|
|
963
|
+
var OBSERVABLE_STRUCT = "observable.struct"; // Predefined bags of create observable options, to avoid allocating temporarily option objects
|
|
958
964
|
// in the majority of cases
|
|
959
965
|
|
|
960
966
|
var defaultCreateObservableOptions = {
|
|
@@ -967,14 +973,14 @@ Object.freeze(defaultCreateObservableOptions);
|
|
|
967
973
|
function asCreateObservableOptions(thing) {
|
|
968
974
|
return thing || defaultCreateObservableOptions;
|
|
969
975
|
}
|
|
970
|
-
var observableAnnotation = /*#__PURE__*/createObservableAnnotation(
|
|
971
|
-
var observableRefAnnotation = /*#__PURE__*/createObservableAnnotation(
|
|
976
|
+
var observableAnnotation = /*#__PURE__*/createObservableAnnotation(OBSERVABLE);
|
|
977
|
+
var observableRefAnnotation = /*#__PURE__*/createObservableAnnotation(OBSERVABLE_REF, {
|
|
972
978
|
enhancer: referenceEnhancer
|
|
973
979
|
});
|
|
974
|
-
var observableShallowAnnotation = /*#__PURE__*/createObservableAnnotation(
|
|
980
|
+
var observableShallowAnnotation = /*#__PURE__*/createObservableAnnotation(OBSERVABLE_SHALLOW, {
|
|
975
981
|
enhancer: shallowEnhancer
|
|
976
982
|
});
|
|
977
|
-
var observableStructAnnotation = /*#__PURE__*/createObservableAnnotation(
|
|
983
|
+
var observableStructAnnotation = /*#__PURE__*/createObservableAnnotation(OBSERVABLE_STRUCT, {
|
|
978
984
|
enhancer: refStructEnhancer
|
|
979
985
|
});
|
|
980
986
|
var observableDecoratorAnnotation = /*#__PURE__*/createDecoratorAnnotation(observableAnnotation);
|
|
@@ -1529,22 +1535,21 @@ var ComputedValue = /*#__PURE__*/function () {
|
|
|
1529
1535
|
/* see #1208 */
|
|
1530
1536
|
this.dependenciesState_ === IDerivationState_.NOT_TRACKING_;
|
|
1531
1537
|
var newValue = this.computeValue_(true);
|
|
1532
|
-
|
|
1533
|
-
if ( isSpyEnabled()) {
|
|
1534
|
-
spyReport({
|
|
1535
|
-
observableKind: "computed",
|
|
1536
|
-
debugObjectName: this.name_,
|
|
1537
|
-
object: this.scope_,
|
|
1538
|
-
type: "update",
|
|
1539
|
-
oldValue: this.value_,
|
|
1540
|
-
newValue: newValue
|
|
1541
|
-
});
|
|
1542
|
-
}
|
|
1543
|
-
|
|
1544
1538
|
var changed = wasSuspended || isCaughtException(oldValue) || isCaughtException(newValue) || !this.equals_(oldValue, newValue);
|
|
1545
1539
|
|
|
1546
1540
|
if (changed) {
|
|
1547
1541
|
this.value_ = newValue;
|
|
1542
|
+
|
|
1543
|
+
if ( isSpyEnabled()) {
|
|
1544
|
+
spyReport({
|
|
1545
|
+
observableKind: "computed",
|
|
1546
|
+
debugObjectName: this.name_,
|
|
1547
|
+
object: this.scope_,
|
|
1548
|
+
type: "update",
|
|
1549
|
+
oldValue: oldValue,
|
|
1550
|
+
newValue: newValue
|
|
1551
|
+
});
|
|
1552
|
+
}
|
|
1548
1553
|
}
|
|
1549
1554
|
|
|
1550
1555
|
return changed;
|
|
@@ -1579,6 +1584,10 @@ var ComputedValue = /*#__PURE__*/function () {
|
|
|
1579
1584
|
if (!this.keepAlive_) {
|
|
1580
1585
|
clearObserving(this);
|
|
1581
1586
|
this.value_ = undefined; // don't hold on to computed value!
|
|
1587
|
+
|
|
1588
|
+
if ( this.isTracing_ !== TraceMode.NONE) {
|
|
1589
|
+
console.log("[mobx.trace] Computed value '" + this.name_ + "' was suspended and it will recompute on the next access.");
|
|
1590
|
+
}
|
|
1582
1591
|
}
|
|
1583
1592
|
};
|
|
1584
1593
|
|
|
@@ -1611,16 +1620,12 @@ var ComputedValue = /*#__PURE__*/function () {
|
|
|
1611
1620
|
|
|
1612
1621
|
_proto.warnAboutUntrackedRead_ = function warnAboutUntrackedRead_() {
|
|
1613
1622
|
|
|
1614
|
-
if (this.requiresReaction_ === true) {
|
|
1615
|
-
die("[mobx] Computed value " + this.name_ + " is read outside a reactive context");
|
|
1616
|
-
}
|
|
1617
|
-
|
|
1618
1623
|
if (this.isTracing_ !== TraceMode.NONE) {
|
|
1619
|
-
console.log("[mobx.trace] '" + this.name_ + "' is being read outside a reactive context. Doing a full recompute");
|
|
1624
|
+
console.log("[mobx.trace] Computed value '" + this.name_ + "' is being read outside a reactive context. Doing a full recompute.");
|
|
1620
1625
|
}
|
|
1621
1626
|
|
|
1622
|
-
if (globalState.computedRequiresReaction) {
|
|
1623
|
-
console.warn("[mobx] Computed value " + this.name_ + " is being read outside a reactive context. Doing a full recompute");
|
|
1627
|
+
if (globalState.computedRequiresReaction || this.requiresReaction_) {
|
|
1628
|
+
console.warn("[mobx] Computed value '" + this.name_ + "' is being read outside a reactive context. Doing a full recompute.");
|
|
1624
1629
|
}
|
|
1625
1630
|
};
|
|
1626
1631
|
|
|
@@ -1753,7 +1758,7 @@ function checkIfStateModificationsAreAllowed(atom) {
|
|
|
1753
1758
|
}
|
|
1754
1759
|
function checkIfStateReadsAreAllowed(observable) {
|
|
1755
1760
|
if ( !globalState.allowStateReads && globalState.observableRequiresReaction) {
|
|
1756
|
-
console.warn("[mobx] Observable " + observable.name_ + " being read outside a reactive context");
|
|
1761
|
+
console.warn("[mobx] Observable '" + observable.name_ + "' being read outside a reactive context.");
|
|
1757
1762
|
}
|
|
1758
1763
|
}
|
|
1759
1764
|
/**
|
|
@@ -1797,7 +1802,7 @@ function warnAboutDerivationWithoutDependencies(derivation) {
|
|
|
1797
1802
|
if (derivation.observing_.length !== 0) return;
|
|
1798
1803
|
|
|
1799
1804
|
if (globalState.reactionRequiresObservable || derivation.requiresObservable_) {
|
|
1800
|
-
console.warn("[mobx] Derivation " + derivation.name_ + " is created/updated without reading any observable value");
|
|
1805
|
+
console.warn("[mobx] Derivation '" + derivation.name_ + "' is created/updated without reading any observable value.");
|
|
1801
1806
|
}
|
|
1802
1807
|
}
|
|
1803
1808
|
/**
|
|
@@ -1963,6 +1968,8 @@ var globalState = /*#__PURE__*/function () {
|
|
|
1963
1968
|
if (global.__mobxGlobals && global.__mobxGlobals.version !== new MobXGlobals().version) canMergeGlobalState = false;
|
|
1964
1969
|
|
|
1965
1970
|
if (!canMergeGlobalState) {
|
|
1971
|
+
// Because this is a IIFE we need to let isolateCalled a chance to change
|
|
1972
|
+
// so we run it after the event loop completed at least 1 iteration
|
|
1966
1973
|
setTimeout(function () {
|
|
1967
1974
|
if (!isolateCalled) {
|
|
1968
1975
|
die(35);
|
|
@@ -2210,8 +2217,7 @@ function printDepTree(tree, lines, depth) {
|
|
|
2210
2217
|
return;
|
|
2211
2218
|
}
|
|
2212
2219
|
|
|
2213
|
-
lines.push("" +
|
|
2214
|
-
|
|
2220
|
+
lines.push("" + "\t".repeat(depth - 1) + tree.name);
|
|
2215
2221
|
if (tree.dependencies) tree.dependencies.forEach(function (child) {
|
|
2216
2222
|
return printDepTree(child, lines, depth + 1);
|
|
2217
2223
|
});
|
|
@@ -2642,8 +2648,7 @@ function reaction(expression, effect, opts) {
|
|
|
2642
2648
|
var firstTime = true;
|
|
2643
2649
|
var isScheduled = false;
|
|
2644
2650
|
var value;
|
|
2645
|
-
var oldValue
|
|
2646
|
-
|
|
2651
|
+
var oldValue;
|
|
2647
2652
|
var equals = opts.compareStructural ? comparer.structural : opts.equals || comparer["default"];
|
|
2648
2653
|
var r = new Reaction(name, function () {
|
|
2649
2654
|
if (firstTime || runSync) {
|
|
@@ -2759,7 +2764,7 @@ function extendObservable(target, properties, annotations, options) {
|
|
|
2759
2764
|
if (arguments.length > 4) die("'extendObservable' expected 2-4 arguments");
|
|
2760
2765
|
if (typeof target !== "object") die("'extendObservable' expects an object as first argument");
|
|
2761
2766
|
if (isObservableMap(target)) die("'extendObservable' should not be used on maps, use map.merge instead");
|
|
2762
|
-
if (!isPlainObject(properties)) die("'
|
|
2767
|
+
if (!isPlainObject(properties)) die("'extendObservable' only accepts plain objects as second argument");
|
|
2763
2768
|
if (isObservable(properties) || isObservable(annotations)) die("Extending an object with another observable (object) is not supported");
|
|
2764
2769
|
} // Pull descriptors first, so we don't have to deal with props added by administration ($mobx)
|
|
2765
2770
|
|
|
@@ -2950,14 +2955,14 @@ function interceptProperty(thing, property, handler) {
|
|
|
2950
2955
|
}
|
|
2951
2956
|
|
|
2952
2957
|
function _isComputed(value, property) {
|
|
2953
|
-
if (property
|
|
2954
|
-
|
|
2955
|
-
if (!value[$mobx].values_.has(property)) return false;
|
|
2956
|
-
var atom = getAtom(value, property);
|
|
2957
|
-
return isComputedValue(atom);
|
|
2958
|
+
if (property === undefined) {
|
|
2959
|
+
return isComputedValue(value);
|
|
2958
2960
|
}
|
|
2959
2961
|
|
|
2960
|
-
|
|
2962
|
+
if (isObservableObject(value) === false) return false;
|
|
2963
|
+
if (!value[$mobx].values_.has(property)) return false;
|
|
2964
|
+
var atom = getAtom(value, property);
|
|
2965
|
+
return isComputedValue(atom);
|
|
2961
2966
|
}
|
|
2962
2967
|
function isComputed(value) {
|
|
2963
2968
|
if ( arguments.length > 1) return die("isComputed expects only 1 argument. Use isComputedProp to inspect the observability of a property");
|
|
@@ -3281,10 +3286,10 @@ function _when(predicate, effect, opts) {
|
|
|
3281
3286
|
var timeoutHandle;
|
|
3282
3287
|
|
|
3283
3288
|
if (typeof opts.timeout === "number") {
|
|
3289
|
+
var error = new Error("WHEN_TIMEOUT");
|
|
3284
3290
|
timeoutHandle = setTimeout(function () {
|
|
3285
3291
|
if (!disposer[$mobx].isDisposed_) {
|
|
3286
3292
|
disposer();
|
|
3287
|
-
var error = new Error("WHEN_TIMEOUT");
|
|
3288
3293
|
if (opts.onError) opts.onError(error);else throw error;
|
|
3289
3294
|
}
|
|
3290
3295
|
}, opts.timeout);
|
|
@@ -3316,7 +3321,7 @@ function whenPromise(predicate, opts) {
|
|
|
3316
3321
|
|
|
3317
3322
|
cancel = function cancel() {
|
|
3318
3323
|
disposer();
|
|
3319
|
-
reject("WHEN_CANCELLED");
|
|
3324
|
+
reject(new Error("WHEN_CANCELLED"));
|
|
3320
3325
|
};
|
|
3321
3326
|
});
|
|
3322
3327
|
res.cancel = cancel;
|
|
@@ -3447,7 +3452,11 @@ function makeObservable(target, annotations, options) {
|
|
|
3447
3452
|
try {
|
|
3448
3453
|
var _annotations;
|
|
3449
3454
|
|
|
3450
|
-
|
|
3455
|
+
if ("development" !== "production" && annotations && target[storedAnnotationsSymbol]) {
|
|
3456
|
+
die("makeObservable second arg must be nullish when using decorators. Mixing @decorator syntax with annotations is not supported.");
|
|
3457
|
+
} // Default to decorators
|
|
3458
|
+
|
|
3459
|
+
|
|
3451
3460
|
(_annotations = annotations) != null ? _annotations : annotations = collectStoredAnnotations(target); // Annotate
|
|
3452
3461
|
|
|
3453
3462
|
ownKeys(annotations).forEach(function (key) {
|
|
@@ -3608,7 +3617,7 @@ var ObservableArrayAdministration = /*#__PURE__*/function () {
|
|
|
3608
3617
|
};
|
|
3609
3618
|
|
|
3610
3619
|
_proto.setArrayLength_ = function setArrayLength_(newLength) {
|
|
3611
|
-
if (typeof newLength !== "number" || newLength < 0) die("Out of range: " + newLength);
|
|
3620
|
+
if (typeof newLength !== "number" || isNaN(newLength) || newLength < 0) die("Out of range: " + newLength);
|
|
3612
3621
|
var currentLength = this.values_.length;
|
|
3613
3622
|
if (newLength === currentLength) return;else if (newLength > currentLength) {
|
|
3614
3623
|
var newItems = new Array(newLength - currentLength);
|
|
@@ -4097,9 +4106,11 @@ var ObservableMap = /*#__PURE__*/function () {
|
|
|
4097
4106
|
|
|
4098
4107
|
if ( notifySpy) spyReportStart(_change);
|
|
4099
4108
|
transaction(function () {
|
|
4109
|
+
var _this2$hasMap_$get;
|
|
4110
|
+
|
|
4100
4111
|
_this2.keysAtom_.reportChanged();
|
|
4101
4112
|
|
|
4102
|
-
_this2.
|
|
4113
|
+
(_this2$hasMap_$get = _this2.hasMap_.get(key)) == null ? void 0 : _this2$hasMap_$get.setNewValue_(false);
|
|
4103
4114
|
|
|
4104
4115
|
var observable = _this2.data_.get(key);
|
|
4105
4116
|
|
|
@@ -4115,14 +4126,6 @@ var ObservableMap = /*#__PURE__*/function () {
|
|
|
4115
4126
|
return false;
|
|
4116
4127
|
};
|
|
4117
4128
|
|
|
4118
|
-
_proto.updateHasMapEntry_ = function updateHasMapEntry_(key, value) {
|
|
4119
|
-
var entry = this.hasMap_.get(key);
|
|
4120
|
-
|
|
4121
|
-
if (entry) {
|
|
4122
|
-
entry.setNewValue_(value);
|
|
4123
|
-
}
|
|
4124
|
-
};
|
|
4125
|
-
|
|
4126
4129
|
_proto.updateValue_ = function updateValue_(key, newValue) {
|
|
4127
4130
|
var observable = this.data_.get(key);
|
|
4128
4131
|
newValue = observable.prepareNewValue_(newValue);
|
|
@@ -4151,13 +4154,15 @@ var ObservableMap = /*#__PURE__*/function () {
|
|
|
4151
4154
|
|
|
4152
4155
|
checkIfStateModificationsAreAllowed(this.keysAtom_);
|
|
4153
4156
|
transaction(function () {
|
|
4157
|
+
var _this3$hasMap_$get;
|
|
4158
|
+
|
|
4154
4159
|
var observable = new ObservableValue(newValue, _this3.enhancer_, _this3.name_ + "." + stringifyKey(key) , false);
|
|
4155
4160
|
|
|
4156
4161
|
_this3.data_.set(key, observable);
|
|
4157
4162
|
|
|
4158
4163
|
newValue = observable.value_; // value might have been changed
|
|
4159
4164
|
|
|
4160
|
-
_this3.
|
|
4165
|
+
(_this3$hasMap_$get = _this3.hasMap_.get(key)) == null ? void 0 : _this3$hasMap_$get.setNewValue_(true);
|
|
4161
4166
|
|
|
4162
4167
|
_this3.keysAtom_.reportChanged();
|
|
4163
4168
|
});
|
|
@@ -5734,7 +5739,7 @@ function isAnnotation(thing) {
|
|
|
5734
5739
|
* - utils/ Utility stuff.
|
|
5735
5740
|
*
|
|
5736
5741
|
*/
|
|
5737
|
-
["Symbol", "Map", "Set"
|
|
5742
|
+
["Symbol", "Map", "Set"].forEach(function (m) {
|
|
5738
5743
|
var g = getGlobal();
|
|
5739
5744
|
|
|
5740
5745
|
if (typeof g[m] === "undefined") {
|