mobx 5.8.0 → 5.9.0
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 +17 -0
- package/LICENSE +0 -0
- package/README.md +8 -8
- package/lib/api/become-observed.d.ts +3 -3
- package/lib/api/flow.d.ts +8 -5
- package/lib/api/intercept-read.d.ts +2 -1
- package/lib/api/intercept.d.ts +2 -1
- package/lib/api/object-api.d.ts +6 -1
- package/lib/api/observable.d.ts +3 -1
- package/lib/api/observe.d.ts +2 -1
- package/lib/core/globalstate.d.ts +1 -0
- package/lib/internal.d.ts +1 -0
- package/lib/mobx.d.ts +1 -1
- package/lib/mobx.es6.js +287 -27
- package/lib/mobx.js +330 -33
- package/lib/mobx.min.js +1 -1
- package/lib/mobx.min.js.map +1 -1
- package/lib/mobx.module.js +329 -34
- package/lib/mobx.umd.js +330 -33
- package/lib/mobx.umd.min.js +1 -1
- package/lib/mobx.umd.min.js.map +1 -1
- package/lib/types/observableset.d.ts +49 -0
- package/lib/types/observablevalue.d.ts +4 -2
- package/lib/utils/utils.d.ts +1 -0
- package/package.json +2 -1
package/lib/mobx.js
CHANGED
|
@@ -189,6 +189,9 @@ function isArrayLike$$1(x) {
|
|
|
189
189
|
function isES6Map$$1(thing) {
|
|
190
190
|
return thing instanceof Map;
|
|
191
191
|
}
|
|
192
|
+
function isES6Set$$1(thing) {
|
|
193
|
+
return thing instanceof Set;
|
|
194
|
+
}
|
|
192
195
|
function getMapLikeKeys$$1(map) {
|
|
193
196
|
if (isPlainObject$$1(map))
|
|
194
197
|
return Object.keys(map);
|
|
@@ -367,12 +370,14 @@ function deepEnhancer$$1(v, _, name) {
|
|
|
367
370
|
return observable$$1.object(v, undefined, { name: name });
|
|
368
371
|
if (isES6Map$$1(v))
|
|
369
372
|
return observable$$1.map(v, { name: name });
|
|
373
|
+
if (isES6Set$$1(v))
|
|
374
|
+
return observable$$1.set(v, { name: name });
|
|
370
375
|
return v;
|
|
371
376
|
}
|
|
372
377
|
function shallowEnhancer$$1(v, _, name) {
|
|
373
378
|
if (v === undefined || v === null)
|
|
374
379
|
return v;
|
|
375
|
-
if (isObservableObject$$1(v) || isObservableArray$$1(v) || isObservableMap$$1(v))
|
|
380
|
+
if (isObservableObject$$1(v) || isObservableArray$$1(v) || isObservableMap$$1(v) || isObservableSet$$1(v))
|
|
376
381
|
return v;
|
|
377
382
|
if (Array.isArray(v))
|
|
378
383
|
return observable$$1.array(v, { name: name, deep: false });
|
|
@@ -380,8 +385,10 @@ function shallowEnhancer$$1(v, _, name) {
|
|
|
380
385
|
return observable$$1.object(v, undefined, { name: name, deep: false });
|
|
381
386
|
if (isES6Map$$1(v))
|
|
382
387
|
return observable$$1.map(v, { name: name, deep: false });
|
|
388
|
+
if (isES6Set$$1(v))
|
|
389
|
+
return observable$$1.set(v, { name: name, deep: false });
|
|
383
390
|
return fail$$1(process.env.NODE_ENV !== "production" &&
|
|
384
|
-
"The shallow modifier / decorator can only used in combination with arrays, objects and
|
|
391
|
+
"The shallow modifier / decorator can only used in combination with arrays, objects, maps and sets");
|
|
385
392
|
}
|
|
386
393
|
function referenceEnhancer$$1(newValue) {
|
|
387
394
|
// never turn into an observable
|
|
@@ -433,7 +440,7 @@ var defaultCreateObservableOptions$$1 = {
|
|
|
433
440
|
};
|
|
434
441
|
Object.freeze(defaultCreateObservableOptions$$1);
|
|
435
442
|
function assertValidOption(key) {
|
|
436
|
-
if (!/^(deep|name|defaultDecorator|proxy)$/.test(key))
|
|
443
|
+
if (!/^(deep|name|equals|defaultDecorator|proxy)$/.test(key))
|
|
437
444
|
fail$$1("invalid option for (extend)observable: " + key);
|
|
438
445
|
}
|
|
439
446
|
function asCreateObservableOptions$$1(thing) {
|
|
@@ -478,7 +485,9 @@ function createObservable(v, arg2, arg3) {
|
|
|
478
485
|
? observable$$1.array(v, arg2)
|
|
479
486
|
: isES6Map$$1(v)
|
|
480
487
|
? observable$$1.map(v, arg2)
|
|
481
|
-
: v
|
|
488
|
+
: isES6Set$$1(v)
|
|
489
|
+
? observable$$1.set(v, arg2)
|
|
490
|
+
: v;
|
|
482
491
|
// this value could be converted to a new observable data structure, return it
|
|
483
492
|
if (res !== v)
|
|
484
493
|
return res;
|
|
@@ -491,7 +500,7 @@ var observableFactories = {
|
|
|
491
500
|
if (arguments.length > 2)
|
|
492
501
|
incorrectlyUsedAsDecorator("box");
|
|
493
502
|
var o = asCreateObservableOptions$$1(options);
|
|
494
|
-
return new ObservableValue$$1(value, getEnhancerFromOptions(o), o.name);
|
|
503
|
+
return new ObservableValue$$1(value, getEnhancerFromOptions(o), o.name, true, o.equals);
|
|
495
504
|
},
|
|
496
505
|
array: function (initialValues, options) {
|
|
497
506
|
if (arguments.length > 2)
|
|
@@ -505,6 +514,12 @@ var observableFactories = {
|
|
|
505
514
|
var o = asCreateObservableOptions$$1(options);
|
|
506
515
|
return new ObservableMap$$1(initialValues, getEnhancerFromOptions(o), o.name);
|
|
507
516
|
},
|
|
517
|
+
set: function (initialValues, options) {
|
|
518
|
+
if (arguments.length > 2)
|
|
519
|
+
incorrectlyUsedAsDecorator("set");
|
|
520
|
+
var o = asCreateObservableOptions$$1(options);
|
|
521
|
+
return new ObservableSet$$1(initialValues, getEnhancerFromOptions(o), o.name);
|
|
522
|
+
},
|
|
508
523
|
object: function (props, decorators, options) {
|
|
509
524
|
if (typeof arguments[1] === "string")
|
|
510
525
|
incorrectlyUsedAsDecorator("object");
|
|
@@ -584,11 +599,21 @@ function createAction$$1(actionName, fn) {
|
|
|
584
599
|
}
|
|
585
600
|
function executeAction$$1(actionName, fn, scope, args) {
|
|
586
601
|
var runInfo = startAction(actionName, fn, scope, args);
|
|
602
|
+
var shouldSupressReactionError = true;
|
|
587
603
|
try {
|
|
588
|
-
|
|
604
|
+
var res = fn.apply(scope, args);
|
|
605
|
+
shouldSupressReactionError = false;
|
|
606
|
+
return res;
|
|
589
607
|
}
|
|
590
608
|
finally {
|
|
591
|
-
|
|
609
|
+
if (shouldSupressReactionError) {
|
|
610
|
+
globalState$$1.suppressReactionErrors = shouldSupressReactionError;
|
|
611
|
+
endAction(runInfo);
|
|
612
|
+
globalState$$1.suppressReactionErrors = false;
|
|
613
|
+
}
|
|
614
|
+
else {
|
|
615
|
+
endAction(runInfo);
|
|
616
|
+
}
|
|
592
617
|
}
|
|
593
618
|
}
|
|
594
619
|
function startAction(actionName, fn, scope, args) {
|
|
@@ -659,11 +684,14 @@ function allowStateChangesInsideComputed$$1(func) {
|
|
|
659
684
|
|
|
660
685
|
var ObservableValue$$1 = /** @class */ (function (_super) {
|
|
661
686
|
__extends(ObservableValue$$1, _super);
|
|
662
|
-
function ObservableValue$$1(value, enhancer, name, notifySpy) {
|
|
687
|
+
function ObservableValue$$1(value, enhancer, name, notifySpy, equals) {
|
|
663
688
|
if (name === void 0) { name = "ObservableValue@" + getNextId$$1(); }
|
|
664
689
|
if (notifySpy === void 0) { notifySpy = true; }
|
|
690
|
+
if (equals === void 0) { equals = comparer$$1.default; }
|
|
665
691
|
var _this = _super.call(this, name) || this;
|
|
666
692
|
_this.enhancer = enhancer;
|
|
693
|
+
_this.name = name;
|
|
694
|
+
_this.equals = equals;
|
|
667
695
|
_this.hasUnreportedChange = false;
|
|
668
696
|
_this.value = enhancer(value, undefined, name);
|
|
669
697
|
if (notifySpy && isSpyEnabled$$1() && process.env.NODE_ENV !== "production") {
|
|
@@ -709,7 +737,7 @@ var ObservableValue$$1 = /** @class */ (function (_super) {
|
|
|
709
737
|
}
|
|
710
738
|
// apply modifier
|
|
711
739
|
newValue = this.enhancer(newValue, this.value, this.name);
|
|
712
|
-
return this.value
|
|
740
|
+
return this.equals(this.value, newValue) ? globalState$$1.UNCHANGED : newValue;
|
|
713
741
|
};
|
|
714
742
|
ObservableValue$$1.prototype.setNewValue = function (newValue) {
|
|
715
743
|
var oldValue = this.value;
|
|
@@ -1311,6 +1339,11 @@ var MobXGlobals$$1 = /** @class */ (function () {
|
|
|
1311
1339
|
* the stack when an exception occurs while debugging.
|
|
1312
1340
|
*/
|
|
1313
1341
|
this.disableErrorBoundaries = false;
|
|
1342
|
+
/*
|
|
1343
|
+
* If true, we are already handling an exception in an action. Any errors in reactions should be supressed, as
|
|
1344
|
+
* they are not the cause, see: https://github.com/mobxjs/mobx/issues/1836
|
|
1345
|
+
*/
|
|
1346
|
+
this.suppressReactionErrors = false;
|
|
1314
1347
|
}
|
|
1315
1348
|
return MobXGlobals$$1;
|
|
1316
1349
|
}());
|
|
@@ -1555,7 +1588,7 @@ function logTraceInfo(derivation, observable$$1) {
|
|
|
1555
1588
|
var lines = [];
|
|
1556
1589
|
printDepTree(getDependencyTree$$1(derivation), lines, 1);
|
|
1557
1590
|
// prettier-ignore
|
|
1558
|
-
new Function("debugger;\n/*\nTracing '" + derivation.name + "'\n\nYou are entering this break point because derivation '" + derivation.name + "' is being traced and '" + observable$$1.name + "' is now forcing it to update.\nJust follow the stacktrace you should now see in the devtools to see precisely what piece of your code is causing this update\nThe stackframe you are looking for is at least ~6-8 stack-frames up.\n\n" + (derivation instanceof ComputedValue$$1 ? derivation.derivation.toString() : "") + "\n\nThe dependencies for this derivation are:\n\n" + lines.join("\n") + "\n*/\n ")();
|
|
1591
|
+
new Function("debugger;\n/*\nTracing '" + derivation.name + "'\n\nYou are entering this break point because derivation '" + derivation.name + "' is being traced and '" + observable$$1.name + "' is now forcing it to update.\nJust follow the stacktrace you should now see in the devtools to see precisely what piece of your code is causing this update\nThe stackframe you are looking for is at least ~6-8 stack-frames up.\n\n" + (derivation instanceof ComputedValue$$1 ? derivation.derivation.toString().replace(/[*]\//g, "/") : "") + "\n\nThe dependencies for this derivation are:\n\n" + lines.join("\n") + "\n*/\n ")();
|
|
1559
1592
|
}
|
|
1560
1593
|
}
|
|
1561
1594
|
function printDepTree(tree, lines, depth) {
|
|
@@ -1664,9 +1697,14 @@ var Reaction$$1 = /** @class */ (function () {
|
|
|
1664
1697
|
}
|
|
1665
1698
|
if (globalState$$1.disableErrorBoundaries)
|
|
1666
1699
|
throw error;
|
|
1667
|
-
var message = "[mobx] Encountered an uncaught exception that was thrown by a reaction or observer component, in: '" + this;
|
|
1668
|
-
|
|
1669
|
-
|
|
1700
|
+
var message = "[mobx] Encountered an uncaught exception that was thrown by a reaction or observer component, in: '" + this + "'";
|
|
1701
|
+
if (globalState$$1.suppressReactionErrors) {
|
|
1702
|
+
console.warn("[mobx] (error in reaction '" + this.name + "' suppressed, fix error of causing action below)"); // prettier-ignore
|
|
1703
|
+
}
|
|
1704
|
+
else {
|
|
1705
|
+
console.error(message, error);
|
|
1706
|
+
/** If debugging brought you here, please, read the above message :-). Tnx! */
|
|
1707
|
+
}
|
|
1670
1708
|
if (isSpyEnabled$$1()) {
|
|
1671
1709
|
spyReport$$1({
|
|
1672
1710
|
type: "error",
|
|
@@ -2046,6 +2084,9 @@ function interceptHook(hook, thing, arg2, arg3) {
|
|
|
2046
2084
|
|
|
2047
2085
|
function configure$$1(options) {
|
|
2048
2086
|
var enforceActions = options.enforceActions, computedRequiresReaction = options.computedRequiresReaction, disableErrorBoundaries = options.disableErrorBoundaries, reactionScheduler = options.reactionScheduler;
|
|
2087
|
+
if (options.isolateGlobalState === true) {
|
|
2088
|
+
isolateGlobalState$$1();
|
|
2089
|
+
}
|
|
2049
2090
|
if (enforceActions !== undefined) {
|
|
2050
2091
|
if (typeof enforceActions === "boolean" || enforceActions === "strict")
|
|
2051
2092
|
deprecated$$1("Deprecated value for 'enforceActions', use 'false' => '\"never\"', 'true' => '\"observed\"', '\"strict\"' => \"'always'\" instead");
|
|
@@ -2072,9 +2113,6 @@ function configure$$1(options) {
|
|
|
2072
2113
|
if (computedRequiresReaction !== undefined) {
|
|
2073
2114
|
globalState$$1.computedRequiresReaction = !!computedRequiresReaction;
|
|
2074
2115
|
}
|
|
2075
|
-
if (options.isolateGlobalState === true) {
|
|
2076
|
-
isolateGlobalState$$1();
|
|
2077
|
-
}
|
|
2078
2116
|
if (disableErrorBoundaries !== undefined) {
|
|
2079
2117
|
if (disableErrorBoundaries === true)
|
|
2080
2118
|
console.warn("WARNING: Debug feature only. MobX will NOT recover from errors when `disableErrorBoundaries` is enabled.");
|
|
@@ -2196,7 +2234,7 @@ function flow$$1(generator) {
|
|
|
2196
2234
|
var gen = action$$1(name + " - runid: " + runId + " - init", generator).apply(ctx, args);
|
|
2197
2235
|
var rejector;
|
|
2198
2236
|
var pendingPromise = undefined;
|
|
2199
|
-
var
|
|
2237
|
+
var promise = new Promise(function (resolve, reject) {
|
|
2200
2238
|
var stepId = 0;
|
|
2201
2239
|
rejector = reject;
|
|
2202
2240
|
function onFulfilled(res) {
|
|
@@ -2234,14 +2272,14 @@ function flow$$1(generator) {
|
|
|
2234
2272
|
}
|
|
2235
2273
|
onFulfilled(undefined); // kick off the process
|
|
2236
2274
|
});
|
|
2237
|
-
|
|
2275
|
+
promise.cancel = action$$1(name + " - runid: " + runId + " - cancel", function () {
|
|
2238
2276
|
try {
|
|
2239
2277
|
if (pendingPromise)
|
|
2240
2278
|
cancelPromise(pendingPromise);
|
|
2241
2279
|
// Finally block can return (or yield) stuff..
|
|
2242
|
-
var
|
|
2280
|
+
var res = gen.return();
|
|
2243
2281
|
// eat anything that promise would do, it's cancelled!
|
|
2244
|
-
var yieldedPromise = Promise.resolve(
|
|
2282
|
+
var yieldedPromise = Promise.resolve(res.value);
|
|
2245
2283
|
yieldedPromise.then(noop$$1, noop$$1);
|
|
2246
2284
|
cancelPromise(yieldedPromise); // maybe it can be cancelled :)
|
|
2247
2285
|
// reject our original promise
|
|
@@ -2251,7 +2289,7 @@ function flow$$1(generator) {
|
|
|
2251
2289
|
rejector(e); // there could be a throwing finally block
|
|
2252
2290
|
}
|
|
2253
2291
|
});
|
|
2254
|
-
return
|
|
2292
|
+
return promise;
|
|
2255
2293
|
};
|
|
2256
2294
|
}
|
|
2257
2295
|
function cancelPromise(promise) {
|
|
@@ -2359,11 +2397,14 @@ function keys$$1(obj) {
|
|
|
2359
2397
|
if (isObservableMap$$1(obj)) {
|
|
2360
2398
|
return Array.from(obj.keys());
|
|
2361
2399
|
}
|
|
2400
|
+
if (isObservableSet$$1(obj)) {
|
|
2401
|
+
return Array.from(obj.keys());
|
|
2402
|
+
}
|
|
2362
2403
|
if (isObservableArray$$1(obj)) {
|
|
2363
2404
|
return obj.map(function (_, index) { return index; });
|
|
2364
2405
|
}
|
|
2365
2406
|
return fail$$1(process.env.NODE_ENV !== "production" &&
|
|
2366
|
-
"'keys()' can only be used on observable objects, arrays and maps");
|
|
2407
|
+
"'keys()' can only be used on observable objects, arrays, sets and maps");
|
|
2367
2408
|
}
|
|
2368
2409
|
function values$$1(obj) {
|
|
2369
2410
|
if (isObservableObject$$1(obj)) {
|
|
@@ -2372,11 +2413,14 @@ function values$$1(obj) {
|
|
|
2372
2413
|
if (isObservableMap$$1(obj)) {
|
|
2373
2414
|
return keys$$1(obj).map(function (key) { return obj.get(key); });
|
|
2374
2415
|
}
|
|
2416
|
+
if (isObservableSet$$1(obj)) {
|
|
2417
|
+
return Array.from(obj.values());
|
|
2418
|
+
}
|
|
2375
2419
|
if (isObservableArray$$1(obj)) {
|
|
2376
2420
|
return obj.slice();
|
|
2377
2421
|
}
|
|
2378
2422
|
return fail$$1(process.env.NODE_ENV !== "production" &&
|
|
2379
|
-
"'values()' can only be used on observable objects, arrays and maps");
|
|
2423
|
+
"'values()' can only be used on observable objects, arrays, sets and maps");
|
|
2380
2424
|
}
|
|
2381
2425
|
function entries$$1(obj) {
|
|
2382
2426
|
if (isObservableObject$$1(obj)) {
|
|
@@ -2385,6 +2429,9 @@ function entries$$1(obj) {
|
|
|
2385
2429
|
if (isObservableMap$$1(obj)) {
|
|
2386
2430
|
return keys$$1(obj).map(function (key) { return [key, obj.get(key)]; });
|
|
2387
2431
|
}
|
|
2432
|
+
if (isObservableSet$$1(obj)) {
|
|
2433
|
+
return Array.from(obj.entries());
|
|
2434
|
+
}
|
|
2388
2435
|
if (isObservableArray$$1(obj)) {
|
|
2389
2436
|
return obj.map(function (key, index) { return [index, key]; });
|
|
2390
2437
|
}
|
|
@@ -2440,6 +2487,9 @@ function remove$$1(obj, key) {
|
|
|
2440
2487
|
else if (isObservableMap$$1(obj)) {
|
|
2441
2488
|
obj.delete(key);
|
|
2442
2489
|
}
|
|
2490
|
+
else if (isObservableSet$$1(obj)) {
|
|
2491
|
+
obj.delete(key);
|
|
2492
|
+
}
|
|
2443
2493
|
else if (isObservableArray$$1(obj)) {
|
|
2444
2494
|
if (typeof key !== "number")
|
|
2445
2495
|
key = parseInt(key, 10);
|
|
@@ -2460,6 +2510,9 @@ function has$$1(obj, key) {
|
|
|
2460
2510
|
else if (isObservableMap$$1(obj)) {
|
|
2461
2511
|
return obj.has(key);
|
|
2462
2512
|
}
|
|
2513
|
+
else if (isObservableSet$$1(obj)) {
|
|
2514
|
+
return obj.has(key);
|
|
2515
|
+
}
|
|
2463
2516
|
else if (isObservableArray$$1(obj)) {
|
|
2464
2517
|
return key >= 0 && key < obj.length;
|
|
2465
2518
|
}
|
|
@@ -2537,20 +2590,36 @@ function toJSHelper(source, options, __alreadySeen) {
|
|
|
2537
2590
|
res_1[i] = toAdd[i];
|
|
2538
2591
|
return res_1;
|
|
2539
2592
|
}
|
|
2593
|
+
if (isObservableSet$$1(source) || Object.getPrototypeOf(source) === Set.prototype) {
|
|
2594
|
+
if (options.exportMapsAsObjects === false) {
|
|
2595
|
+
var res_2 = cache(__alreadySeen, source, new Set(), options);
|
|
2596
|
+
source.forEach(function (value) {
|
|
2597
|
+
res_2.add(toJSHelper(value, options, __alreadySeen));
|
|
2598
|
+
});
|
|
2599
|
+
return res_2;
|
|
2600
|
+
}
|
|
2601
|
+
else {
|
|
2602
|
+
var res_3 = cache(__alreadySeen, source, [], options);
|
|
2603
|
+
source.forEach(function (value) {
|
|
2604
|
+
res_3.push(toJSHelper(value, options, __alreadySeen));
|
|
2605
|
+
});
|
|
2606
|
+
return res_3;
|
|
2607
|
+
}
|
|
2608
|
+
}
|
|
2540
2609
|
if (isObservableMap$$1(source) || Object.getPrototypeOf(source) === Map.prototype) {
|
|
2541
2610
|
if (options.exportMapsAsObjects === false) {
|
|
2542
|
-
var
|
|
2611
|
+
var res_4 = cache(__alreadySeen, source, new Map(), options);
|
|
2543
2612
|
source.forEach(function (value, key) {
|
|
2544
|
-
|
|
2613
|
+
res_4.set(key, toJSHelper(value, options, __alreadySeen));
|
|
2545
2614
|
});
|
|
2546
|
-
return
|
|
2615
|
+
return res_4;
|
|
2547
2616
|
}
|
|
2548
2617
|
else {
|
|
2549
|
-
var
|
|
2618
|
+
var res_5 = cache(__alreadySeen, source, {}, options);
|
|
2550
2619
|
source.forEach(function (value, key) {
|
|
2551
|
-
|
|
2620
|
+
res_5[key] = toJSHelper(value, options, __alreadySeen);
|
|
2552
2621
|
});
|
|
2553
|
-
return
|
|
2622
|
+
return res_5;
|
|
2554
2623
|
}
|
|
2555
2624
|
}
|
|
2556
2625
|
// Fallback to the situation that source is an ObservableObject or a plain object
|
|
@@ -3411,8 +3480,11 @@ var ObservableMap$$1 = /** @class */ (function () {
|
|
|
3411
3480
|
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
3412
3481
|
return _this.set(key, value);
|
|
3413
3482
|
});
|
|
3414
|
-
else if (isES6Map$$1(other))
|
|
3483
|
+
else if (isES6Map$$1(other)) {
|
|
3484
|
+
if (other.constructor !== Map)
|
|
3485
|
+
return fail$$1("Cannot initialize from classes that inherit from Map: " + other.constructor.name); // prettier-ignore
|
|
3415
3486
|
other.forEach(function (value, key) { return _this.set(key, value); });
|
|
3487
|
+
}
|
|
3416
3488
|
else if (other !== null && other !== undefined)
|
|
3417
3489
|
fail$$1("Cannot initialize map from " + other);
|
|
3418
3490
|
});
|
|
@@ -3522,6 +3594,224 @@ var ObservableMap$$1 = /** @class */ (function () {
|
|
|
3522
3594
|
/* 'var' fixes small-build issue */
|
|
3523
3595
|
var isObservableMap$$1 = createInstanceofPredicate$$1("ObservableMap", ObservableMap$$1);
|
|
3524
3596
|
|
|
3597
|
+
var _a$1;
|
|
3598
|
+
var ObservableSetMarker = {};
|
|
3599
|
+
var ObservableSet$$1 = /** @class */ (function () {
|
|
3600
|
+
function ObservableSet$$1(initialData, enhancer, name) {
|
|
3601
|
+
if (enhancer === void 0) { enhancer = deepEnhancer$$1; }
|
|
3602
|
+
if (name === void 0) { name = "ObservableSet@" + getNextId$$1(); }
|
|
3603
|
+
this.name = name;
|
|
3604
|
+
this[_a$1] = ObservableSetMarker;
|
|
3605
|
+
this._data = new Set();
|
|
3606
|
+
this._atom = createAtom$$1(this.name);
|
|
3607
|
+
this[Symbol.toStringTag] = "Set";
|
|
3608
|
+
if (typeof Set !== "function") {
|
|
3609
|
+
throw new Error("mobx.set requires Set polyfill for the current browser. Check babel-polyfill or core-js/es6/set.js");
|
|
3610
|
+
}
|
|
3611
|
+
this.enhancer = function (newV, oldV) { return enhancer(newV, oldV, name); };
|
|
3612
|
+
if (initialData) {
|
|
3613
|
+
this.replace(initialData);
|
|
3614
|
+
}
|
|
3615
|
+
}
|
|
3616
|
+
ObservableSet$$1.prototype.dehanceValue = function (value) {
|
|
3617
|
+
if (this.dehancer !== undefined) {
|
|
3618
|
+
return this.dehancer(value);
|
|
3619
|
+
}
|
|
3620
|
+
return value;
|
|
3621
|
+
};
|
|
3622
|
+
ObservableSet$$1.prototype.clear = function () {
|
|
3623
|
+
var _this = this;
|
|
3624
|
+
transaction$$1(function () {
|
|
3625
|
+
untracked$$1(function () {
|
|
3626
|
+
var e_1, _a;
|
|
3627
|
+
try {
|
|
3628
|
+
for (var _b = __values(_this._data.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
3629
|
+
var value = _c.value;
|
|
3630
|
+
_this.delete(value);
|
|
3631
|
+
}
|
|
3632
|
+
}
|
|
3633
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
3634
|
+
finally {
|
|
3635
|
+
try {
|
|
3636
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
3637
|
+
}
|
|
3638
|
+
finally { if (e_1) throw e_1.error; }
|
|
3639
|
+
}
|
|
3640
|
+
});
|
|
3641
|
+
});
|
|
3642
|
+
};
|
|
3643
|
+
ObservableSet$$1.prototype.forEach = function (callbackFn, thisArg) {
|
|
3644
|
+
var e_2, _a;
|
|
3645
|
+
try {
|
|
3646
|
+
for (var _b = __values(this), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
3647
|
+
var value = _c.value;
|
|
3648
|
+
callbackFn.call(thisArg, value, value, this);
|
|
3649
|
+
}
|
|
3650
|
+
}
|
|
3651
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
3652
|
+
finally {
|
|
3653
|
+
try {
|
|
3654
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
3655
|
+
}
|
|
3656
|
+
finally { if (e_2) throw e_2.error; }
|
|
3657
|
+
}
|
|
3658
|
+
};
|
|
3659
|
+
Object.defineProperty(ObservableSet$$1.prototype, "size", {
|
|
3660
|
+
get: function () {
|
|
3661
|
+
this._atom.reportObserved();
|
|
3662
|
+
return this._data.size;
|
|
3663
|
+
},
|
|
3664
|
+
enumerable: true,
|
|
3665
|
+
configurable: true
|
|
3666
|
+
});
|
|
3667
|
+
ObservableSet$$1.prototype.add = function (value) {
|
|
3668
|
+
var _this = this;
|
|
3669
|
+
checkIfStateModificationsAreAllowed$$1(this._atom);
|
|
3670
|
+
if (hasInterceptors$$1(this)) {
|
|
3671
|
+
var change = interceptChange$$1(this, {
|
|
3672
|
+
type: "add",
|
|
3673
|
+
object: this,
|
|
3674
|
+
newValue: value
|
|
3675
|
+
});
|
|
3676
|
+
if (!change)
|
|
3677
|
+
return this;
|
|
3678
|
+
// TODO: ideally, value = change.value would be done here, so that values can be
|
|
3679
|
+
// changed by interceptor. Same applies for other Set and Map api's.
|
|
3680
|
+
}
|
|
3681
|
+
if (!this.has(value)) {
|
|
3682
|
+
transaction$$1(function () {
|
|
3683
|
+
_this._data.add(_this.enhancer(value, undefined));
|
|
3684
|
+
_this._atom.reportChanged();
|
|
3685
|
+
});
|
|
3686
|
+
var notifySpy = isSpyEnabled$$1();
|
|
3687
|
+
var notify = hasListeners$$1(this);
|
|
3688
|
+
var change = notify || notifySpy
|
|
3689
|
+
? {
|
|
3690
|
+
type: "add",
|
|
3691
|
+
object: this,
|
|
3692
|
+
newValue: value
|
|
3693
|
+
}
|
|
3694
|
+
: null;
|
|
3695
|
+
if (notifySpy && process.env.NODE_ENV !== "production")
|
|
3696
|
+
spyReportStart$$1(change);
|
|
3697
|
+
if (notify)
|
|
3698
|
+
notifyListeners$$1(this, change);
|
|
3699
|
+
if (notifySpy && process.env.NODE_ENV !== "production")
|
|
3700
|
+
spyReportEnd$$1();
|
|
3701
|
+
}
|
|
3702
|
+
return this;
|
|
3703
|
+
};
|
|
3704
|
+
ObservableSet$$1.prototype.delete = function (value) {
|
|
3705
|
+
var _this = this;
|
|
3706
|
+
if (hasInterceptors$$1(this)) {
|
|
3707
|
+
var change = interceptChange$$1(this, {
|
|
3708
|
+
type: "delete",
|
|
3709
|
+
object: this,
|
|
3710
|
+
oldValue: value
|
|
3711
|
+
});
|
|
3712
|
+
if (!change)
|
|
3713
|
+
return false;
|
|
3714
|
+
}
|
|
3715
|
+
if (this.has(value)) {
|
|
3716
|
+
var notifySpy = isSpyEnabled$$1();
|
|
3717
|
+
var notify = hasListeners$$1(this);
|
|
3718
|
+
var change = notify || notifySpy
|
|
3719
|
+
? {
|
|
3720
|
+
type: "delete",
|
|
3721
|
+
object: this,
|
|
3722
|
+
oldValue: value
|
|
3723
|
+
}
|
|
3724
|
+
: null;
|
|
3725
|
+
if (notifySpy && process.env.NODE_ENV !== "production")
|
|
3726
|
+
spyReportStart$$1(__assign({}, change, { name: this.name }));
|
|
3727
|
+
transaction$$1(function () {
|
|
3728
|
+
_this._atom.reportChanged();
|
|
3729
|
+
_this._data.delete(value);
|
|
3730
|
+
});
|
|
3731
|
+
if (notify)
|
|
3732
|
+
notifyListeners$$1(this, change);
|
|
3733
|
+
if (notifySpy && process.env.NODE_ENV !== "production")
|
|
3734
|
+
spyReportEnd$$1();
|
|
3735
|
+
return true;
|
|
3736
|
+
}
|
|
3737
|
+
return false;
|
|
3738
|
+
};
|
|
3739
|
+
ObservableSet$$1.prototype.has = function (value) {
|
|
3740
|
+
this._atom.reportObserved();
|
|
3741
|
+
return this._data.has(this.dehanceValue(value));
|
|
3742
|
+
};
|
|
3743
|
+
ObservableSet$$1.prototype.entries = function () {
|
|
3744
|
+
var nextIndex = 0;
|
|
3745
|
+
var keys$$1 = Array.from(this.keys());
|
|
3746
|
+
var values$$1 = Array.from(this.values());
|
|
3747
|
+
return makeIterable({
|
|
3748
|
+
next: function () {
|
|
3749
|
+
var index = nextIndex;
|
|
3750
|
+
nextIndex += 1;
|
|
3751
|
+
return index < values$$1.length
|
|
3752
|
+
? { value: [keys$$1[index], values$$1[index]], done: false }
|
|
3753
|
+
: { done: true };
|
|
3754
|
+
}
|
|
3755
|
+
});
|
|
3756
|
+
};
|
|
3757
|
+
ObservableSet$$1.prototype.keys = function () {
|
|
3758
|
+
return this.values();
|
|
3759
|
+
};
|
|
3760
|
+
ObservableSet$$1.prototype.values = function () {
|
|
3761
|
+
this._atom.reportObserved();
|
|
3762
|
+
var self = this;
|
|
3763
|
+
var nextIndex = 0;
|
|
3764
|
+
var observableValues = Array.from(this._data.values());
|
|
3765
|
+
return makeIterable({
|
|
3766
|
+
next: function () {
|
|
3767
|
+
return nextIndex < observableValues.length
|
|
3768
|
+
? { value: self.dehanceValue(observableValues[nextIndex++]), done: false }
|
|
3769
|
+
: { done: true };
|
|
3770
|
+
}
|
|
3771
|
+
});
|
|
3772
|
+
};
|
|
3773
|
+
ObservableSet$$1.prototype.replace = function (other) {
|
|
3774
|
+
var _this = this;
|
|
3775
|
+
if (isObservableSet$$1(other)) {
|
|
3776
|
+
other = other.toJS();
|
|
3777
|
+
}
|
|
3778
|
+
transaction$$1(function () {
|
|
3779
|
+
if (Array.isArray(other)) {
|
|
3780
|
+
_this.clear();
|
|
3781
|
+
other.forEach(function (value) { return _this.add(value); });
|
|
3782
|
+
}
|
|
3783
|
+
else if (isES6Set$$1(other)) {
|
|
3784
|
+
_this.clear();
|
|
3785
|
+
other.forEach(function (value) { return _this.add(value); });
|
|
3786
|
+
}
|
|
3787
|
+
else if (other !== null && other !== undefined) {
|
|
3788
|
+
fail$$1("Cannot initialize set from " + other);
|
|
3789
|
+
}
|
|
3790
|
+
});
|
|
3791
|
+
return this;
|
|
3792
|
+
};
|
|
3793
|
+
ObservableSet$$1.prototype.observe = function (listener, fireImmediately) {
|
|
3794
|
+
// TODO 'fireImmediately' can be true?
|
|
3795
|
+
process.env.NODE_ENV !== "production" &&
|
|
3796
|
+
invariant$$1(fireImmediately !== true, "`observe` doesn't support fireImmediately=true in combination with sets.");
|
|
3797
|
+
return registerListener$$1(this, listener);
|
|
3798
|
+
};
|
|
3799
|
+
ObservableSet$$1.prototype.intercept = function (handler) {
|
|
3800
|
+
return registerInterceptor$$1(this, handler);
|
|
3801
|
+
};
|
|
3802
|
+
ObservableSet$$1.prototype.toJS = function () {
|
|
3803
|
+
return new Set(this);
|
|
3804
|
+
};
|
|
3805
|
+
ObservableSet$$1.prototype.toString = function () {
|
|
3806
|
+
return this.name + "[ " + Array.from(this).join(", ") + " ]";
|
|
3807
|
+
};
|
|
3808
|
+
ObservableSet$$1.prototype[(_a$1 = $mobx$$1, Symbol.iterator)] = function () {
|
|
3809
|
+
return this.values();
|
|
3810
|
+
};
|
|
3811
|
+
return ObservableSet$$1;
|
|
3812
|
+
}());
|
|
3813
|
+
var isObservableSet$$1 = createInstanceofPredicate$$1("ObservableSet", ObservableSet$$1);
|
|
3814
|
+
|
|
3525
3815
|
var ObservableObjectAdministration$$1 = /** @class */ (function () {
|
|
3526
3816
|
function ObservableObjectAdministration$$1(target, values$$1, name, defaultEnhancer) {
|
|
3527
3817
|
if (values$$1 === void 0) { values$$1 = new Map(); }
|
|
@@ -3793,7 +4083,7 @@ function getAdministrationForComputedPropOwner(owner) {
|
|
|
3793
4083
|
function generateComputedPropConfig$$1(propName) {
|
|
3794
4084
|
return (computedPropertyConfigs[propName] ||
|
|
3795
4085
|
(computedPropertyConfigs[propName] = {
|
|
3796
|
-
configurable:
|
|
4086
|
+
configurable: false,
|
|
3797
4087
|
enumerable: false,
|
|
3798
4088
|
get: function () {
|
|
3799
4089
|
return getAdministrationForComputedPropOwner(this).read(propName);
|
|
@@ -3821,6 +4111,9 @@ function getAtom$$1(thing, property) {
|
|
|
3821
4111
|
"It is not possible to get index atoms from arrays");
|
|
3822
4112
|
return thing[$mobx$$1].atom;
|
|
3823
4113
|
}
|
|
4114
|
+
if (isObservableSet$$1(thing)) {
|
|
4115
|
+
return thing[$mobx$$1];
|
|
4116
|
+
}
|
|
3824
4117
|
if (isObservableMap$$1(thing)) {
|
|
3825
4118
|
var anyThing = thing;
|
|
3826
4119
|
if (property === undefined)
|
|
@@ -3863,7 +4156,7 @@ function getAdministration$$1(thing, property) {
|
|
|
3863
4156
|
return getAdministration$$1(getAtom$$1(thing, property));
|
|
3864
4157
|
if (isAtom$$1(thing) || isComputedValue$$1(thing) || isReaction$$1(thing))
|
|
3865
4158
|
return thing;
|
|
3866
|
-
if (isObservableMap$$1(thing))
|
|
4159
|
+
if (isObservableMap$$1(thing) || isObservableSet$$1(thing))
|
|
3867
4160
|
return thing;
|
|
3868
4161
|
// Initializers run lazily when transpiling to babel, so make sure they are run...
|
|
3869
4162
|
initializeInstance$$1(thing);
|
|
@@ -3875,7 +4168,7 @@ function getDebugName$$1(thing, property) {
|
|
|
3875
4168
|
var named;
|
|
3876
4169
|
if (property !== undefined)
|
|
3877
4170
|
named = getAtom$$1(thing, property);
|
|
3878
|
-
else if (isObservableObject$$1(thing) || isObservableMap$$1(thing))
|
|
4171
|
+
else if (isObservableObject$$1(thing) || isObservableMap$$1(thing) || isObservableSet$$1(thing))
|
|
3879
4172
|
named = getAdministration$$1(thing);
|
|
3880
4173
|
else
|
|
3881
4174
|
named = getAtom$$1(thing); // valid for arrays as well
|
|
@@ -4006,6 +4299,8 @@ function unwrap(a) {
|
|
|
4006
4299
|
return a.slice();
|
|
4007
4300
|
if (isES6Map$$1(a) || isObservableMap$$1(a))
|
|
4008
4301
|
return Array.from(a.entries());
|
|
4302
|
+
if (isES6Set$$1(a) || isObservableSet$$1(a))
|
|
4303
|
+
return Array.from(a.entries());
|
|
4009
4304
|
return a;
|
|
4010
4305
|
}
|
|
4011
4306
|
function has$1(a, key) {
|
|
@@ -4093,6 +4388,8 @@ exports.isBoxedObservable = isObservableValue$$1;
|
|
|
4093
4388
|
exports.isObservableArray = isObservableArray$$1;
|
|
4094
4389
|
exports.ObservableMap = ObservableMap$$1;
|
|
4095
4390
|
exports.isObservableMap = isObservableMap$$1;
|
|
4391
|
+
exports.ObservableSet = ObservableSet$$1;
|
|
4392
|
+
exports.isObservableSet = isObservableSet$$1;
|
|
4096
4393
|
exports.transaction = transaction$$1;
|
|
4097
4394
|
exports.observable = observable$$1;
|
|
4098
4395
|
exports.computed = computed$$1;
|