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
|
@@ -516,7 +516,8 @@
|
|
|
516
516
|
}
|
|
517
517
|
|
|
518
518
|
function defaultComparer(a, b) {
|
|
519
|
-
return Object.is(a, b);
|
|
519
|
+
if (Object.is) return Object.is(a, b);
|
|
520
|
+
return a === b ? a !== 0 || 1 / a === 1 / b : a !== a && b !== b;
|
|
520
521
|
}
|
|
521
522
|
|
|
522
523
|
var comparer = {
|
|
@@ -676,7 +677,7 @@
|
|
|
676
677
|
|
|
677
678
|
function createActionDescriptor(adm, annotation, key, descriptor, // provides ability to disable safeDescriptors for prototypes
|
|
678
679
|
safeDescriptors) {
|
|
679
|
-
var _annotation$options_, _annotation$options_$, _annotation$options_2, _annotation$options_$2, _annotation$options_3;
|
|
680
|
+
var _annotation$options_, _annotation$options_$, _annotation$options_2, _annotation$options_$2, _annotation$options_3, _annotation$options_4, _adm$proxy_2;
|
|
680
681
|
|
|
681
682
|
if (safeDescriptors === void 0) {
|
|
682
683
|
safeDescriptors = globalState.safeDescriptors;
|
|
@@ -692,7 +693,8 @@
|
|
|
692
693
|
}
|
|
693
694
|
|
|
694
695
|
return {
|
|
695
|
-
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
|
|
696
|
+
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
|
|
697
|
+
((_annotation$options_4 = annotation.options_) == null ? void 0 : _annotation$options_4.bound) ? (_adm$proxy_2 = adm.proxy_) != null ? _adm$proxy_2 : adm.target_ : undefined),
|
|
696
698
|
// Non-configurable for classes
|
|
697
699
|
// prevents accidental field redefinition in subclass
|
|
698
700
|
configurable: safeDescriptors ? adm.isPlainObject_ : true,
|
|
@@ -961,6 +963,10 @@
|
|
|
961
963
|
return observableAnnotation.extend_(adm, key, descriptor, proxyTrap);
|
|
962
964
|
}
|
|
963
965
|
|
|
966
|
+
var OBSERVABLE = "observable";
|
|
967
|
+
var OBSERVABLE_REF = "observable.ref";
|
|
968
|
+
var OBSERVABLE_SHALLOW = "observable.shallow";
|
|
969
|
+
var OBSERVABLE_STRUCT = "observable.struct"; // Predefined bags of create observable options, to avoid allocating temporarily option objects
|
|
964
970
|
// in the majority of cases
|
|
965
971
|
|
|
966
972
|
var defaultCreateObservableOptions = {
|
|
@@ -973,14 +979,14 @@
|
|
|
973
979
|
function asCreateObservableOptions(thing) {
|
|
974
980
|
return thing || defaultCreateObservableOptions;
|
|
975
981
|
}
|
|
976
|
-
var observableAnnotation = /*#__PURE__*/createObservableAnnotation(
|
|
977
|
-
var observableRefAnnotation = /*#__PURE__*/createObservableAnnotation(
|
|
982
|
+
var observableAnnotation = /*#__PURE__*/createObservableAnnotation(OBSERVABLE);
|
|
983
|
+
var observableRefAnnotation = /*#__PURE__*/createObservableAnnotation(OBSERVABLE_REF, {
|
|
978
984
|
enhancer: referenceEnhancer
|
|
979
985
|
});
|
|
980
|
-
var observableShallowAnnotation = /*#__PURE__*/createObservableAnnotation(
|
|
986
|
+
var observableShallowAnnotation = /*#__PURE__*/createObservableAnnotation(OBSERVABLE_SHALLOW, {
|
|
981
987
|
enhancer: shallowEnhancer
|
|
982
988
|
});
|
|
983
|
-
var observableStructAnnotation = /*#__PURE__*/createObservableAnnotation(
|
|
989
|
+
var observableStructAnnotation = /*#__PURE__*/createObservableAnnotation(OBSERVABLE_STRUCT, {
|
|
984
990
|
enhancer: refStructEnhancer
|
|
985
991
|
});
|
|
986
992
|
var observableDecoratorAnnotation = /*#__PURE__*/createDecoratorAnnotation(observableAnnotation);
|
|
@@ -1535,22 +1541,21 @@
|
|
|
1535
1541
|
/* see #1208 */
|
|
1536
1542
|
this.dependenciesState_ === IDerivationState_.NOT_TRACKING_;
|
|
1537
1543
|
var newValue = this.computeValue_(true);
|
|
1538
|
-
|
|
1539
|
-
if ( isSpyEnabled()) {
|
|
1540
|
-
spyReport({
|
|
1541
|
-
observableKind: "computed",
|
|
1542
|
-
debugObjectName: this.name_,
|
|
1543
|
-
object: this.scope_,
|
|
1544
|
-
type: "update",
|
|
1545
|
-
oldValue: this.value_,
|
|
1546
|
-
newValue: newValue
|
|
1547
|
-
});
|
|
1548
|
-
}
|
|
1549
|
-
|
|
1550
1544
|
var changed = wasSuspended || isCaughtException(oldValue) || isCaughtException(newValue) || !this.equals_(oldValue, newValue);
|
|
1551
1545
|
|
|
1552
1546
|
if (changed) {
|
|
1553
1547
|
this.value_ = newValue;
|
|
1548
|
+
|
|
1549
|
+
if ( isSpyEnabled()) {
|
|
1550
|
+
spyReport({
|
|
1551
|
+
observableKind: "computed",
|
|
1552
|
+
debugObjectName: this.name_,
|
|
1553
|
+
object: this.scope_,
|
|
1554
|
+
type: "update",
|
|
1555
|
+
oldValue: oldValue,
|
|
1556
|
+
newValue: newValue
|
|
1557
|
+
});
|
|
1558
|
+
}
|
|
1554
1559
|
}
|
|
1555
1560
|
|
|
1556
1561
|
return changed;
|
|
@@ -1585,6 +1590,10 @@
|
|
|
1585
1590
|
if (!this.keepAlive_) {
|
|
1586
1591
|
clearObserving(this);
|
|
1587
1592
|
this.value_ = undefined; // don't hold on to computed value!
|
|
1593
|
+
|
|
1594
|
+
if ( this.isTracing_ !== TraceMode.NONE) {
|
|
1595
|
+
console.log("[mobx.trace] Computed value '" + this.name_ + "' was suspended and it will recompute on the next access.");
|
|
1596
|
+
}
|
|
1588
1597
|
}
|
|
1589
1598
|
};
|
|
1590
1599
|
|
|
@@ -1617,16 +1626,12 @@
|
|
|
1617
1626
|
|
|
1618
1627
|
_proto.warnAboutUntrackedRead_ = function warnAboutUntrackedRead_() {
|
|
1619
1628
|
|
|
1620
|
-
if (this.requiresReaction_ === true) {
|
|
1621
|
-
die("[mobx] Computed value " + this.name_ + " is read outside a reactive context");
|
|
1622
|
-
}
|
|
1623
|
-
|
|
1624
1629
|
if (this.isTracing_ !== TraceMode.NONE) {
|
|
1625
|
-
console.log("[mobx.trace] '" + this.name_ + "' is being read outside a reactive context. Doing a full recompute");
|
|
1630
|
+
console.log("[mobx.trace] Computed value '" + this.name_ + "' is being read outside a reactive context. Doing a full recompute.");
|
|
1626
1631
|
}
|
|
1627
1632
|
|
|
1628
|
-
if (globalState.computedRequiresReaction) {
|
|
1629
|
-
console.warn("[mobx] Computed value " + this.name_ + " is being read outside a reactive context. Doing a full recompute");
|
|
1633
|
+
if (globalState.computedRequiresReaction || this.requiresReaction_) {
|
|
1634
|
+
console.warn("[mobx] Computed value '" + this.name_ + "' is being read outside a reactive context. Doing a full recompute.");
|
|
1630
1635
|
}
|
|
1631
1636
|
};
|
|
1632
1637
|
|
|
@@ -1759,7 +1764,7 @@
|
|
|
1759
1764
|
}
|
|
1760
1765
|
function checkIfStateReadsAreAllowed(observable) {
|
|
1761
1766
|
if ( !globalState.allowStateReads && globalState.observableRequiresReaction) {
|
|
1762
|
-
console.warn("[mobx] Observable " + observable.name_ + " being read outside a reactive context");
|
|
1767
|
+
console.warn("[mobx] Observable '" + observable.name_ + "' being read outside a reactive context.");
|
|
1763
1768
|
}
|
|
1764
1769
|
}
|
|
1765
1770
|
/**
|
|
@@ -1803,7 +1808,7 @@
|
|
|
1803
1808
|
if (derivation.observing_.length !== 0) return;
|
|
1804
1809
|
|
|
1805
1810
|
if (globalState.reactionRequiresObservable || derivation.requiresObservable_) {
|
|
1806
|
-
console.warn("[mobx] Derivation " + derivation.name_ + " is created/updated without reading any observable value");
|
|
1811
|
+
console.warn("[mobx] Derivation '" + derivation.name_ + "' is created/updated without reading any observable value.");
|
|
1807
1812
|
}
|
|
1808
1813
|
}
|
|
1809
1814
|
/**
|
|
@@ -1969,6 +1974,8 @@
|
|
|
1969
1974
|
if (global.__mobxGlobals && global.__mobxGlobals.version !== new MobXGlobals().version) canMergeGlobalState = false;
|
|
1970
1975
|
|
|
1971
1976
|
if (!canMergeGlobalState) {
|
|
1977
|
+
// Because this is a IIFE we need to let isolateCalled a chance to change
|
|
1978
|
+
// so we run it after the event loop completed at least 1 iteration
|
|
1972
1979
|
setTimeout(function () {
|
|
1973
1980
|
if (!isolateCalled) {
|
|
1974
1981
|
die(35);
|
|
@@ -2216,8 +2223,7 @@
|
|
|
2216
2223
|
return;
|
|
2217
2224
|
}
|
|
2218
2225
|
|
|
2219
|
-
lines.push("" +
|
|
2220
|
-
|
|
2226
|
+
lines.push("" + "\t".repeat(depth - 1) + tree.name);
|
|
2221
2227
|
if (tree.dependencies) tree.dependencies.forEach(function (child) {
|
|
2222
2228
|
return printDepTree(child, lines, depth + 1);
|
|
2223
2229
|
});
|
|
@@ -2648,8 +2654,7 @@
|
|
|
2648
2654
|
var firstTime = true;
|
|
2649
2655
|
var isScheduled = false;
|
|
2650
2656
|
var value;
|
|
2651
|
-
var oldValue
|
|
2652
|
-
|
|
2657
|
+
var oldValue;
|
|
2653
2658
|
var equals = opts.compareStructural ? comparer.structural : opts.equals || comparer["default"];
|
|
2654
2659
|
var r = new Reaction(name, function () {
|
|
2655
2660
|
if (firstTime || runSync) {
|
|
@@ -2765,7 +2770,7 @@
|
|
|
2765
2770
|
if (arguments.length > 4) die("'extendObservable' expected 2-4 arguments");
|
|
2766
2771
|
if (typeof target !== "object") die("'extendObservable' expects an object as first argument");
|
|
2767
2772
|
if (isObservableMap(target)) die("'extendObservable' should not be used on maps, use map.merge instead");
|
|
2768
|
-
if (!isPlainObject(properties)) die("'
|
|
2773
|
+
if (!isPlainObject(properties)) die("'extendObservable' only accepts plain objects as second argument");
|
|
2769
2774
|
if (isObservable(properties) || isObservable(annotations)) die("Extending an object with another observable (object) is not supported");
|
|
2770
2775
|
} // Pull descriptors first, so we don't have to deal with props added by administration ($mobx)
|
|
2771
2776
|
|
|
@@ -2956,14 +2961,14 @@
|
|
|
2956
2961
|
}
|
|
2957
2962
|
|
|
2958
2963
|
function _isComputed(value, property) {
|
|
2959
|
-
if (property
|
|
2960
|
-
|
|
2961
|
-
if (!value[$mobx].values_.has(property)) return false;
|
|
2962
|
-
var atom = getAtom(value, property);
|
|
2963
|
-
return isComputedValue(atom);
|
|
2964
|
+
if (property === undefined) {
|
|
2965
|
+
return isComputedValue(value);
|
|
2964
2966
|
}
|
|
2965
2967
|
|
|
2966
|
-
|
|
2968
|
+
if (isObservableObject(value) === false) return false;
|
|
2969
|
+
if (!value[$mobx].values_.has(property)) return false;
|
|
2970
|
+
var atom = getAtom(value, property);
|
|
2971
|
+
return isComputedValue(atom);
|
|
2967
2972
|
}
|
|
2968
2973
|
function isComputed(value) {
|
|
2969
2974
|
if ( arguments.length > 1) return die("isComputed expects only 1 argument. Use isComputedProp to inspect the observability of a property");
|
|
@@ -3287,10 +3292,10 @@
|
|
|
3287
3292
|
var timeoutHandle;
|
|
3288
3293
|
|
|
3289
3294
|
if (typeof opts.timeout === "number") {
|
|
3295
|
+
var error = new Error("WHEN_TIMEOUT");
|
|
3290
3296
|
timeoutHandle = setTimeout(function () {
|
|
3291
3297
|
if (!disposer[$mobx].isDisposed_) {
|
|
3292
3298
|
disposer();
|
|
3293
|
-
var error = new Error("WHEN_TIMEOUT");
|
|
3294
3299
|
if (opts.onError) opts.onError(error);else throw error;
|
|
3295
3300
|
}
|
|
3296
3301
|
}, opts.timeout);
|
|
@@ -3322,7 +3327,7 @@
|
|
|
3322
3327
|
|
|
3323
3328
|
cancel = function cancel() {
|
|
3324
3329
|
disposer();
|
|
3325
|
-
reject("WHEN_CANCELLED");
|
|
3330
|
+
reject(new Error("WHEN_CANCELLED"));
|
|
3326
3331
|
};
|
|
3327
3332
|
});
|
|
3328
3333
|
res.cancel = cancel;
|
|
@@ -3453,7 +3458,11 @@
|
|
|
3453
3458
|
try {
|
|
3454
3459
|
var _annotations;
|
|
3455
3460
|
|
|
3456
|
-
|
|
3461
|
+
if ("development" !== "production" && annotations && target[storedAnnotationsSymbol]) {
|
|
3462
|
+
die("makeObservable second arg must be nullish when using decorators. Mixing @decorator syntax with annotations is not supported.");
|
|
3463
|
+
} // Default to decorators
|
|
3464
|
+
|
|
3465
|
+
|
|
3457
3466
|
(_annotations = annotations) != null ? _annotations : annotations = collectStoredAnnotations(target); // Annotate
|
|
3458
3467
|
|
|
3459
3468
|
ownKeys(annotations).forEach(function (key) {
|
|
@@ -3614,7 +3623,7 @@
|
|
|
3614
3623
|
};
|
|
3615
3624
|
|
|
3616
3625
|
_proto.setArrayLength_ = function setArrayLength_(newLength) {
|
|
3617
|
-
if (typeof newLength !== "number" || newLength < 0) die("Out of range: " + newLength);
|
|
3626
|
+
if (typeof newLength !== "number" || isNaN(newLength) || newLength < 0) die("Out of range: " + newLength);
|
|
3618
3627
|
var currentLength = this.values_.length;
|
|
3619
3628
|
if (newLength === currentLength) return;else if (newLength > currentLength) {
|
|
3620
3629
|
var newItems = new Array(newLength - currentLength);
|
|
@@ -4103,9 +4112,11 @@
|
|
|
4103
4112
|
|
|
4104
4113
|
if ( notifySpy) spyReportStart(_change);
|
|
4105
4114
|
transaction(function () {
|
|
4115
|
+
var _this2$hasMap_$get;
|
|
4116
|
+
|
|
4106
4117
|
_this2.keysAtom_.reportChanged();
|
|
4107
4118
|
|
|
4108
|
-
_this2.
|
|
4119
|
+
(_this2$hasMap_$get = _this2.hasMap_.get(key)) == null ? void 0 : _this2$hasMap_$get.setNewValue_(false);
|
|
4109
4120
|
|
|
4110
4121
|
var observable = _this2.data_.get(key);
|
|
4111
4122
|
|
|
@@ -4121,14 +4132,6 @@
|
|
|
4121
4132
|
return false;
|
|
4122
4133
|
};
|
|
4123
4134
|
|
|
4124
|
-
_proto.updateHasMapEntry_ = function updateHasMapEntry_(key, value) {
|
|
4125
|
-
var entry = this.hasMap_.get(key);
|
|
4126
|
-
|
|
4127
|
-
if (entry) {
|
|
4128
|
-
entry.setNewValue_(value);
|
|
4129
|
-
}
|
|
4130
|
-
};
|
|
4131
|
-
|
|
4132
4135
|
_proto.updateValue_ = function updateValue_(key, newValue) {
|
|
4133
4136
|
var observable = this.data_.get(key);
|
|
4134
4137
|
newValue = observable.prepareNewValue_(newValue);
|
|
@@ -4157,13 +4160,15 @@
|
|
|
4157
4160
|
|
|
4158
4161
|
checkIfStateModificationsAreAllowed(this.keysAtom_);
|
|
4159
4162
|
transaction(function () {
|
|
4163
|
+
var _this3$hasMap_$get;
|
|
4164
|
+
|
|
4160
4165
|
var observable = new ObservableValue(newValue, _this3.enhancer_, _this3.name_ + "." + stringifyKey(key) , false);
|
|
4161
4166
|
|
|
4162
4167
|
_this3.data_.set(key, observable);
|
|
4163
4168
|
|
|
4164
4169
|
newValue = observable.value_; // value might have been changed
|
|
4165
4170
|
|
|
4166
|
-
_this3.
|
|
4171
|
+
(_this3$hasMap_$get = _this3.hasMap_.get(key)) == null ? void 0 : _this3$hasMap_$get.setNewValue_(true);
|
|
4167
4172
|
|
|
4168
4173
|
_this3.keysAtom_.reportChanged();
|
|
4169
4174
|
});
|
|
@@ -5740,7 +5745,7 @@
|
|
|
5740
5745
|
* - utils/ Utility stuff.
|
|
5741
5746
|
*
|
|
5742
5747
|
*/
|
|
5743
|
-
["Symbol", "Map", "Set"
|
|
5748
|
+
["Symbol", "Map", "Set"].forEach(function (m) {
|
|
5744
5749
|
var g = getGlobal();
|
|
5745
5750
|
|
|
5746
5751
|
if (typeof g[m] === "undefined") {
|