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