mobx 6.3.3 → 6.3.7
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 +26 -0
- package/README.md +1 -1
- package/dist/api/autorun.d.ts +3 -3
- package/dist/api/intercept.d.ts +4 -4
- package/dist/api/observe.d.ts +3 -3
- package/dist/mobx.cjs.development.js +38 -38
- 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 +38 -38
- package/dist/mobx.esm.development.js.map +1 -1
- package/dist/mobx.esm.js +38 -38
- 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 +38 -38
- 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 +15 -8
- package/src/api/extendobservable.ts +1 -1
- package/src/api/intercept.ts +4 -4
- package/src/api/iscomputed.ts +6 -6
- package/src/api/makeObservable.ts +7 -1
- package/src/api/observe.ts +4 -3
- package/src/api/when.ts +1 -1
- package/src/core/computedvalue.ts +11 -11
- package/src/core/globalstate.ts +2 -0
- package/src/core/observable.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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# mobx
|
|
2
2
|
|
|
3
|
+
## 6.3.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`3a7dee6f`](https://github.com/mobxjs/mobx/commit/3a7dee6fdaddbb4b79205b054601a8020c226fcc) [#3180](https://github.com/mobxjs/mobx/pull/3180) Thanks [@kubk](https://github.com/kubk)! - Fix type inference of observe function
|
|
8
|
+
|
|
9
|
+
## 6.3.6
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [`49468204`](https://github.com/mobxjs/mobx/commit/49468204d3bc28d15dbf383c0b7f874ca26dff30) [#3162](https://github.com/mobxjs/mobx/pull/3162) Thanks [@upsuper](https://github.com/upsuper)! - Have cancelled when reject with an error rather than a string
|
|
14
|
+
|
|
15
|
+
* [`4afb1ec2`](https://github.com/mobxjs/mobx/commit/4afb1ec24427cf8e1f768d0c6fc49d0f44f4ab8e) [#3154](https://github.com/mobxjs/mobx/pull/3154) Thanks [@urugator](https://github.com/urugator)! - `makeObservable` throws when mixing @decorator syntax with annotations
|
|
16
|
+
|
|
17
|
+
## 6.3.5
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- [`4ac6b454`](https://github.com/mobxjs/mobx/commit/4ac6b45473c2e3b07c8e683cd395bc5edfaa8e15) [#3146](https://github.com/mobxjs/mobx/pull/3146) Thanks [@urugator](https://github.com/urugator)! - fix #3109: spy: computed shouldn't report update unless the value changed
|
|
22
|
+
|
|
23
|
+
## 6.3.4
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- [`0dbf3eb6`](https://github.com/mobxjs/mobx/commit/0dbf3eb6eecfa9cd6cd9dc7d707e8d70927e79bf) [#3141](https://github.com/mobxjs/mobx/pull/3141) Thanks [@urugator](https://github.com/urugator)! - [spy: bound actions report correct object](https://github.com/mobxjs/mobx/discussions/3140)
|
|
28
|
+
|
|
3
29
|
## 6.3.3
|
|
4
30
|
|
|
5
31
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -136,7 +136,7 @@ Changes in the observable state are propagated precisely to all _computations_ a
|
|
|
136
136
|
|
|
137
137
|
This conceptual picture can be applied to the above example, or any other application using MobX.
|
|
138
138
|
|
|
139
|
-
To learn about the core concepts of MobX using a larger example, check out [The gist of MobX](
|
|
139
|
+
To learn about the core concepts of MobX using a larger example, check out [The gist of MobX](https://mobx.js.org/the-gist-of-mobx.html) section, or take the [10 minute interactive introduction to MobX and React](https://mobx.js.org/getting-started).
|
|
140
140
|
The philosophy and benefits of the mental model provided by MobX are also described in great detail in the blog posts [UI as an afterthought](https://michel.codes/blogs/ui-as-an-afterthought) and [How to decouple state and UI (a.k.a. you don’t need componentWillMount)](https://hackernoon.com/how-to-decouple-state-and-ui-a-k-a-you-dont-need-componentwillmount-cc90b787aa37).
|
|
141
141
|
|
|
142
142
|
<div class="cheat"><a href="https://gum.co/fSocU"><button title="Download the MobX 6 cheat sheet and sponsor the project">Download the MobX 6 cheat sheet</button></a></div>
|
package/dist/api/autorun.d.ts
CHANGED
|
@@ -17,8 +17,8 @@ export interface IAutorunOptions {
|
|
|
17
17
|
* @returns disposer function, which can be used to stop the view from being updated in the future.
|
|
18
18
|
*/
|
|
19
19
|
export declare function autorun(view: (r: IReactionPublic) => any, opts?: IAutorunOptions): IReactionDisposer;
|
|
20
|
-
export declare type IReactionOptions<T> = IAutorunOptions & {
|
|
21
|
-
fireImmediately?:
|
|
20
|
+
export declare type IReactionOptions<T, FireImmediately extends boolean> = IAutorunOptions & {
|
|
21
|
+
fireImmediately?: FireImmediately;
|
|
22
22
|
equals?: IEqualsComparer<T>;
|
|
23
23
|
};
|
|
24
|
-
export declare function reaction<T>(expression: (r: IReactionPublic) => T, effect: (arg: T, prev: T, r: IReactionPublic) => void, opts?: IReactionOptions<T>): IReactionDisposer;
|
|
24
|
+
export declare function reaction<T, FireImmediately extends boolean = false>(expression: (r: IReactionPublic) => T, effect: (arg: T, prev: FireImmediately extends true ? T | undefined : T, r: IReactionPublic) => void, opts?: IReactionOptions<T, FireImmediately>): IReactionDisposer;
|
package/dist/api/intercept.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { IArrayWillChange, IArrayWillSplice, IInterceptor, IMapWillChange, IObjectWillChange, IObservableArray, IObservableValue, IValueWillChange, Lambda, ObservableMap, ObservableSet, ISetWillChange } from "../internal";
|
|
2
2
|
export declare function intercept<T>(value: IObservableValue<T>, handler: IInterceptor<IValueWillChange<T>>): Lambda;
|
|
3
3
|
export declare function intercept<T>(observableArray: IObservableArray<T>, handler: IInterceptor<IArrayWillChange<T> | IArrayWillSplice<T>>): Lambda;
|
|
4
|
-
export declare function intercept<K, V>(observableMap: ObservableMap<K, V>, handler: IInterceptor<IMapWillChange<K, V>>): Lambda;
|
|
5
|
-
export declare function intercept<V>(
|
|
6
|
-
export declare function intercept<K, V>(observableMap: ObservableMap<K, V>, property: K, handler: IInterceptor<IValueWillChange<V>>): Lambda;
|
|
4
|
+
export declare function intercept<K, V>(observableMap: ObservableMap<K, V> | Map<K, V>, handler: IInterceptor<IMapWillChange<K, V>>): Lambda;
|
|
5
|
+
export declare function intercept<V>(observableSet: ObservableSet<V> | Set<V>, handler: IInterceptor<ISetWillChange<V>>): Lambda;
|
|
6
|
+
export declare function intercept<K, V>(observableMap: ObservableMap<K, V> | Map<K, V>, property: K, handler: IInterceptor<IValueWillChange<V>>): Lambda;
|
|
7
7
|
export declare function intercept(object: object, handler: IInterceptor<IObjectWillChange>): Lambda;
|
|
8
|
-
export declare function intercept<T extends object, K extends keyof T>(object: T, property: K, handler: IInterceptor<IValueWillChange<
|
|
8
|
+
export declare function intercept<T extends object, K extends keyof T>(object: T, property: K, handler: IInterceptor<IValueWillChange<T[K]>>): Lambda;
|
package/dist/api/observe.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { IArrayDidChange, IComputedValue, IMapDidChange, IObjectDidChange, IObservableArray, IObservableValue, IValueDidChange, Lambda, ObservableMap, ObservableSet, ISetDidChange } from "../internal";
|
|
2
2
|
export declare function observe<T>(value: IObservableValue<T> | IComputedValue<T>, listener: (change: IValueDidChange<T>) => void, fireImmediately?: boolean): Lambda;
|
|
3
3
|
export declare function observe<T>(observableArray: IObservableArray<T>, listener: (change: IArrayDidChange<T>) => void, fireImmediately?: boolean): Lambda;
|
|
4
|
-
export declare function observe<V>(
|
|
5
|
-
export declare function observe<K, V>(observableMap: ObservableMap<K, V>, listener: (change: IMapDidChange<K, V>) => void, fireImmediately?: boolean): Lambda;
|
|
6
|
-
export declare function observe<K, V>(observableMap: ObservableMap<K, V>, property: K, listener: (change: IValueDidChange<V>) => void, fireImmediately?: boolean): Lambda;
|
|
4
|
+
export declare function observe<V>(observableSet: ObservableSet<V> | Set<V>, listener: (change: ISetDidChange<V>) => void, fireImmediately?: boolean): Lambda;
|
|
5
|
+
export declare function observe<K, V>(observableMap: ObservableMap<K, V> | Map<K, V>, listener: (change: IMapDidChange<K, V>) => void, fireImmediately?: boolean): Lambda;
|
|
6
|
+
export declare function observe<K, V>(observableMap: ObservableMap<K, V> | Map<K, V>, property: K, listener: (change: IValueDidChange<V>) => void, fireImmediately?: boolean): Lambda;
|
|
7
7
|
export declare function observe(object: Object, listener: (change: IObjectDidChange) => void, fireImmediately?: boolean): Lambda;
|
|
8
8
|
export declare function observe<T, K extends keyof T>(object: T, property: K, listener: (change: IValueDidChange<T[K]>) => void, fireImmediately?: boolean): Lambda;
|
|
@@ -675,7 +675,7 @@ function assertActionDescriptor(adm, _ref, key, _ref2) {
|
|
|
675
675
|
|
|
676
676
|
function createActionDescriptor(adm, annotation, key, descriptor, // provides ability to disable safeDescriptors for prototypes
|
|
677
677
|
safeDescriptors) {
|
|
678
|
-
var _annotation$options_, _annotation$options_$, _annotation$options_2, _annotation$options_$2, _annotation$options_3;
|
|
678
|
+
var _annotation$options_, _annotation$options_$, _annotation$options_2, _annotation$options_$2, _annotation$options_3, _annotation$options_4, _adm$proxy_2;
|
|
679
679
|
|
|
680
680
|
if (safeDescriptors === void 0) {
|
|
681
681
|
safeDescriptors = globalState.safeDescriptors;
|
|
@@ -691,7 +691,8 @@ safeDescriptors) {
|
|
|
691
691
|
}
|
|
692
692
|
|
|
693
693
|
return {
|
|
694
|
-
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
|
|
694
|
+
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
|
|
695
|
+
((_annotation$options_4 = annotation.options_) == null ? void 0 : _annotation$options_4.bound) ? (_adm$proxy_2 = adm.proxy_) != null ? _adm$proxy_2 : adm.target_ : undefined),
|
|
695
696
|
// Non-configurable for classes
|
|
696
697
|
// prevents accidental field redefinition in subclass
|
|
697
698
|
configurable: safeDescriptors ? adm.isPlainObject_ : true,
|
|
@@ -1538,22 +1539,21 @@ var ComputedValue = /*#__PURE__*/function () {
|
|
|
1538
1539
|
/* see #1208 */
|
|
1539
1540
|
this.dependenciesState_ === IDerivationState_.NOT_TRACKING_;
|
|
1540
1541
|
var newValue = this.computeValue_(true);
|
|
1541
|
-
|
|
1542
|
-
if ( isSpyEnabled()) {
|
|
1543
|
-
spyReport({
|
|
1544
|
-
observableKind: "computed",
|
|
1545
|
-
debugObjectName: this.name_,
|
|
1546
|
-
object: this.scope_,
|
|
1547
|
-
type: "update",
|
|
1548
|
-
oldValue: this.value_,
|
|
1549
|
-
newValue: newValue
|
|
1550
|
-
});
|
|
1551
|
-
}
|
|
1552
|
-
|
|
1553
1542
|
var changed = wasSuspended || isCaughtException(oldValue) || isCaughtException(newValue) || !this.equals_(oldValue, newValue);
|
|
1554
1543
|
|
|
1555
1544
|
if (changed) {
|
|
1556
1545
|
this.value_ = newValue;
|
|
1546
|
+
|
|
1547
|
+
if ( isSpyEnabled()) {
|
|
1548
|
+
spyReport({
|
|
1549
|
+
observableKind: "computed",
|
|
1550
|
+
debugObjectName: this.name_,
|
|
1551
|
+
object: this.scope_,
|
|
1552
|
+
type: "update",
|
|
1553
|
+
oldValue: oldValue,
|
|
1554
|
+
newValue: newValue
|
|
1555
|
+
});
|
|
1556
|
+
}
|
|
1557
1557
|
}
|
|
1558
1558
|
|
|
1559
1559
|
return changed;
|
|
@@ -1972,6 +1972,8 @@ var globalState = /*#__PURE__*/function () {
|
|
|
1972
1972
|
if (global.__mobxGlobals && global.__mobxGlobals.version !== new MobXGlobals().version) canMergeGlobalState = false;
|
|
1973
1973
|
|
|
1974
1974
|
if (!canMergeGlobalState) {
|
|
1975
|
+
// Because this is a IIFE we need to let isolateCalled a chance to change
|
|
1976
|
+
// so we run it after the event loop completed at least 1 iteration
|
|
1975
1977
|
setTimeout(function () {
|
|
1976
1978
|
if (!isolateCalled) {
|
|
1977
1979
|
die(35);
|
|
@@ -2219,8 +2221,7 @@ function printDepTree(tree, lines, depth) {
|
|
|
2219
2221
|
return;
|
|
2220
2222
|
}
|
|
2221
2223
|
|
|
2222
|
-
lines.push("" +
|
|
2223
|
-
|
|
2224
|
+
lines.push("" + "\t".repeat(depth - 1) + tree.name);
|
|
2224
2225
|
if (tree.dependencies) tree.dependencies.forEach(function (child) {
|
|
2225
2226
|
return printDepTree(child, lines, depth + 1);
|
|
2226
2227
|
});
|
|
@@ -2651,8 +2652,7 @@ function reaction(expression, effect, opts) {
|
|
|
2651
2652
|
var firstTime = true;
|
|
2652
2653
|
var isScheduled = false;
|
|
2653
2654
|
var value;
|
|
2654
|
-
var oldValue
|
|
2655
|
-
|
|
2655
|
+
var oldValue;
|
|
2656
2656
|
var equals = opts.compareStructural ? comparer.structural : opts.equals || comparer["default"];
|
|
2657
2657
|
var r = new Reaction(name, function () {
|
|
2658
2658
|
if (firstTime || runSync) {
|
|
@@ -2768,7 +2768,7 @@ function extendObservable(target, properties, annotations, options) {
|
|
|
2768
2768
|
if (arguments.length > 4) die("'extendObservable' expected 2-4 arguments");
|
|
2769
2769
|
if (typeof target !== "object") die("'extendObservable' expects an object as first argument");
|
|
2770
2770
|
if (isObservableMap(target)) die("'extendObservable' should not be used on maps, use map.merge instead");
|
|
2771
|
-
if (!isPlainObject(properties)) die("'
|
|
2771
|
+
if (!isPlainObject(properties)) die("'extendObservable' only accepts plain objects as second argument");
|
|
2772
2772
|
if (isObservable(properties) || isObservable(annotations)) die("Extending an object with another observable (object) is not supported");
|
|
2773
2773
|
} // Pull descriptors first, so we don't have to deal with props added by administration ($mobx)
|
|
2774
2774
|
|
|
@@ -2959,14 +2959,14 @@ function interceptProperty(thing, property, handler) {
|
|
|
2959
2959
|
}
|
|
2960
2960
|
|
|
2961
2961
|
function _isComputed(value, property) {
|
|
2962
|
-
if (property
|
|
2963
|
-
|
|
2964
|
-
if (!value[$mobx].values_.has(property)) return false;
|
|
2965
|
-
var atom = getAtom(value, property);
|
|
2966
|
-
return isComputedValue(atom);
|
|
2962
|
+
if (property === undefined) {
|
|
2963
|
+
return isComputedValue(value);
|
|
2967
2964
|
}
|
|
2968
2965
|
|
|
2969
|
-
|
|
2966
|
+
if (isObservableObject(value) === false) return false;
|
|
2967
|
+
if (!value[$mobx].values_.has(property)) return false;
|
|
2968
|
+
var atom = getAtom(value, property);
|
|
2969
|
+
return isComputedValue(atom);
|
|
2970
2970
|
}
|
|
2971
2971
|
function isComputed(value) {
|
|
2972
2972
|
if ( arguments.length > 1) return die("isComputed expects only 1 argument. Use isComputedProp to inspect the observability of a property");
|
|
@@ -3325,7 +3325,7 @@ function whenPromise(predicate, opts) {
|
|
|
3325
3325
|
|
|
3326
3326
|
cancel = function cancel() {
|
|
3327
3327
|
disposer();
|
|
3328
|
-
reject("WHEN_CANCELLED");
|
|
3328
|
+
reject(new Error("WHEN_CANCELLED"));
|
|
3329
3329
|
};
|
|
3330
3330
|
});
|
|
3331
3331
|
res.cancel = cancel;
|
|
@@ -3456,7 +3456,11 @@ function makeObservable(target, annotations, options) {
|
|
|
3456
3456
|
try {
|
|
3457
3457
|
var _annotations;
|
|
3458
3458
|
|
|
3459
|
-
|
|
3459
|
+
if ("development" !== "production" && annotations && target[storedAnnotationsSymbol]) {
|
|
3460
|
+
die("makeObservable second arg must be nullish when using decorators. Mixing @decorator syntax with annotations is not supported.");
|
|
3461
|
+
} // Default to decorators
|
|
3462
|
+
|
|
3463
|
+
|
|
3460
3464
|
(_annotations = annotations) != null ? _annotations : annotations = collectStoredAnnotations(target); // Annotate
|
|
3461
3465
|
|
|
3462
3466
|
ownKeys(annotations).forEach(function (key) {
|
|
@@ -3617,7 +3621,7 @@ var ObservableArrayAdministration = /*#__PURE__*/function () {
|
|
|
3617
3621
|
};
|
|
3618
3622
|
|
|
3619
3623
|
_proto.setArrayLength_ = function setArrayLength_(newLength) {
|
|
3620
|
-
if (typeof newLength !== "number" || newLength < 0) die("Out of range: " + newLength);
|
|
3624
|
+
if (typeof newLength !== "number" || isNaN(newLength) || newLength < 0) die("Out of range: " + newLength);
|
|
3621
3625
|
var currentLength = this.values_.length;
|
|
3622
3626
|
if (newLength === currentLength) return;else if (newLength > currentLength) {
|
|
3623
3627
|
var newItems = new Array(newLength - currentLength);
|
|
@@ -4106,9 +4110,11 @@ var ObservableMap = /*#__PURE__*/function () {
|
|
|
4106
4110
|
|
|
4107
4111
|
if ( notifySpy) spyReportStart(_change);
|
|
4108
4112
|
transaction(function () {
|
|
4113
|
+
var _this2$hasMap_$get;
|
|
4114
|
+
|
|
4109
4115
|
_this2.keysAtom_.reportChanged();
|
|
4110
4116
|
|
|
4111
|
-
_this2.
|
|
4117
|
+
(_this2$hasMap_$get = _this2.hasMap_.get(key)) == null ? void 0 : _this2$hasMap_$get.setNewValue_(false);
|
|
4112
4118
|
|
|
4113
4119
|
var observable = _this2.data_.get(key);
|
|
4114
4120
|
|
|
@@ -4124,14 +4130,6 @@ var ObservableMap = /*#__PURE__*/function () {
|
|
|
4124
4130
|
return false;
|
|
4125
4131
|
};
|
|
4126
4132
|
|
|
4127
|
-
_proto.updateHasMapEntry_ = function updateHasMapEntry_(key, value) {
|
|
4128
|
-
var entry = this.hasMap_.get(key);
|
|
4129
|
-
|
|
4130
|
-
if (entry) {
|
|
4131
|
-
entry.setNewValue_(value);
|
|
4132
|
-
}
|
|
4133
|
-
};
|
|
4134
|
-
|
|
4135
4133
|
_proto.updateValue_ = function updateValue_(key, newValue) {
|
|
4136
4134
|
var observable = this.data_.get(key);
|
|
4137
4135
|
newValue = observable.prepareNewValue_(newValue);
|
|
@@ -4160,13 +4158,15 @@ var ObservableMap = /*#__PURE__*/function () {
|
|
|
4160
4158
|
|
|
4161
4159
|
checkIfStateModificationsAreAllowed(this.keysAtom_);
|
|
4162
4160
|
transaction(function () {
|
|
4161
|
+
var _this3$hasMap_$get;
|
|
4162
|
+
|
|
4163
4163
|
var observable = new ObservableValue(newValue, _this3.enhancer_, _this3.name_ + "." + stringifyKey(key) , false);
|
|
4164
4164
|
|
|
4165
4165
|
_this3.data_.set(key, observable);
|
|
4166
4166
|
|
|
4167
4167
|
newValue = observable.value_; // value might have been changed
|
|
4168
4168
|
|
|
4169
|
-
_this3.
|
|
4169
|
+
(_this3$hasMap_$get = _this3.hasMap_.get(key)) == null ? void 0 : _this3$hasMap_$get.setNewValue_(true);
|
|
4170
4170
|
|
|
4171
4171
|
_this3.keysAtom_.reportChanged();
|
|
4172
4172
|
});
|