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.es6.js
CHANGED
|
@@ -103,6 +103,9 @@ function isArrayLike$$1(x) {
|
|
|
103
103
|
function isES6Map$$1(thing) {
|
|
104
104
|
return thing instanceof Map;
|
|
105
105
|
}
|
|
106
|
+
function isES6Set$$1(thing) {
|
|
107
|
+
return thing instanceof Set;
|
|
108
|
+
}
|
|
106
109
|
function getMapLikeKeys$$1(map) {
|
|
107
110
|
if (isPlainObject$$1(map))
|
|
108
111
|
return Object.keys(map);
|
|
@@ -274,12 +277,14 @@ function deepEnhancer$$1(v, _, name) {
|
|
|
274
277
|
return observable$$1.object(v, undefined, { name });
|
|
275
278
|
if (isES6Map$$1(v))
|
|
276
279
|
return observable$$1.map(v, { name });
|
|
280
|
+
if (isES6Set$$1(v))
|
|
281
|
+
return observable$$1.set(v, { name });
|
|
277
282
|
return v;
|
|
278
283
|
}
|
|
279
284
|
function shallowEnhancer$$1(v, _, name) {
|
|
280
285
|
if (v === undefined || v === null)
|
|
281
286
|
return v;
|
|
282
|
-
if (isObservableObject$$1(v) || isObservableArray$$1(v) || isObservableMap$$1(v))
|
|
287
|
+
if (isObservableObject$$1(v) || isObservableArray$$1(v) || isObservableMap$$1(v) || isObservableSet$$1(v))
|
|
283
288
|
return v;
|
|
284
289
|
if (Array.isArray(v))
|
|
285
290
|
return observable$$1.array(v, { name, deep: false });
|
|
@@ -287,8 +292,10 @@ function shallowEnhancer$$1(v, _, name) {
|
|
|
287
292
|
return observable$$1.object(v, undefined, { name, deep: false });
|
|
288
293
|
if (isES6Map$$1(v))
|
|
289
294
|
return observable$$1.map(v, { name, deep: false });
|
|
295
|
+
if (isES6Set$$1(v))
|
|
296
|
+
return observable$$1.set(v, { name, deep: false });
|
|
290
297
|
return fail$$1(process.env.NODE_ENV !== "production" &&
|
|
291
|
-
"The shallow modifier / decorator can only used in combination with arrays, objects and
|
|
298
|
+
"The shallow modifier / decorator can only used in combination with arrays, objects, maps and sets");
|
|
292
299
|
}
|
|
293
300
|
function referenceEnhancer$$1(newValue) {
|
|
294
301
|
// never turn into an observable
|
|
@@ -340,7 +347,7 @@ const defaultCreateObservableOptions$$1 = {
|
|
|
340
347
|
};
|
|
341
348
|
Object.freeze(defaultCreateObservableOptions$$1);
|
|
342
349
|
function assertValidOption(key) {
|
|
343
|
-
if (!/^(deep|name|defaultDecorator|proxy)$/.test(key))
|
|
350
|
+
if (!/^(deep|name|equals|defaultDecorator|proxy)$/.test(key))
|
|
344
351
|
fail$$1(`invalid option for (extend)observable: ${key}`);
|
|
345
352
|
}
|
|
346
353
|
function asCreateObservableOptions$$1(thing) {
|
|
@@ -385,7 +392,9 @@ function createObservable(v, arg2, arg3) {
|
|
|
385
392
|
? observable$$1.array(v, arg2)
|
|
386
393
|
: isES6Map$$1(v)
|
|
387
394
|
? observable$$1.map(v, arg2)
|
|
388
|
-
: v
|
|
395
|
+
: isES6Set$$1(v)
|
|
396
|
+
? observable$$1.set(v, arg2)
|
|
397
|
+
: v;
|
|
389
398
|
// this value could be converted to a new observable data structure, return it
|
|
390
399
|
if (res !== v)
|
|
391
400
|
return res;
|
|
@@ -398,7 +407,7 @@ const observableFactories = {
|
|
|
398
407
|
if (arguments.length > 2)
|
|
399
408
|
incorrectlyUsedAsDecorator("box");
|
|
400
409
|
const o = asCreateObservableOptions$$1(options);
|
|
401
|
-
return new ObservableValue$$1(value, getEnhancerFromOptions(o), o.name);
|
|
410
|
+
return new ObservableValue$$1(value, getEnhancerFromOptions(o), o.name, true, o.equals);
|
|
402
411
|
},
|
|
403
412
|
array(initialValues, options) {
|
|
404
413
|
if (arguments.length > 2)
|
|
@@ -412,6 +421,12 @@ const observableFactories = {
|
|
|
412
421
|
const o = asCreateObservableOptions$$1(options);
|
|
413
422
|
return new ObservableMap$$1(initialValues, getEnhancerFromOptions(o), o.name);
|
|
414
423
|
},
|
|
424
|
+
set(initialValues, options) {
|
|
425
|
+
if (arguments.length > 2)
|
|
426
|
+
incorrectlyUsedAsDecorator("set");
|
|
427
|
+
const o = asCreateObservableOptions$$1(options);
|
|
428
|
+
return new ObservableSet$$1(initialValues, getEnhancerFromOptions(o), o.name);
|
|
429
|
+
},
|
|
415
430
|
object(props, decorators, options) {
|
|
416
431
|
if (typeof arguments[1] === "string")
|
|
417
432
|
incorrectlyUsedAsDecorator("object");
|
|
@@ -491,11 +506,21 @@ function createAction$$1(actionName, fn) {
|
|
|
491
506
|
}
|
|
492
507
|
function executeAction$$1(actionName, fn, scope, args) {
|
|
493
508
|
const runInfo = startAction(actionName, fn, scope, args);
|
|
509
|
+
let shouldSupressReactionError = true;
|
|
494
510
|
try {
|
|
495
|
-
|
|
511
|
+
const res = fn.apply(scope, args);
|
|
512
|
+
shouldSupressReactionError = false;
|
|
513
|
+
return res;
|
|
496
514
|
}
|
|
497
515
|
finally {
|
|
498
|
-
|
|
516
|
+
if (shouldSupressReactionError) {
|
|
517
|
+
globalState$$1.suppressReactionErrors = shouldSupressReactionError;
|
|
518
|
+
endAction(runInfo);
|
|
519
|
+
globalState$$1.suppressReactionErrors = false;
|
|
520
|
+
}
|
|
521
|
+
else {
|
|
522
|
+
endAction(runInfo);
|
|
523
|
+
}
|
|
499
524
|
}
|
|
500
525
|
}
|
|
501
526
|
function startAction(actionName, fn, scope, args) {
|
|
@@ -565,9 +590,11 @@ function allowStateChangesInsideComputed$$1(func) {
|
|
|
565
590
|
}
|
|
566
591
|
|
|
567
592
|
class ObservableValue$$1 extends Atom$$1 {
|
|
568
|
-
constructor(value, enhancer, name = "ObservableValue@" + getNextId$$1(), notifySpy = true) {
|
|
593
|
+
constructor(value, enhancer, name = "ObservableValue@" + getNextId$$1(), notifySpy = true, equals = comparer$$1.default) {
|
|
569
594
|
super(name);
|
|
570
595
|
this.enhancer = enhancer;
|
|
596
|
+
this.name = name;
|
|
597
|
+
this.equals = equals;
|
|
571
598
|
this.hasUnreportedChange = false;
|
|
572
599
|
this.value = enhancer(value, undefined, name);
|
|
573
600
|
if (notifySpy && isSpyEnabled$$1() && process.env.NODE_ENV !== "production") {
|
|
@@ -612,7 +639,7 @@ class ObservableValue$$1 extends Atom$$1 {
|
|
|
612
639
|
}
|
|
613
640
|
// apply modifier
|
|
614
641
|
newValue = this.enhancer(newValue, this.value, this.name);
|
|
615
|
-
return this.value
|
|
642
|
+
return this.equals(this.value, newValue) ? globalState$$1.UNCHANGED : newValue;
|
|
616
643
|
}
|
|
617
644
|
setNewValue(newValue) {
|
|
618
645
|
const oldValue = this.value;
|
|
@@ -1211,6 +1238,11 @@ class MobXGlobals$$1 {
|
|
|
1211
1238
|
* the stack when an exception occurs while debugging.
|
|
1212
1239
|
*/
|
|
1213
1240
|
this.disableErrorBoundaries = false;
|
|
1241
|
+
/*
|
|
1242
|
+
* If true, we are already handling an exception in an action. Any errors in reactions should be supressed, as
|
|
1243
|
+
* they are not the cause, see: https://github.com/mobxjs/mobx/issues/1836
|
|
1244
|
+
*/
|
|
1245
|
+
this.suppressReactionErrors = false;
|
|
1214
1246
|
}
|
|
1215
1247
|
}
|
|
1216
1248
|
let canMergeGlobalState = true;
|
|
@@ -1462,7 +1494,7 @@ You are entering this break point because derivation '${derivation.name}' is bei
|
|
|
1462
1494
|
Just follow the stacktrace you should now see in the devtools to see precisely what piece of your code is causing this update
|
|
1463
1495
|
The stackframe you are looking for is at least ~6-8 stack-frames up.
|
|
1464
1496
|
|
|
1465
|
-
${derivation instanceof ComputedValue$$1 ? derivation.derivation.toString() : ""}
|
|
1497
|
+
${derivation instanceof ComputedValue$$1 ? derivation.derivation.toString().replace(/[*]\//g, "/") : ""}
|
|
1466
1498
|
|
|
1467
1499
|
The dependencies for this derivation are:
|
|
1468
1500
|
|
|
@@ -1575,9 +1607,14 @@ class Reaction$$1 {
|
|
|
1575
1607
|
}
|
|
1576
1608
|
if (globalState$$1.disableErrorBoundaries)
|
|
1577
1609
|
throw error;
|
|
1578
|
-
const message = `[mobx] Encountered an uncaught exception that was thrown by a reaction or observer component, in: '${this}`;
|
|
1579
|
-
|
|
1580
|
-
|
|
1610
|
+
const message = `[mobx] Encountered an uncaught exception that was thrown by a reaction or observer component, in: '${this}'`;
|
|
1611
|
+
if (globalState$$1.suppressReactionErrors) {
|
|
1612
|
+
console.warn(`[mobx] (error in reaction '${this.name}' suppressed, fix error of causing action below)`); // prettier-ignore
|
|
1613
|
+
}
|
|
1614
|
+
else {
|
|
1615
|
+
console.error(message, error);
|
|
1616
|
+
/** If debugging brought you here, please, read the above message :-). Tnx! */
|
|
1617
|
+
}
|
|
1581
1618
|
if (isSpyEnabled$$1()) {
|
|
1582
1619
|
spyReport$$1({
|
|
1583
1620
|
type: "error",
|
|
@@ -1953,6 +1990,9 @@ function interceptHook(hook, thing, arg2, arg3) {
|
|
|
1953
1990
|
|
|
1954
1991
|
function configure$$1(options) {
|
|
1955
1992
|
const { enforceActions, computedRequiresReaction, disableErrorBoundaries, reactionScheduler } = options;
|
|
1993
|
+
if (options.isolateGlobalState === true) {
|
|
1994
|
+
isolateGlobalState$$1();
|
|
1995
|
+
}
|
|
1956
1996
|
if (enforceActions !== undefined) {
|
|
1957
1997
|
if (typeof enforceActions === "boolean" || enforceActions === "strict")
|
|
1958
1998
|
deprecated$$1(`Deprecated value for 'enforceActions', use 'false' => '"never"', 'true' => '"observed"', '"strict"' => "'always'" instead`);
|
|
@@ -1979,9 +2019,6 @@ function configure$$1(options) {
|
|
|
1979
2019
|
if (computedRequiresReaction !== undefined) {
|
|
1980
2020
|
globalState$$1.computedRequiresReaction = !!computedRequiresReaction;
|
|
1981
2021
|
}
|
|
1982
|
-
if (options.isolateGlobalState === true) {
|
|
1983
|
-
isolateGlobalState$$1();
|
|
1984
|
-
}
|
|
1985
2022
|
if (disableErrorBoundaries !== undefined) {
|
|
1986
2023
|
if (disableErrorBoundaries === true)
|
|
1987
2024
|
console.warn("WARNING: Debug feature only. MobX will NOT recover from errors when `disableErrorBoundaries` is enabled.");
|
|
@@ -2100,7 +2137,7 @@ function flow$$1(generator) {
|
|
|
2100
2137
|
const gen = action$$1(`${name} - runid: ${runId} - init`, generator).apply(ctx, args);
|
|
2101
2138
|
let rejector;
|
|
2102
2139
|
let pendingPromise = undefined;
|
|
2103
|
-
const
|
|
2140
|
+
const promise = new Promise(function (resolve, reject) {
|
|
2104
2141
|
let stepId = 0;
|
|
2105
2142
|
rejector = reject;
|
|
2106
2143
|
function onFulfilled(res) {
|
|
@@ -2138,7 +2175,7 @@ function flow$$1(generator) {
|
|
|
2138
2175
|
}
|
|
2139
2176
|
onFulfilled(undefined); // kick off the process
|
|
2140
2177
|
});
|
|
2141
|
-
|
|
2178
|
+
promise.cancel = action$$1(`${name} - runid: ${runId} - cancel`, function () {
|
|
2142
2179
|
try {
|
|
2143
2180
|
if (pendingPromise)
|
|
2144
2181
|
cancelPromise(pendingPromise);
|
|
@@ -2155,7 +2192,7 @@ function flow$$1(generator) {
|
|
|
2155
2192
|
rejector(e); // there could be a throwing finally block
|
|
2156
2193
|
}
|
|
2157
2194
|
});
|
|
2158
|
-
return
|
|
2195
|
+
return promise;
|
|
2159
2196
|
};
|
|
2160
2197
|
}
|
|
2161
2198
|
function cancelPromise(promise) {
|
|
@@ -2263,11 +2300,14 @@ function keys$$1(obj) {
|
|
|
2263
2300
|
if (isObservableMap$$1(obj)) {
|
|
2264
2301
|
return Array.from(obj.keys());
|
|
2265
2302
|
}
|
|
2303
|
+
if (isObservableSet$$1(obj)) {
|
|
2304
|
+
return Array.from(obj.keys());
|
|
2305
|
+
}
|
|
2266
2306
|
if (isObservableArray$$1(obj)) {
|
|
2267
2307
|
return obj.map((_, index) => index);
|
|
2268
2308
|
}
|
|
2269
2309
|
return fail$$1(process.env.NODE_ENV !== "production" &&
|
|
2270
|
-
"'keys()' can only be used on observable objects, arrays and maps");
|
|
2310
|
+
"'keys()' can only be used on observable objects, arrays, sets and maps");
|
|
2271
2311
|
}
|
|
2272
2312
|
function values$$1(obj) {
|
|
2273
2313
|
if (isObservableObject$$1(obj)) {
|
|
@@ -2276,11 +2316,14 @@ function values$$1(obj) {
|
|
|
2276
2316
|
if (isObservableMap$$1(obj)) {
|
|
2277
2317
|
return keys$$1(obj).map(key => obj.get(key));
|
|
2278
2318
|
}
|
|
2319
|
+
if (isObservableSet$$1(obj)) {
|
|
2320
|
+
return Array.from(obj.values());
|
|
2321
|
+
}
|
|
2279
2322
|
if (isObservableArray$$1(obj)) {
|
|
2280
2323
|
return obj.slice();
|
|
2281
2324
|
}
|
|
2282
2325
|
return fail$$1(process.env.NODE_ENV !== "production" &&
|
|
2283
|
-
"'values()' can only be used on observable objects, arrays and maps");
|
|
2326
|
+
"'values()' can only be used on observable objects, arrays, sets and maps");
|
|
2284
2327
|
}
|
|
2285
2328
|
function entries$$1(obj) {
|
|
2286
2329
|
if (isObservableObject$$1(obj)) {
|
|
@@ -2289,6 +2332,9 @@ function entries$$1(obj) {
|
|
|
2289
2332
|
if (isObservableMap$$1(obj)) {
|
|
2290
2333
|
return keys$$1(obj).map(key => [key, obj.get(key)]);
|
|
2291
2334
|
}
|
|
2335
|
+
if (isObservableSet$$1(obj)) {
|
|
2336
|
+
return Array.from(obj.entries());
|
|
2337
|
+
}
|
|
2292
2338
|
if (isObservableArray$$1(obj)) {
|
|
2293
2339
|
return obj.map((key, index) => [index, key]);
|
|
2294
2340
|
}
|
|
@@ -2344,6 +2390,9 @@ function remove$$1(obj, key) {
|
|
|
2344
2390
|
else if (isObservableMap$$1(obj)) {
|
|
2345
2391
|
obj.delete(key);
|
|
2346
2392
|
}
|
|
2393
|
+
else if (isObservableSet$$1(obj)) {
|
|
2394
|
+
obj.delete(key);
|
|
2395
|
+
}
|
|
2347
2396
|
else if (isObservableArray$$1(obj)) {
|
|
2348
2397
|
if (typeof key !== "number")
|
|
2349
2398
|
key = parseInt(key, 10);
|
|
@@ -2364,6 +2413,9 @@ function has$$1(obj, key) {
|
|
|
2364
2413
|
else if (isObservableMap$$1(obj)) {
|
|
2365
2414
|
return obj.has(key);
|
|
2366
2415
|
}
|
|
2416
|
+
else if (isObservableSet$$1(obj)) {
|
|
2417
|
+
return obj.has(key);
|
|
2418
|
+
}
|
|
2367
2419
|
else if (isObservableArray$$1(obj)) {
|
|
2368
2420
|
return key >= 0 && key < obj.length;
|
|
2369
2421
|
}
|
|
@@ -2441,6 +2493,22 @@ function toJSHelper(source, options, __alreadySeen) {
|
|
|
2441
2493
|
res[i] = toAdd[i];
|
|
2442
2494
|
return res;
|
|
2443
2495
|
}
|
|
2496
|
+
if (isObservableSet$$1(source) || Object.getPrototypeOf(source) === Set.prototype) {
|
|
2497
|
+
if (options.exportMapsAsObjects === false) {
|
|
2498
|
+
const res = cache(__alreadySeen, source, new Set(), options);
|
|
2499
|
+
source.forEach(value => {
|
|
2500
|
+
res.add(toJSHelper(value, options, __alreadySeen));
|
|
2501
|
+
});
|
|
2502
|
+
return res;
|
|
2503
|
+
}
|
|
2504
|
+
else {
|
|
2505
|
+
const res = cache(__alreadySeen, source, [], options);
|
|
2506
|
+
source.forEach(value => {
|
|
2507
|
+
res.push(toJSHelper(value, options, __alreadySeen));
|
|
2508
|
+
});
|
|
2509
|
+
return res;
|
|
2510
|
+
}
|
|
2511
|
+
}
|
|
2444
2512
|
if (isObservableMap$$1(source) || Object.getPrototypeOf(source) === Map.prototype) {
|
|
2445
2513
|
if (options.exportMapsAsObjects === false) {
|
|
2446
2514
|
const res = cache(__alreadySeen, source, new Map(), options);
|
|
@@ -3271,8 +3339,11 @@ class ObservableMap$$1 {
|
|
|
3271
3339
|
Object.keys(other).forEach(key => this.set(key, other[key]));
|
|
3272
3340
|
else if (Array.isArray(other))
|
|
3273
3341
|
other.forEach(([key, value]) => this.set(key, value));
|
|
3274
|
-
else if (isES6Map$$1(other))
|
|
3342
|
+
else if (isES6Map$$1(other)) {
|
|
3343
|
+
if (other.constructor !== Map)
|
|
3344
|
+
return fail$$1("Cannot initialize from classes that inherit from Map: " + other.constructor.name); // prettier-ignore
|
|
3275
3345
|
other.forEach((value, key) => this.set(key, value));
|
|
3346
|
+
}
|
|
3276
3347
|
else if (other !== null && other !== undefined)
|
|
3277
3348
|
fail$$1("Cannot initialize map from " + other);
|
|
3278
3349
|
});
|
|
@@ -3351,6 +3422,190 @@ class ObservableMap$$1 {
|
|
|
3351
3422
|
/* 'var' fixes small-build issue */
|
|
3352
3423
|
var isObservableMap$$1 = createInstanceofPredicate$$1("ObservableMap", ObservableMap$$1);
|
|
3353
3424
|
|
|
3425
|
+
var _a$1;
|
|
3426
|
+
const ObservableSetMarker = {};
|
|
3427
|
+
class ObservableSet$$1 {
|
|
3428
|
+
constructor(initialData, enhancer = deepEnhancer$$1, name = "ObservableSet@" + getNextId$$1()) {
|
|
3429
|
+
this.name = name;
|
|
3430
|
+
this[_a$1] = ObservableSetMarker;
|
|
3431
|
+
this._data = new Set();
|
|
3432
|
+
this._atom = createAtom$$1(this.name);
|
|
3433
|
+
this[Symbol.toStringTag] = "Set";
|
|
3434
|
+
if (typeof Set !== "function") {
|
|
3435
|
+
throw new Error("mobx.set requires Set polyfill for the current browser. Check babel-polyfill or core-js/es6/set.js");
|
|
3436
|
+
}
|
|
3437
|
+
this.enhancer = (newV, oldV) => enhancer(newV, oldV, name);
|
|
3438
|
+
if (initialData) {
|
|
3439
|
+
this.replace(initialData);
|
|
3440
|
+
}
|
|
3441
|
+
}
|
|
3442
|
+
dehanceValue(value) {
|
|
3443
|
+
if (this.dehancer !== undefined) {
|
|
3444
|
+
return this.dehancer(value);
|
|
3445
|
+
}
|
|
3446
|
+
return value;
|
|
3447
|
+
}
|
|
3448
|
+
clear() {
|
|
3449
|
+
transaction$$1(() => {
|
|
3450
|
+
untracked$$1(() => {
|
|
3451
|
+
for (const value of this._data.values())
|
|
3452
|
+
this.delete(value);
|
|
3453
|
+
});
|
|
3454
|
+
});
|
|
3455
|
+
}
|
|
3456
|
+
forEach(callbackFn, thisArg) {
|
|
3457
|
+
for (const value of this) {
|
|
3458
|
+
callbackFn.call(thisArg, value, value, this);
|
|
3459
|
+
}
|
|
3460
|
+
}
|
|
3461
|
+
get size() {
|
|
3462
|
+
this._atom.reportObserved();
|
|
3463
|
+
return this._data.size;
|
|
3464
|
+
}
|
|
3465
|
+
add(value) {
|
|
3466
|
+
checkIfStateModificationsAreAllowed$$1(this._atom);
|
|
3467
|
+
if (hasInterceptors$$1(this)) {
|
|
3468
|
+
const change = interceptChange$$1(this, {
|
|
3469
|
+
type: "add",
|
|
3470
|
+
object: this,
|
|
3471
|
+
newValue: value
|
|
3472
|
+
});
|
|
3473
|
+
if (!change)
|
|
3474
|
+
return this;
|
|
3475
|
+
// TODO: ideally, value = change.value would be done here, so that values can be
|
|
3476
|
+
// changed by interceptor. Same applies for other Set and Map api's.
|
|
3477
|
+
}
|
|
3478
|
+
if (!this.has(value)) {
|
|
3479
|
+
transaction$$1(() => {
|
|
3480
|
+
this._data.add(this.enhancer(value, undefined));
|
|
3481
|
+
this._atom.reportChanged();
|
|
3482
|
+
});
|
|
3483
|
+
const notifySpy = isSpyEnabled$$1();
|
|
3484
|
+
const notify = hasListeners$$1(this);
|
|
3485
|
+
const change = notify || notifySpy
|
|
3486
|
+
? {
|
|
3487
|
+
type: "add",
|
|
3488
|
+
object: this,
|
|
3489
|
+
newValue: value
|
|
3490
|
+
}
|
|
3491
|
+
: null;
|
|
3492
|
+
if (notifySpy && process.env.NODE_ENV !== "production")
|
|
3493
|
+
spyReportStart$$1(change);
|
|
3494
|
+
if (notify)
|
|
3495
|
+
notifyListeners$$1(this, change);
|
|
3496
|
+
if (notifySpy && process.env.NODE_ENV !== "production")
|
|
3497
|
+
spyReportEnd$$1();
|
|
3498
|
+
}
|
|
3499
|
+
return this;
|
|
3500
|
+
}
|
|
3501
|
+
delete(value) {
|
|
3502
|
+
if (hasInterceptors$$1(this)) {
|
|
3503
|
+
const change = interceptChange$$1(this, {
|
|
3504
|
+
type: "delete",
|
|
3505
|
+
object: this,
|
|
3506
|
+
oldValue: value
|
|
3507
|
+
});
|
|
3508
|
+
if (!change)
|
|
3509
|
+
return false;
|
|
3510
|
+
}
|
|
3511
|
+
if (this.has(value)) {
|
|
3512
|
+
const notifySpy = isSpyEnabled$$1();
|
|
3513
|
+
const notify = hasListeners$$1(this);
|
|
3514
|
+
const change = notify || notifySpy
|
|
3515
|
+
? {
|
|
3516
|
+
type: "delete",
|
|
3517
|
+
object: this,
|
|
3518
|
+
oldValue: value
|
|
3519
|
+
}
|
|
3520
|
+
: null;
|
|
3521
|
+
if (notifySpy && process.env.NODE_ENV !== "production")
|
|
3522
|
+
spyReportStart$$1(Object.assign({}, change, { name: this.name }));
|
|
3523
|
+
transaction$$1(() => {
|
|
3524
|
+
this._atom.reportChanged();
|
|
3525
|
+
this._data.delete(value);
|
|
3526
|
+
});
|
|
3527
|
+
if (notify)
|
|
3528
|
+
notifyListeners$$1(this, change);
|
|
3529
|
+
if (notifySpy && process.env.NODE_ENV !== "production")
|
|
3530
|
+
spyReportEnd$$1();
|
|
3531
|
+
return true;
|
|
3532
|
+
}
|
|
3533
|
+
return false;
|
|
3534
|
+
}
|
|
3535
|
+
has(value) {
|
|
3536
|
+
this._atom.reportObserved();
|
|
3537
|
+
return this._data.has(this.dehanceValue(value));
|
|
3538
|
+
}
|
|
3539
|
+
entries() {
|
|
3540
|
+
let nextIndex = 0;
|
|
3541
|
+
const keys$$1 = Array.from(this.keys());
|
|
3542
|
+
const values$$1 = Array.from(this.values());
|
|
3543
|
+
return makeIterable({
|
|
3544
|
+
next() {
|
|
3545
|
+
const index = nextIndex;
|
|
3546
|
+
nextIndex += 1;
|
|
3547
|
+
return index < values$$1.length
|
|
3548
|
+
? { value: [keys$$1[index], values$$1[index]], done: false }
|
|
3549
|
+
: { done: true };
|
|
3550
|
+
}
|
|
3551
|
+
});
|
|
3552
|
+
}
|
|
3553
|
+
keys() {
|
|
3554
|
+
return this.values();
|
|
3555
|
+
}
|
|
3556
|
+
values() {
|
|
3557
|
+
this._atom.reportObserved();
|
|
3558
|
+
const self = this;
|
|
3559
|
+
let nextIndex = 0;
|
|
3560
|
+
const observableValues = Array.from(this._data.values());
|
|
3561
|
+
return makeIterable({
|
|
3562
|
+
next() {
|
|
3563
|
+
return nextIndex < observableValues.length
|
|
3564
|
+
? { value: self.dehanceValue(observableValues[nextIndex++]), done: false }
|
|
3565
|
+
: { done: true };
|
|
3566
|
+
}
|
|
3567
|
+
});
|
|
3568
|
+
}
|
|
3569
|
+
replace(other) {
|
|
3570
|
+
if (isObservableSet$$1(other)) {
|
|
3571
|
+
other = other.toJS();
|
|
3572
|
+
}
|
|
3573
|
+
transaction$$1(() => {
|
|
3574
|
+
if (Array.isArray(other)) {
|
|
3575
|
+
this.clear();
|
|
3576
|
+
other.forEach(value => this.add(value));
|
|
3577
|
+
}
|
|
3578
|
+
else if (isES6Set$$1(other)) {
|
|
3579
|
+
this.clear();
|
|
3580
|
+
other.forEach(value => this.add(value));
|
|
3581
|
+
}
|
|
3582
|
+
else if (other !== null && other !== undefined) {
|
|
3583
|
+
fail$$1("Cannot initialize set from " + other);
|
|
3584
|
+
}
|
|
3585
|
+
});
|
|
3586
|
+
return this;
|
|
3587
|
+
}
|
|
3588
|
+
observe(listener, fireImmediately) {
|
|
3589
|
+
// TODO 'fireImmediately' can be true?
|
|
3590
|
+
process.env.NODE_ENV !== "production" &&
|
|
3591
|
+
invariant$$1(fireImmediately !== true, "`observe` doesn't support fireImmediately=true in combination with sets.");
|
|
3592
|
+
return registerListener$$1(this, listener);
|
|
3593
|
+
}
|
|
3594
|
+
intercept(handler) {
|
|
3595
|
+
return registerInterceptor$$1(this, handler);
|
|
3596
|
+
}
|
|
3597
|
+
toJS() {
|
|
3598
|
+
return new Set(this);
|
|
3599
|
+
}
|
|
3600
|
+
toString() {
|
|
3601
|
+
return this.name + "[ " + Array.from(this).join(", ") + " ]";
|
|
3602
|
+
}
|
|
3603
|
+
[(_a$1 = $mobx$$1, Symbol.iterator)]() {
|
|
3604
|
+
return this.values();
|
|
3605
|
+
}
|
|
3606
|
+
}
|
|
3607
|
+
const isObservableSet$$1 = createInstanceofPredicate$$1("ObservableSet", ObservableSet$$1);
|
|
3608
|
+
|
|
3354
3609
|
class ObservableObjectAdministration$$1 {
|
|
3355
3610
|
constructor(target, values$$1 = new Map(), name, defaultEnhancer) {
|
|
3356
3611
|
this.target = target;
|
|
@@ -3605,7 +3860,7 @@ function getAdministrationForComputedPropOwner(owner) {
|
|
|
3605
3860
|
function generateComputedPropConfig$$1(propName) {
|
|
3606
3861
|
return (computedPropertyConfigs[propName] ||
|
|
3607
3862
|
(computedPropertyConfigs[propName] = {
|
|
3608
|
-
configurable:
|
|
3863
|
+
configurable: false,
|
|
3609
3864
|
enumerable: false,
|
|
3610
3865
|
get() {
|
|
3611
3866
|
return getAdministrationForComputedPropOwner(this).read(propName);
|
|
@@ -3633,6 +3888,9 @@ function getAtom$$1(thing, property) {
|
|
|
3633
3888
|
"It is not possible to get index atoms from arrays");
|
|
3634
3889
|
return thing[$mobx$$1].atom;
|
|
3635
3890
|
}
|
|
3891
|
+
if (isObservableSet$$1(thing)) {
|
|
3892
|
+
return thing[$mobx$$1];
|
|
3893
|
+
}
|
|
3636
3894
|
if (isObservableMap$$1(thing)) {
|
|
3637
3895
|
const anyThing = thing;
|
|
3638
3896
|
if (property === undefined)
|
|
@@ -3675,7 +3933,7 @@ function getAdministration$$1(thing, property) {
|
|
|
3675
3933
|
return getAdministration$$1(getAtom$$1(thing, property));
|
|
3676
3934
|
if (isAtom$$1(thing) || isComputedValue$$1(thing) || isReaction$$1(thing))
|
|
3677
3935
|
return thing;
|
|
3678
|
-
if (isObservableMap$$1(thing))
|
|
3936
|
+
if (isObservableMap$$1(thing) || isObservableSet$$1(thing))
|
|
3679
3937
|
return thing;
|
|
3680
3938
|
// Initializers run lazily when transpiling to babel, so make sure they are run...
|
|
3681
3939
|
initializeInstance$$1(thing);
|
|
@@ -3687,7 +3945,7 @@ function getDebugName$$1(thing, property) {
|
|
|
3687
3945
|
let named;
|
|
3688
3946
|
if (property !== undefined)
|
|
3689
3947
|
named = getAtom$$1(thing, property);
|
|
3690
|
-
else if (isObservableObject$$1(thing) || isObservableMap$$1(thing))
|
|
3948
|
+
else if (isObservableObject$$1(thing) || isObservableMap$$1(thing) || isObservableSet$$1(thing))
|
|
3691
3949
|
named = getAdministration$$1(thing);
|
|
3692
3950
|
else
|
|
3693
3951
|
named = getAtom$$1(thing); // valid for arrays as well
|
|
@@ -3818,6 +4076,8 @@ function unwrap(a) {
|
|
|
3818
4076
|
return a.slice();
|
|
3819
4077
|
if (isES6Map$$1(a) || isObservableMap$$1(a))
|
|
3820
4078
|
return Array.from(a.entries());
|
|
4079
|
+
if (isES6Set$$1(a) || isObservableSet$$1(a))
|
|
4080
|
+
return Array.from(a.entries());
|
|
3821
4081
|
return a;
|
|
3822
4082
|
}
|
|
3823
4083
|
function has$1(a, key) {
|
|
@@ -3867,7 +4127,7 @@ try {
|
|
|
3867
4127
|
process.env.NODE_ENV;
|
|
3868
4128
|
}
|
|
3869
4129
|
catch (e) {
|
|
3870
|
-
|
|
4130
|
+
const g = typeof window !== "undefined" ? window : global;
|
|
3871
4131
|
if (typeof process === "undefined")
|
|
3872
4132
|
g.process = {};
|
|
3873
4133
|
g.process.env = {};
|
|
@@ -3895,4 +4155,4 @@ if (typeof __MOBX_DEVTOOLS_GLOBAL_HOOK__ === "object") {
|
|
|
3895
4155
|
});
|
|
3896
4156
|
}
|
|
3897
4157
|
|
|
3898
|
-
export { Reaction$$1 as Reaction, untracked$$1 as untracked, IDerivationState, createAtom$$1 as createAtom, spy$$1 as spy, comparer$$1 as comparer, isObservableObject$$1 as isObservableObject, isObservableValue$$1 as isBoxedObservable, isObservableArray$$1 as isObservableArray, ObservableMap$$1 as ObservableMap, isObservableMap$$1 as isObservableMap, transaction$$1 as transaction, observable$$1 as observable, computed$$1 as computed, isObservable$$1 as isObservable, isObservableProp$$1 as isObservableProp, isComputed$$1 as isComputed, isComputedProp$$1 as isComputedProp, extendObservable$$1 as extendObservable, observe$$1 as observe, intercept$$1 as intercept, autorun$$1 as autorun, reaction$$1 as reaction, when$$1 as when, action$$1 as action, isAction$$1 as isAction, runInAction$$1 as runInAction, keys$$1 as keys, values$$1 as values, entries$$1 as entries, set$$1 as set, remove$$1 as remove, has$$1 as has, get$$1 as get, decorate$$1 as decorate, configure$$1 as configure, onBecomeObserved$$1 as onBecomeObserved, onBecomeUnobserved$$1 as onBecomeUnobserved, flow$$1 as flow, toJS$$1 as toJS, trace$$1 as trace, getDependencyTree$$1 as getDependencyTree, getObserverTree$$1 as getObserverTree, resetGlobalState$$1 as _resetGlobalState, getGlobalState$$1 as _getGlobalState, getDebugName$$1 as getDebugName, getAtom$$1 as getAtom, getAdministration$$1 as _getAdministration, allowStateChanges$$1 as _allowStateChanges, allowStateChangesInsideComputed$$1 as _allowStateChangesInsideComputed, isArrayLike$$1 as isArrayLike, $mobx$$1 as $mobx, isComputingDerivation$$1 as _isComputingDerivation, onReactionError$$1 as onReactionError, interceptReads$$1 as _interceptReads };
|
|
4158
|
+
export { Reaction$$1 as Reaction, untracked$$1 as untracked, IDerivationState, createAtom$$1 as createAtom, spy$$1 as spy, comparer$$1 as comparer, isObservableObject$$1 as isObservableObject, isObservableValue$$1 as isBoxedObservable, isObservableArray$$1 as isObservableArray, ObservableMap$$1 as ObservableMap, isObservableMap$$1 as isObservableMap, ObservableSet$$1 as ObservableSet, isObservableSet$$1 as isObservableSet, transaction$$1 as transaction, observable$$1 as observable, computed$$1 as computed, isObservable$$1 as isObservable, isObservableProp$$1 as isObservableProp, isComputed$$1 as isComputed, isComputedProp$$1 as isComputedProp, extendObservable$$1 as extendObservable, observe$$1 as observe, intercept$$1 as intercept, autorun$$1 as autorun, reaction$$1 as reaction, when$$1 as when, action$$1 as action, isAction$$1 as isAction, runInAction$$1 as runInAction, keys$$1 as keys, values$$1 as values, entries$$1 as entries, set$$1 as set, remove$$1 as remove, has$$1 as has, get$$1 as get, decorate$$1 as decorate, configure$$1 as configure, onBecomeObserved$$1 as onBecomeObserved, onBecomeUnobserved$$1 as onBecomeUnobserved, flow$$1 as flow, toJS$$1 as toJS, trace$$1 as trace, getDependencyTree$$1 as getDependencyTree, getObserverTree$$1 as getObserverTree, resetGlobalState$$1 as _resetGlobalState, getGlobalState$$1 as _getGlobalState, getDebugName$$1 as getDebugName, getAtom$$1 as getAtom, getAdministration$$1 as _getAdministration, allowStateChanges$$1 as _allowStateChanges, allowStateChangesInsideComputed$$1 as _allowStateChangesInsideComputed, isArrayLike$$1 as isArrayLike, $mobx$$1 as $mobx, isComputingDerivation$$1 as _isComputingDerivation, onReactionError$$1 as onReactionError, interceptReads$$1 as _interceptReads };
|