mobx 6.9.1 → 6.10.1
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 +18 -0
- package/dist/api/autorun.d.ts +2 -1
- package/dist/api/makeObservable.d.ts +3 -2
- package/dist/api/when.d.ts +1 -8
- package/dist/core/atom.d.ts +2 -1
- package/dist/core/globalstate.d.ts +5 -0
- package/dist/core/reaction.d.ts +2 -2
- package/dist/internal.d.ts +1 -0
- package/dist/mobx.cjs.development.js +137 -85
- 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 +137 -85
- package/dist/mobx.esm.development.js.map +1 -1
- package/dist/mobx.esm.js +137 -85
- 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 +137 -85
- 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/generic-abort-signal.d.ts +6 -0
- package/dist/types/type-utils.d.ts +7 -0
- package/package.json +1 -1
- package/src/api/autorun.ts +11 -5
- package/src/api/extendobservable.ts +6 -9
- package/src/api/makeObservable.ts +22 -26
- package/src/api/observable.ts +10 -7
- package/src/api/when.ts +2 -9
- package/src/core/atom.ts +12 -2
- package/src/core/globalstate.ts +6 -0
- package/src/core/observable.ts +6 -0
- package/src/core/reaction.ts +10 -5
- package/src/internal.ts +1 -0
- package/src/types/generic-abort-signal.ts +7 -0
- package/src/types/legacyobservablearray.ts +17 -19
- package/src/types/observablearray.ts +12 -13
- package/src/types/observablemap.ts +13 -10
- package/src/types/observableobject.ts +6 -1
- package/src/types/observableset.ts +9 -6
- package/src/types/type-utils.ts +26 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# mobx
|
|
2
2
|
|
|
3
|
+
## 6.10.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`3ceeb865`](https://github.com/mobxjs/mobx/commit/3ceeb8651e328c4c7211c875696b3f5269fea834) [#3732](https://github.com/mobxjs/mobx/pull/3732) Thanks [@urugator](https://github.com/urugator)! - - fix: #3728: Observable initialization updates state version.
|
|
8
|
+
- fix: Observable set initialization violates `enforceActions: "always"`.
|
|
9
|
+
- fix: Changing keys of observable object does not respect `enforceActions`.
|
|
10
|
+
|
|
11
|
+
## 6.10.0
|
|
12
|
+
|
|
13
|
+
### Minor Changes
|
|
14
|
+
|
|
15
|
+
- [`bebd5f05`](https://github.com/mobxjs/mobx/commit/bebd5f0507a109145f401c78630ed9d59e4a1101) [#3727](https://github.com/mobxjs/mobx/pull/3727) Thanks [@rluvaton](https://github.com/rluvaton)! - Added support for `signal` (AbortSignal) in `autorun`, `reaction` and sync `when` options to dispose them
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- [`55f78ddc`](https://github.com/mobxjs/mobx/commit/55f78ddc20e84f38a7aa88b99a51ad994e558241) [#3717](https://github.com/mobxjs/mobx/pull/3717) Thanks [@liucan233](https://github.com/liucan233)! - remove proxy option for makeObservable and makeAutoObservable
|
|
20
|
+
|
|
3
21
|
## 6.9.1
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/dist/api/autorun.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IEqualsComparer, IReactionDisposer, IReactionPublic } from "../internal";
|
|
1
|
+
import { IEqualsComparer, IReactionDisposer, IReactionPublic, GenericAbortSignal } from "../internal";
|
|
2
2
|
export interface IAutorunOptions {
|
|
3
3
|
delay?: number;
|
|
4
4
|
name?: string;
|
|
@@ -9,6 +9,7 @@ export interface IAutorunOptions {
|
|
|
9
9
|
requiresObservable?: boolean;
|
|
10
10
|
scheduler?: (callback: () => void) => any;
|
|
11
11
|
onError?: (error: any) => void;
|
|
12
|
+
signal?: GenericAbortSignal;
|
|
12
13
|
}
|
|
13
14
|
/**
|
|
14
15
|
* Creates a named reactive view and keeps it alive, so that the view is always
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AnnotationsMap, CreateObservableOptions } from "../internal";
|
|
2
2
|
declare type NoInfer<T> = [T][T extends any ? 0 : never];
|
|
3
|
-
|
|
4
|
-
export declare function
|
|
3
|
+
declare type MakeObservableOptions = Omit<CreateObservableOptions, "proxy">;
|
|
4
|
+
export declare function makeObservable<T extends object, AdditionalKeys extends PropertyKey = never>(target: T, annotations?: AnnotationsMap<T, NoInfer<AdditionalKeys>>, options?: MakeObservableOptions): T;
|
|
5
|
+
export declare function makeAutoObservable<T extends object, AdditionalKeys extends PropertyKey = never>(target: T, overrides?: AnnotationsMap<T, NoInfer<AdditionalKeys>>, options?: MakeObservableOptions): T;
|
|
5
6
|
export {};
|
package/dist/api/when.d.ts
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import { IReactionDisposer, Lambda } from "../internal";
|
|
2
|
-
interface GenericAbortSignal {
|
|
3
|
-
readonly aborted: boolean;
|
|
4
|
-
onabort?: ((...args: any) => any) | null;
|
|
5
|
-
addEventListener?: (...args: any) => any;
|
|
6
|
-
removeEventListener?: (...args: any) => any;
|
|
7
|
-
}
|
|
1
|
+
import { IReactionDisposer, Lambda, GenericAbortSignal } from "../internal";
|
|
8
2
|
export interface IWhenOptions {
|
|
9
3
|
name?: string;
|
|
10
4
|
timeout?: number;
|
|
@@ -15,4 +9,3 @@ export declare function when(predicate: () => boolean, opts?: IWhenOptions): Pro
|
|
|
15
9
|
cancel(): void;
|
|
16
10
|
};
|
|
17
11
|
export declare function when(predicate: () => boolean, effect: Lambda, opts?: IWhenOptions): IReactionDisposer;
|
|
18
|
-
export {};
|
package/dist/core/atom.d.ts
CHANGED
|
@@ -2,13 +2,14 @@ import { IDerivationState_, IObservable, IDerivation, Lambda } from "../internal
|
|
|
2
2
|
export declare const $mobx: unique symbol;
|
|
3
3
|
export interface IAtom extends IObservable {
|
|
4
4
|
reportObserved(): boolean;
|
|
5
|
-
reportChanged():
|
|
5
|
+
reportChanged(): void;
|
|
6
6
|
}
|
|
7
7
|
export declare class Atom implements IAtom {
|
|
8
8
|
name_: string;
|
|
9
9
|
isPendingUnobservation_: boolean;
|
|
10
10
|
isBeingObserved_: boolean;
|
|
11
11
|
observers_: Set<IDerivation>;
|
|
12
|
+
batchId_: number;
|
|
12
13
|
diffValue_: number;
|
|
13
14
|
lastAccessedBy_: number;
|
|
14
15
|
lowestObserverState_: IDerivationState_;
|
|
@@ -37,6 +37,11 @@ export declare class MobXGlobals {
|
|
|
37
37
|
* Are we in a batch block? (and how many of them)
|
|
38
38
|
*/
|
|
39
39
|
inBatch: number;
|
|
40
|
+
/**
|
|
41
|
+
* ID of the latest batch. Used to suppress reportChanged of newly created atoms.
|
|
42
|
+
* Note the value persists even after batch ended.
|
|
43
|
+
*/
|
|
44
|
+
batchId: number;
|
|
40
45
|
/**
|
|
41
46
|
* Observables that don't have observers anymore, and are about to be
|
|
42
47
|
* suspended, unless somebody else accesses it in the same batch
|
package/dist/core/reaction.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IDerivation, IDerivationState_, IObservable, Lambda, TraceMode } from "../internal";
|
|
1
|
+
import { IDerivation, IDerivationState_, IObservable, Lambda, TraceMode, GenericAbortSignal } from "../internal";
|
|
2
2
|
/**
|
|
3
3
|
* Reactions are a special kind of derivations. Several things distinguishes them from normal reactive computations
|
|
4
4
|
*
|
|
@@ -52,7 +52,7 @@ export declare class Reaction implements IDerivation, IReactionPublic {
|
|
|
52
52
|
track(fn: () => void): void;
|
|
53
53
|
reportExceptionInDerivation_(error: any): void;
|
|
54
54
|
dispose(): void;
|
|
55
|
-
getDisposer_(): IReactionDisposer;
|
|
55
|
+
getDisposer_(abortSignal?: GenericAbortSignal): IReactionDisposer;
|
|
56
56
|
toString(): string;
|
|
57
57
|
trace(enterBreakPoint?: boolean): void;
|
|
58
58
|
}
|
package/dist/internal.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export * from "./types/flowannotation";
|
|
|
11
11
|
export * from "./types/computedannotation";
|
|
12
12
|
export * from "./types/observableannotation";
|
|
13
13
|
export * from "./types/autoannotation";
|
|
14
|
+
export * from "./types/generic-abort-signal";
|
|
14
15
|
export * from "./api/observable";
|
|
15
16
|
export * from "./api/computed";
|
|
16
17
|
export * from "./core/action";
|
|
@@ -426,12 +426,14 @@ var Atom = /*#__PURE__*/function () {
|
|
|
426
426
|
this.isPendingUnobservation_ = false;
|
|
427
427
|
this.isBeingObserved_ = false;
|
|
428
428
|
this.observers_ = new Set();
|
|
429
|
+
this.batchId_ = void 0;
|
|
429
430
|
this.diffValue_ = 0;
|
|
430
431
|
this.lastAccessedBy_ = 0;
|
|
431
432
|
this.lowestObserverState_ = IDerivationState_.NOT_TRACKING_;
|
|
432
433
|
this.onBOL = void 0;
|
|
433
434
|
this.onBUOL = void 0;
|
|
434
435
|
this.name_ = name_;
|
|
436
|
+
this.batchId_ = globalState.inBatch ? globalState.batchId : NaN;
|
|
435
437
|
}
|
|
436
438
|
// onBecomeObservedListeners
|
|
437
439
|
var _proto = Atom.prototype;
|
|
@@ -460,6 +462,12 @@ var Atom = /*#__PURE__*/function () {
|
|
|
460
462
|
* Invoke this method _after_ this method has changed to signal mobx that all its observers should invalidate.
|
|
461
463
|
*/;
|
|
462
464
|
_proto.reportChanged = function reportChanged() {
|
|
465
|
+
if (globalState.inBatch && this.batchId_ === globalState.batchId) {
|
|
466
|
+
// Called from the same batch this atom was created in.
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
// Avoids the possibility of hitting the same globalState.batchId when it cycled through all integers (necessary?)
|
|
470
|
+
this.batchId_ = NaN;
|
|
463
471
|
startBatch();
|
|
464
472
|
propagateChanged(this);
|
|
465
473
|
// We could update state version only at the end of batch,
|
|
@@ -993,7 +1001,9 @@ var observableFactories = {
|
|
|
993
1001
|
return new ObservableSet(initialValues, getEnhancerFromOptions(o), o.name);
|
|
994
1002
|
},
|
|
995
1003
|
object: function object(props, decorators, options) {
|
|
996
|
-
return
|
|
1004
|
+
return initObservable(function () {
|
|
1005
|
+
return extendObservable(globalState.useProxies === false || (options == null ? void 0 : options.proxy) === false ? asObservableObject({}, options) : asDynamicObservableObject({}, options), props, decorators);
|
|
1006
|
+
});
|
|
997
1007
|
},
|
|
998
1008
|
ref: /*#__PURE__*/createDecoratorAnnotation(observableRefAnnotation),
|
|
999
1009
|
shallow: /*#__PURE__*/createDecoratorAnnotation(observableShallowAnnotation),
|
|
@@ -1815,6 +1825,7 @@ var MobXGlobals = function MobXGlobals() {
|
|
|
1815
1825
|
this.runId = 0;
|
|
1816
1826
|
this.mobxGuid = 0;
|
|
1817
1827
|
this.inBatch = 0;
|
|
1828
|
+
this.batchId = Number.MIN_SAFE_INTEGER;
|
|
1818
1829
|
this.pendingUnobservations = [];
|
|
1819
1830
|
this.pendingReactions = [];
|
|
1820
1831
|
this.isRunningReactions = false;
|
|
@@ -1954,6 +1965,9 @@ function queueForUnobservation(observable) {
|
|
|
1954
1965
|
* Avoids unnecessary recalculations.
|
|
1955
1966
|
*/
|
|
1956
1967
|
function startBatch() {
|
|
1968
|
+
if (globalState.inBatch === 0) {
|
|
1969
|
+
globalState.batchId = globalState.batchId < Number.MAX_SAFE_INTEGER ? globalState.batchId + 1 : Number.MIN_SAFE_INTEGER;
|
|
1970
|
+
}
|
|
1957
1971
|
globalState.inBatch++;
|
|
1958
1972
|
}
|
|
1959
1973
|
function endBatch() {
|
|
@@ -2246,10 +2260,15 @@ var Reaction = /*#__PURE__*/function () {
|
|
|
2246
2260
|
}
|
|
2247
2261
|
}
|
|
2248
2262
|
};
|
|
2249
|
-
_proto.getDisposer_ = function getDisposer_() {
|
|
2250
|
-
var
|
|
2251
|
-
|
|
2252
|
-
|
|
2263
|
+
_proto.getDisposer_ = function getDisposer_(abortSignal) {
|
|
2264
|
+
var _this2 = this;
|
|
2265
|
+
var dispose = function dispose() {
|
|
2266
|
+
_this2.dispose();
|
|
2267
|
+
abortSignal == null ? void 0 : abortSignal.removeEventListener == null ? void 0 : abortSignal.removeEventListener("abort", dispose);
|
|
2268
|
+
};
|
|
2269
|
+
abortSignal == null ? void 0 : abortSignal.addEventListener == null ? void 0 : abortSignal.addEventListener("abort", dispose);
|
|
2270
|
+
dispose[$mobx] = this;
|
|
2271
|
+
return dispose;
|
|
2253
2272
|
};
|
|
2254
2273
|
_proto.toString = function toString() {
|
|
2255
2274
|
return "Reaction[" + this.name_ + "]";
|
|
@@ -2423,7 +2442,7 @@ function isAction(thing) {
|
|
|
2423
2442
|
* @returns disposer function, which can be used to stop the view from being updated in the future.
|
|
2424
2443
|
*/
|
|
2425
2444
|
function autorun(view, opts) {
|
|
2426
|
-
var _opts$name, _opts;
|
|
2445
|
+
var _opts$name, _opts, _opts2, _opts2$signal, _opts3;
|
|
2427
2446
|
if (opts === void 0) {
|
|
2428
2447
|
opts = EMPTY_OBJECT;
|
|
2429
2448
|
}
|
|
@@ -2462,8 +2481,10 @@ function autorun(view, opts) {
|
|
|
2462
2481
|
function reactionRunner() {
|
|
2463
2482
|
view(reaction);
|
|
2464
2483
|
}
|
|
2465
|
-
|
|
2466
|
-
|
|
2484
|
+
if (!((_opts2 = opts) != null && (_opts2$signal = _opts2.signal) != null && _opts2$signal.aborted)) {
|
|
2485
|
+
reaction.schedule_();
|
|
2486
|
+
}
|
|
2487
|
+
return reaction.getDisposer_((_opts3 = opts) == null ? void 0 : _opts3.signal);
|
|
2467
2488
|
}
|
|
2468
2489
|
var run = function run(f) {
|
|
2469
2490
|
return f();
|
|
@@ -2474,7 +2495,7 @@ function createSchedulerFromOptions(opts) {
|
|
|
2474
2495
|
} : run;
|
|
2475
2496
|
}
|
|
2476
2497
|
function reaction(expression, effect, opts) {
|
|
2477
|
-
var _opts$name2;
|
|
2498
|
+
var _opts$name2, _opts4, _opts4$signal, _opts5;
|
|
2478
2499
|
if (opts === void 0) {
|
|
2479
2500
|
opts = EMPTY_OBJECT;
|
|
2480
2501
|
}
|
|
@@ -2524,8 +2545,10 @@ function reaction(expression, effect, opts) {
|
|
|
2524
2545
|
}
|
|
2525
2546
|
firstTime = false;
|
|
2526
2547
|
}
|
|
2527
|
-
|
|
2528
|
-
|
|
2548
|
+
if (!((_opts4 = opts) != null && (_opts4$signal = _opts4.signal) != null && _opts4$signal.aborted)) {
|
|
2549
|
+
r.schedule_();
|
|
2550
|
+
}
|
|
2551
|
+
return r.getDisposer_((_opts5 = opts) == null ? void 0 : _opts5.signal);
|
|
2529
2552
|
}
|
|
2530
2553
|
function wrapErrorHandler(errorHandler, baseFn) {
|
|
2531
2554
|
return function () {
|
|
@@ -2620,17 +2643,14 @@ function extendObservable(target, properties, annotations, options) {
|
|
|
2620
2643
|
}
|
|
2621
2644
|
// Pull descriptors first, so we don't have to deal with props added by administration ($mobx)
|
|
2622
2645
|
var descriptors = getOwnPropertyDescriptors(properties);
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
try {
|
|
2646
|
+
initObservable(function () {
|
|
2647
|
+
var adm = asObservableObject(target, options)[$mobx];
|
|
2626
2648
|
ownKeys(descriptors).forEach(function (key) {
|
|
2627
2649
|
adm.extend_(key, descriptors[key],
|
|
2628
2650
|
// must pass "undefined" for { key: undefined }
|
|
2629
2651
|
!annotations ? true : key in annotations ? annotations[key] : true);
|
|
2630
2652
|
});
|
|
2631
|
-
}
|
|
2632
|
-
endBatch();
|
|
2633
|
-
}
|
|
2653
|
+
});
|
|
2634
2654
|
return target;
|
|
2635
2655
|
}
|
|
2636
2656
|
|
|
@@ -3316,10 +3336,9 @@ function notifyListeners(listenable, change) {
|
|
|
3316
3336
|
}
|
|
3317
3337
|
|
|
3318
3338
|
function makeObservable(target, annotations, options) {
|
|
3319
|
-
|
|
3320
|
-
startBatch();
|
|
3321
|
-
try {
|
|
3339
|
+
initObservable(function () {
|
|
3322
3340
|
var _annotations;
|
|
3341
|
+
var adm = asObservableObject(target, options)[$mobx];
|
|
3323
3342
|
if ("development" !== "production" && annotations && target[storedAnnotationsSymbol]) {
|
|
3324
3343
|
die("makeObservable second arg must be nullish when using decorators. Mixing @decorator syntax with annotations is not supported.");
|
|
3325
3344
|
}
|
|
@@ -3329,9 +3348,7 @@ function makeObservable(target, annotations, options) {
|
|
|
3329
3348
|
ownKeys(annotations).forEach(function (key) {
|
|
3330
3349
|
return adm.make_(key, annotations[key]);
|
|
3331
3350
|
});
|
|
3332
|
-
}
|
|
3333
|
-
endBatch();
|
|
3334
|
-
}
|
|
3351
|
+
});
|
|
3335
3352
|
return target;
|
|
3336
3353
|
}
|
|
3337
3354
|
// proto[keysSymbol] = new Set<PropertyKey>()
|
|
@@ -3350,26 +3367,23 @@ function makeAutoObservable(target, overrides, options) {
|
|
|
3350
3367
|
if (isPlainObject(target)) {
|
|
3351
3368
|
return extendObservable(target, target, overrides, options);
|
|
3352
3369
|
}
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
try {
|
|
3370
|
+
initObservable(function () {
|
|
3371
|
+
var adm = asObservableObject(target, options)[$mobx];
|
|
3372
|
+
// Optimization: cache keys on proto
|
|
3373
|
+
// Assumes makeAutoObservable can be called only once per object and can't be used in subclass
|
|
3374
|
+
if (!target[keysSymbol]) {
|
|
3375
|
+
var proto = Object.getPrototypeOf(target);
|
|
3376
|
+
var keys = new Set([].concat(ownKeys(target), ownKeys(proto)));
|
|
3377
|
+
keys["delete"]("constructor");
|
|
3378
|
+
keys["delete"]($mobx);
|
|
3379
|
+
addHiddenProp(proto, keysSymbol, keys);
|
|
3380
|
+
}
|
|
3365
3381
|
target[keysSymbol].forEach(function (key) {
|
|
3366
3382
|
return adm.make_(key,
|
|
3367
3383
|
// must pass "undefined" for { key: undefined }
|
|
3368
3384
|
!overrides ? true : key in overrides ? overrides[key] : true);
|
|
3369
3385
|
});
|
|
3370
|
-
}
|
|
3371
|
-
endBatch();
|
|
3372
|
-
}
|
|
3386
|
+
});
|
|
3373
3387
|
return target;
|
|
3374
3388
|
}
|
|
3375
3389
|
|
|
@@ -3677,16 +3691,16 @@ function createObservableArray(initialValues, enhancer, name, owned) {
|
|
|
3677
3691
|
owned = false;
|
|
3678
3692
|
}
|
|
3679
3693
|
assertProxies();
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3694
|
+
return initObservable(function () {
|
|
3695
|
+
var adm = new ObservableArrayAdministration(name, enhancer, owned, false);
|
|
3696
|
+
addHiddenFinalProp(adm.values_, $mobx, adm);
|
|
3697
|
+
var proxy = new Proxy(adm.values_, arrayTraps);
|
|
3698
|
+
adm.proxy_ = proxy;
|
|
3699
|
+
if (initialValues && initialValues.length) {
|
|
3700
|
+
adm.spliceWithArray_(0, 0, initialValues);
|
|
3701
|
+
}
|
|
3702
|
+
return proxy;
|
|
3703
|
+
});
|
|
3690
3704
|
}
|
|
3691
3705
|
// eslint-disable-next-line
|
|
3692
3706
|
var arrayExtensions = {
|
|
@@ -3882,11 +3896,13 @@ var ObservableMap = /*#__PURE__*/function () {
|
|
|
3882
3896
|
if (!isFunction(Map)) {
|
|
3883
3897
|
die(18);
|
|
3884
3898
|
}
|
|
3885
|
-
|
|
3886
|
-
|
|
3887
|
-
|
|
3888
|
-
|
|
3889
|
-
|
|
3899
|
+
initObservable(function () {
|
|
3900
|
+
_this.keysAtom_ = createAtom("development" !== "production" ? _this.name_ + ".keys()" : "ObservableMap.keys()");
|
|
3901
|
+
_this.data_ = new Map();
|
|
3902
|
+
_this.hasMap_ = new Map();
|
|
3903
|
+
if (initialData) {
|
|
3904
|
+
_this.merge(initialData);
|
|
3905
|
+
}
|
|
3890
3906
|
});
|
|
3891
3907
|
}
|
|
3892
3908
|
var _proto = ObservableMap.prototype;
|
|
@@ -4270,6 +4286,7 @@ _Symbol$iterator$1 = Symbol.iterator;
|
|
|
4270
4286
|
_Symbol$toStringTag$1 = Symbol.toStringTag;
|
|
4271
4287
|
var ObservableSet = /*#__PURE__*/function () {
|
|
4272
4288
|
function ObservableSet(initialData, enhancer, name_) {
|
|
4289
|
+
var _this = this;
|
|
4273
4290
|
if (enhancer === void 0) {
|
|
4274
4291
|
enhancer = deepEnhancer;
|
|
4275
4292
|
}
|
|
@@ -4288,13 +4305,15 @@ var ObservableSet = /*#__PURE__*/function () {
|
|
|
4288
4305
|
if (!isFunction(Set)) {
|
|
4289
4306
|
die(22);
|
|
4290
4307
|
}
|
|
4291
|
-
this.atom_ = createAtom(this.name_);
|
|
4292
4308
|
this.enhancer_ = function (newV, oldV) {
|
|
4293
4309
|
return enhancer(newV, oldV, name_);
|
|
4294
4310
|
};
|
|
4295
|
-
|
|
4296
|
-
|
|
4297
|
-
|
|
4311
|
+
initObservable(function () {
|
|
4312
|
+
_this.atom_ = createAtom(_this.name_);
|
|
4313
|
+
if (initialData) {
|
|
4314
|
+
_this.replace(initialData);
|
|
4315
|
+
}
|
|
4316
|
+
});
|
|
4298
4317
|
}
|
|
4299
4318
|
var _proto = ObservableSet.prototype;
|
|
4300
4319
|
_proto.dehanceValue_ = function dehanceValue_(value) {
|
|
@@ -4304,12 +4323,12 @@ var ObservableSet = /*#__PURE__*/function () {
|
|
|
4304
4323
|
return value;
|
|
4305
4324
|
};
|
|
4306
4325
|
_proto.clear = function clear() {
|
|
4307
|
-
var
|
|
4326
|
+
var _this2 = this;
|
|
4308
4327
|
transaction(function () {
|
|
4309
4328
|
untracked(function () {
|
|
4310
|
-
for (var _iterator = _createForOfIteratorHelperLoose(
|
|
4329
|
+
for (var _iterator = _createForOfIteratorHelperLoose(_this2.data_.values()), _step; !(_step = _iterator()).done;) {
|
|
4311
4330
|
var value = _step.value;
|
|
4312
|
-
|
|
4331
|
+
_this2["delete"](value);
|
|
4313
4332
|
}
|
|
4314
4333
|
});
|
|
4315
4334
|
});
|
|
@@ -4321,7 +4340,7 @@ var ObservableSet = /*#__PURE__*/function () {
|
|
|
4321
4340
|
}
|
|
4322
4341
|
};
|
|
4323
4342
|
_proto.add = function add(value) {
|
|
4324
|
-
var
|
|
4343
|
+
var _this3 = this;
|
|
4325
4344
|
checkIfStateModificationsAreAllowed(this.atom_);
|
|
4326
4345
|
if (hasInterceptors(this)) {
|
|
4327
4346
|
var change = interceptChange(this, {
|
|
@@ -4338,8 +4357,8 @@ var ObservableSet = /*#__PURE__*/function () {
|
|
|
4338
4357
|
|
|
4339
4358
|
if (!this.has(value)) {
|
|
4340
4359
|
transaction(function () {
|
|
4341
|
-
|
|
4342
|
-
|
|
4360
|
+
_this3.data_.add(_this3.enhancer_(value, undefined));
|
|
4361
|
+
_this3.atom_.reportChanged();
|
|
4343
4362
|
});
|
|
4344
4363
|
var notifySpy = isSpyEnabled();
|
|
4345
4364
|
var notify = hasListeners(this);
|
|
@@ -4363,7 +4382,7 @@ var ObservableSet = /*#__PURE__*/function () {
|
|
|
4363
4382
|
return this;
|
|
4364
4383
|
};
|
|
4365
4384
|
_proto["delete"] = function _delete(value) {
|
|
4366
|
-
var
|
|
4385
|
+
var _this4 = this;
|
|
4367
4386
|
if (hasInterceptors(this)) {
|
|
4368
4387
|
var change = interceptChange(this, {
|
|
4369
4388
|
type: DELETE,
|
|
@@ -4388,8 +4407,8 @@ var ObservableSet = /*#__PURE__*/function () {
|
|
|
4388
4407
|
spyReportStart(_change2);
|
|
4389
4408
|
}
|
|
4390
4409
|
transaction(function () {
|
|
4391
|
-
|
|
4392
|
-
|
|
4410
|
+
_this4.atom_.reportChanged();
|
|
4411
|
+
_this4.data_["delete"](value);
|
|
4393
4412
|
});
|
|
4394
4413
|
if (notify) {
|
|
4395
4414
|
notifyListeners(this, _change2);
|
|
@@ -4442,20 +4461,20 @@ var ObservableSet = /*#__PURE__*/function () {
|
|
|
4442
4461
|
});
|
|
4443
4462
|
};
|
|
4444
4463
|
_proto.replace = function replace(other) {
|
|
4445
|
-
var
|
|
4464
|
+
var _this5 = this;
|
|
4446
4465
|
if (isObservableSet(other)) {
|
|
4447
4466
|
other = new Set(other);
|
|
4448
4467
|
}
|
|
4449
4468
|
transaction(function () {
|
|
4450
4469
|
if (Array.isArray(other)) {
|
|
4451
|
-
|
|
4470
|
+
_this5.clear();
|
|
4452
4471
|
other.forEach(function (value) {
|
|
4453
|
-
return
|
|
4472
|
+
return _this5.add(value);
|
|
4454
4473
|
});
|
|
4455
4474
|
} else if (isES6Set(other)) {
|
|
4456
|
-
|
|
4475
|
+
_this5.clear();
|
|
4457
4476
|
other.forEach(function (value) {
|
|
4458
|
-
return
|
|
4477
|
+
return _this5.add(value);
|
|
4459
4478
|
});
|
|
4460
4479
|
} else if (other !== null && other !== undefined) {
|
|
4461
4480
|
die("Cannot initialize set from " + other);
|
|
@@ -4719,6 +4738,7 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
4719
4738
|
if (proxyTrap === void 0) {
|
|
4720
4739
|
proxyTrap = false;
|
|
4721
4740
|
}
|
|
4741
|
+
checkIfStateModificationsAreAllowed(this.keysAtom_);
|
|
4722
4742
|
try {
|
|
4723
4743
|
startBatch();
|
|
4724
4744
|
// Delete
|
|
@@ -4766,6 +4786,7 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
4766
4786
|
if (proxyTrap === void 0) {
|
|
4767
4787
|
proxyTrap = false;
|
|
4768
4788
|
}
|
|
4789
|
+
checkIfStateModificationsAreAllowed(this.keysAtom_);
|
|
4769
4790
|
try {
|
|
4770
4791
|
startBatch();
|
|
4771
4792
|
// Delete
|
|
@@ -4817,6 +4838,7 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
4817
4838
|
if (proxyTrap === void 0) {
|
|
4818
4839
|
proxyTrap = false;
|
|
4819
4840
|
}
|
|
4841
|
+
checkIfStateModificationsAreAllowed(this.keysAtom_);
|
|
4820
4842
|
try {
|
|
4821
4843
|
startBatch();
|
|
4822
4844
|
// Delete
|
|
@@ -4872,6 +4894,7 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
4872
4894
|
if (proxyTrap === void 0) {
|
|
4873
4895
|
proxyTrap = false;
|
|
4874
4896
|
}
|
|
4897
|
+
checkIfStateModificationsAreAllowed(this.keysAtom_);
|
|
4875
4898
|
// No such prop
|
|
4876
4899
|
if (!hasProp(this.target_, key)) {
|
|
4877
4900
|
return true;
|
|
@@ -5101,6 +5124,17 @@ function assertAnnotable(adm, annotation, key) {
|
|
|
5101
5124
|
|
|
5102
5125
|
// Bug in safari 9.* (or iOS 9 safari mobile). See #364
|
|
5103
5126
|
var ENTRY_0 = /*#__PURE__*/createArrayEntryDescriptor(0);
|
|
5127
|
+
var safariPrototypeSetterInheritanceBug = /*#__PURE__*/function () {
|
|
5128
|
+
var v = false;
|
|
5129
|
+
var p = {};
|
|
5130
|
+
Object.defineProperty(p, "0", {
|
|
5131
|
+
set: function set() {
|
|
5132
|
+
v = true;
|
|
5133
|
+
}
|
|
5134
|
+
});
|
|
5135
|
+
/*#__PURE__*/Object.create(p)["0"] = 1;
|
|
5136
|
+
return v === false;
|
|
5137
|
+
}();
|
|
5104
5138
|
/**
|
|
5105
5139
|
* This array buffer contains two lists of properties, so that all arrays
|
|
5106
5140
|
* can recycle their property definitions, which significantly improves performance of creating
|
|
@@ -5133,20 +5167,20 @@ var LegacyObservableArray = /*#__PURE__*/function (_StubArray, _Symbol$toStringT
|
|
|
5133
5167
|
owned = false;
|
|
5134
5168
|
}
|
|
5135
5169
|
_this = _StubArray.call(this) || this;
|
|
5136
|
-
|
|
5137
|
-
|
|
5138
|
-
|
|
5139
|
-
|
|
5140
|
-
|
|
5141
|
-
|
|
5142
|
-
|
|
5143
|
-
|
|
5144
|
-
|
|
5145
|
-
|
|
5146
|
-
|
|
5147
|
-
|
|
5148
|
-
|
|
5149
|
-
}
|
|
5170
|
+
initObservable(function () {
|
|
5171
|
+
var adm = new ObservableArrayAdministration(name, enhancer, owned, true);
|
|
5172
|
+
adm.proxy_ = _assertThisInitialized(_this);
|
|
5173
|
+
addHiddenFinalProp(_assertThisInitialized(_this), $mobx, adm);
|
|
5174
|
+
if (initialValues && initialValues.length) {
|
|
5175
|
+
// @ts-ignore
|
|
5176
|
+
_this.spliceWithArray(0, 0, initialValues);
|
|
5177
|
+
}
|
|
5178
|
+
if (safariPrototypeSetterInheritanceBug) {
|
|
5179
|
+
// Seems that Safari won't use numeric prototype setter untill any * numeric property is
|
|
5180
|
+
// defined on the instance. After that it works fine, even if this property is deleted.
|
|
5181
|
+
Object.defineProperty(_assertThisInitialized(_this), "0", ENTRY_0);
|
|
5182
|
+
}
|
|
5183
|
+
});
|
|
5150
5184
|
return _this;
|
|
5151
5185
|
}
|
|
5152
5186
|
var _proto = LegacyObservableArray.prototype;
|
|
@@ -5301,6 +5335,24 @@ function getDebugName(thing, property) {
|
|
|
5301
5335
|
}
|
|
5302
5336
|
return named.name_;
|
|
5303
5337
|
}
|
|
5338
|
+
/**
|
|
5339
|
+
* Helper function for initializing observable structures, it applies:
|
|
5340
|
+
* 1. allowStateChanges so we don't violate enforceActions.
|
|
5341
|
+
* 2. untracked so we don't accidentaly subscribe to anything observable accessed during init in case the observable is created inside derivation.
|
|
5342
|
+
* 3. batch to avoid state version updates
|
|
5343
|
+
*/
|
|
5344
|
+
function initObservable(cb) {
|
|
5345
|
+
var derivation = untrackedStart();
|
|
5346
|
+
var allowStateChanges = allowStateChangesStart(true);
|
|
5347
|
+
startBatch();
|
|
5348
|
+
try {
|
|
5349
|
+
return cb();
|
|
5350
|
+
} finally {
|
|
5351
|
+
endBatch();
|
|
5352
|
+
allowStateChangesEnd(allowStateChanges);
|
|
5353
|
+
untrackedEnd(derivation);
|
|
5354
|
+
}
|
|
5355
|
+
}
|
|
5304
5356
|
|
|
5305
5357
|
var toString = objectPrototype.toString;
|
|
5306
5358
|
function deepEqual(a, b, depth) {
|