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.
@@ -185,6 +185,9 @@ function isArrayLike$$1(x) {
185
185
  function isES6Map$$1(thing) {
186
186
  return thing instanceof Map;
187
187
  }
188
+ function isES6Set$$1(thing) {
189
+ return thing instanceof Set;
190
+ }
188
191
  function getMapLikeKeys$$1(map) {
189
192
  if (isPlainObject$$1(map))
190
193
  return Object.keys(map);
@@ -363,12 +366,14 @@ function deepEnhancer$$1(v, _, name) {
363
366
  return observable$$1.object(v, undefined, { name: name });
364
367
  if (isES6Map$$1(v))
365
368
  return observable$$1.map(v, { name: name });
369
+ if (isES6Set$$1(v))
370
+ return observable$$1.set(v, { name: name });
366
371
  return v;
367
372
  }
368
373
  function shallowEnhancer$$1(v, _, name) {
369
374
  if (v === undefined || v === null)
370
375
  return v;
371
- if (isObservableObject$$1(v) || isObservableArray$$1(v) || isObservableMap$$1(v))
376
+ if (isObservableObject$$1(v) || isObservableArray$$1(v) || isObservableMap$$1(v) || isObservableSet$$1(v))
372
377
  return v;
373
378
  if (Array.isArray(v))
374
379
  return observable$$1.array(v, { name: name, deep: false });
@@ -376,8 +381,10 @@ function shallowEnhancer$$1(v, _, name) {
376
381
  return observable$$1.object(v, undefined, { name: name, deep: false });
377
382
  if (isES6Map$$1(v))
378
383
  return observable$$1.map(v, { name: name, deep: false });
384
+ if (isES6Set$$1(v))
385
+ return observable$$1.set(v, { name: name, deep: false });
379
386
  return fail$$1(process.env.NODE_ENV !== "production" &&
380
- "The shallow modifier / decorator can only used in combination with arrays, objects and maps");
387
+ "The shallow modifier / decorator can only used in combination with arrays, objects, maps and sets");
381
388
  }
382
389
  function referenceEnhancer$$1(newValue) {
383
390
  // never turn into an observable
@@ -429,7 +436,7 @@ var defaultCreateObservableOptions$$1 = {
429
436
  };
430
437
  Object.freeze(defaultCreateObservableOptions$$1);
431
438
  function assertValidOption(key) {
432
- if (!/^(deep|name|defaultDecorator|proxy)$/.test(key))
439
+ if (!/^(deep|name|equals|defaultDecorator|proxy)$/.test(key))
433
440
  fail$$1("invalid option for (extend)observable: " + key);
434
441
  }
435
442
  function asCreateObservableOptions$$1(thing) {
@@ -474,7 +481,9 @@ function createObservable(v, arg2, arg3) {
474
481
  ? observable$$1.array(v, arg2)
475
482
  : isES6Map$$1(v)
476
483
  ? observable$$1.map(v, arg2)
477
- : v;
484
+ : isES6Set$$1(v)
485
+ ? observable$$1.set(v, arg2)
486
+ : v;
478
487
  // this value could be converted to a new observable data structure, return it
479
488
  if (res !== v)
480
489
  return res;
@@ -487,7 +496,7 @@ var observableFactories = {
487
496
  if (arguments.length > 2)
488
497
  incorrectlyUsedAsDecorator("box");
489
498
  var o = asCreateObservableOptions$$1(options);
490
- return new ObservableValue$$1(value, getEnhancerFromOptions(o), o.name);
499
+ return new ObservableValue$$1(value, getEnhancerFromOptions(o), o.name, true, o.equals);
491
500
  },
492
501
  array: function (initialValues, options) {
493
502
  if (arguments.length > 2)
@@ -501,6 +510,12 @@ var observableFactories = {
501
510
  var o = asCreateObservableOptions$$1(options);
502
511
  return new ObservableMap$$1(initialValues, getEnhancerFromOptions(o), o.name);
503
512
  },
513
+ set: function (initialValues, options) {
514
+ if (arguments.length > 2)
515
+ incorrectlyUsedAsDecorator("set");
516
+ var o = asCreateObservableOptions$$1(options);
517
+ return new ObservableSet$$1(initialValues, getEnhancerFromOptions(o), o.name);
518
+ },
504
519
  object: function (props, decorators, options) {
505
520
  if (typeof arguments[1] === "string")
506
521
  incorrectlyUsedAsDecorator("object");
@@ -580,11 +595,21 @@ function createAction$$1(actionName, fn) {
580
595
  }
581
596
  function executeAction$$1(actionName, fn, scope, args) {
582
597
  var runInfo = startAction(actionName, fn, scope, args);
598
+ var shouldSupressReactionError = true;
583
599
  try {
584
- return fn.apply(scope, args);
600
+ var res = fn.apply(scope, args);
601
+ shouldSupressReactionError = false;
602
+ return res;
585
603
  }
586
604
  finally {
587
- endAction(runInfo);
605
+ if (shouldSupressReactionError) {
606
+ globalState$$1.suppressReactionErrors = shouldSupressReactionError;
607
+ endAction(runInfo);
608
+ globalState$$1.suppressReactionErrors = false;
609
+ }
610
+ else {
611
+ endAction(runInfo);
612
+ }
588
613
  }
589
614
  }
590
615
  function startAction(actionName, fn, scope, args) {
@@ -655,11 +680,14 @@ function allowStateChangesInsideComputed$$1(func) {
655
680
 
656
681
  var ObservableValue$$1 = /** @class */ (function (_super) {
657
682
  __extends(ObservableValue$$1, _super);
658
- function ObservableValue$$1(value, enhancer, name, notifySpy) {
683
+ function ObservableValue$$1(value, enhancer, name, notifySpy, equals) {
659
684
  if (name === void 0) { name = "ObservableValue@" + getNextId$$1(); }
660
685
  if (notifySpy === void 0) { notifySpy = true; }
686
+ if (equals === void 0) { equals = comparer$$1.default; }
661
687
  var _this = _super.call(this, name) || this;
662
688
  _this.enhancer = enhancer;
689
+ _this.name = name;
690
+ _this.equals = equals;
663
691
  _this.hasUnreportedChange = false;
664
692
  _this.value = enhancer(value, undefined, name);
665
693
  if (notifySpy && isSpyEnabled$$1() && process.env.NODE_ENV !== "production") {
@@ -705,7 +733,7 @@ var ObservableValue$$1 = /** @class */ (function (_super) {
705
733
  }
706
734
  // apply modifier
707
735
  newValue = this.enhancer(newValue, this.value, this.name);
708
- return this.value !== newValue ? newValue : globalState$$1.UNCHANGED;
736
+ return this.equals(this.value, newValue) ? globalState$$1.UNCHANGED : newValue;
709
737
  };
710
738
  ObservableValue$$1.prototype.setNewValue = function (newValue) {
711
739
  var oldValue = this.value;
@@ -1308,6 +1336,11 @@ var MobXGlobals$$1 = /** @class */ (function () {
1308
1336
  * the stack when an exception occurs while debugging.
1309
1337
  */
1310
1338
  this.disableErrorBoundaries = false;
1339
+ /*
1340
+ * If true, we are already handling an exception in an action. Any errors in reactions should be supressed, as
1341
+ * they are not the cause, see: https://github.com/mobxjs/mobx/issues/1836
1342
+ */
1343
+ this.suppressReactionErrors = false;
1311
1344
  }
1312
1345
  return MobXGlobals$$1;
1313
1346
  }());
@@ -1552,7 +1585,7 @@ function logTraceInfo(derivation, observable$$1) {
1552
1585
  var lines = [];
1553
1586
  printDepTree(getDependencyTree$$1(derivation), lines, 1);
1554
1587
  // prettier-ignore
1555
- 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 ")();
1588
+ 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 ")();
1556
1589
  }
1557
1590
  }
1558
1591
  function printDepTree(tree, lines, depth) {
@@ -1661,9 +1694,14 @@ var Reaction$$1 = /** @class */ (function () {
1661
1694
  }
1662
1695
  if (globalState$$1.disableErrorBoundaries)
1663
1696
  throw error;
1664
- var message = "[mobx] Encountered an uncaught exception that was thrown by a reaction or observer component, in: '" + this;
1665
- console.error(message, error);
1666
- /** If debugging brought you here, please, read the above message :-). Tnx! */
1697
+ var message = "[mobx] Encountered an uncaught exception that was thrown by a reaction or observer component, in: '" + this + "'";
1698
+ if (globalState$$1.suppressReactionErrors) {
1699
+ console.warn("[mobx] (error in reaction '" + this.name + "' suppressed, fix error of causing action below)"); // prettier-ignore
1700
+ }
1701
+ else {
1702
+ console.error(message, error);
1703
+ /** If debugging brought you here, please, read the above message :-). Tnx! */
1704
+ }
1667
1705
  if (isSpyEnabled$$1()) {
1668
1706
  spyReport$$1({
1669
1707
  type: "error",
@@ -2043,6 +2081,9 @@ function interceptHook(hook, thing, arg2, arg3) {
2043
2081
 
2044
2082
  function configure$$1(options) {
2045
2083
  var enforceActions = options.enforceActions, computedRequiresReaction = options.computedRequiresReaction, disableErrorBoundaries = options.disableErrorBoundaries, reactionScheduler = options.reactionScheduler;
2084
+ if (options.isolateGlobalState === true) {
2085
+ isolateGlobalState$$1();
2086
+ }
2046
2087
  if (enforceActions !== undefined) {
2047
2088
  if (typeof enforceActions === "boolean" || enforceActions === "strict")
2048
2089
  deprecated$$1("Deprecated value for 'enforceActions', use 'false' => '\"never\"', 'true' => '\"observed\"', '\"strict\"' => \"'always'\" instead");
@@ -2069,9 +2110,6 @@ function configure$$1(options) {
2069
2110
  if (computedRequiresReaction !== undefined) {
2070
2111
  globalState$$1.computedRequiresReaction = !!computedRequiresReaction;
2071
2112
  }
2072
- if (options.isolateGlobalState === true) {
2073
- isolateGlobalState$$1();
2074
- }
2075
2113
  if (disableErrorBoundaries !== undefined) {
2076
2114
  if (disableErrorBoundaries === true)
2077
2115
  console.warn("WARNING: Debug feature only. MobX will NOT recover from errors when `disableErrorBoundaries` is enabled.");
@@ -2193,7 +2231,7 @@ function flow$$1(generator) {
2193
2231
  var gen = action$$1(name + " - runid: " + runId + " - init", generator).apply(ctx, args);
2194
2232
  var rejector;
2195
2233
  var pendingPromise = undefined;
2196
- var res = new Promise(function (resolve, reject) {
2234
+ var promise = new Promise(function (resolve, reject) {
2197
2235
  var stepId = 0;
2198
2236
  rejector = reject;
2199
2237
  function onFulfilled(res) {
@@ -2231,14 +2269,14 @@ function flow$$1(generator) {
2231
2269
  }
2232
2270
  onFulfilled(undefined); // kick off the process
2233
2271
  });
2234
- res.cancel = action$$1(name + " - runid: " + runId + " - cancel", function () {
2272
+ promise.cancel = action$$1(name + " - runid: " + runId + " - cancel", function () {
2235
2273
  try {
2236
2274
  if (pendingPromise)
2237
2275
  cancelPromise(pendingPromise);
2238
2276
  // Finally block can return (or yield) stuff..
2239
- var res_1 = gen.return();
2277
+ var res = gen.return();
2240
2278
  // eat anything that promise would do, it's cancelled!
2241
- var yieldedPromise = Promise.resolve(res_1.value);
2279
+ var yieldedPromise = Promise.resolve(res.value);
2242
2280
  yieldedPromise.then(noop$$1, noop$$1);
2243
2281
  cancelPromise(yieldedPromise); // maybe it can be cancelled :)
2244
2282
  // reject our original promise
@@ -2248,7 +2286,7 @@ function flow$$1(generator) {
2248
2286
  rejector(e); // there could be a throwing finally block
2249
2287
  }
2250
2288
  });
2251
- return res;
2289
+ return promise;
2252
2290
  };
2253
2291
  }
2254
2292
  function cancelPromise(promise) {
@@ -2356,11 +2394,14 @@ function keys$$1(obj) {
2356
2394
  if (isObservableMap$$1(obj)) {
2357
2395
  return Array.from(obj.keys());
2358
2396
  }
2397
+ if (isObservableSet$$1(obj)) {
2398
+ return Array.from(obj.keys());
2399
+ }
2359
2400
  if (isObservableArray$$1(obj)) {
2360
2401
  return obj.map(function (_, index) { return index; });
2361
2402
  }
2362
2403
  return fail$$1(process.env.NODE_ENV !== "production" &&
2363
- "'keys()' can only be used on observable objects, arrays and maps");
2404
+ "'keys()' can only be used on observable objects, arrays, sets and maps");
2364
2405
  }
2365
2406
  function values$$1(obj) {
2366
2407
  if (isObservableObject$$1(obj)) {
@@ -2369,11 +2410,14 @@ function values$$1(obj) {
2369
2410
  if (isObservableMap$$1(obj)) {
2370
2411
  return keys$$1(obj).map(function (key) { return obj.get(key); });
2371
2412
  }
2413
+ if (isObservableSet$$1(obj)) {
2414
+ return Array.from(obj.values());
2415
+ }
2372
2416
  if (isObservableArray$$1(obj)) {
2373
2417
  return obj.slice();
2374
2418
  }
2375
2419
  return fail$$1(process.env.NODE_ENV !== "production" &&
2376
- "'values()' can only be used on observable objects, arrays and maps");
2420
+ "'values()' can only be used on observable objects, arrays, sets and maps");
2377
2421
  }
2378
2422
  function entries$$1(obj) {
2379
2423
  if (isObservableObject$$1(obj)) {
@@ -2382,6 +2426,9 @@ function entries$$1(obj) {
2382
2426
  if (isObservableMap$$1(obj)) {
2383
2427
  return keys$$1(obj).map(function (key) { return [key, obj.get(key)]; });
2384
2428
  }
2429
+ if (isObservableSet$$1(obj)) {
2430
+ return Array.from(obj.entries());
2431
+ }
2385
2432
  if (isObservableArray$$1(obj)) {
2386
2433
  return obj.map(function (key, index) { return [index, key]; });
2387
2434
  }
@@ -2437,6 +2484,9 @@ function remove$$1(obj, key) {
2437
2484
  else if (isObservableMap$$1(obj)) {
2438
2485
  obj.delete(key);
2439
2486
  }
2487
+ else if (isObservableSet$$1(obj)) {
2488
+ obj.delete(key);
2489
+ }
2440
2490
  else if (isObservableArray$$1(obj)) {
2441
2491
  if (typeof key !== "number")
2442
2492
  key = parseInt(key, 10);
@@ -2457,6 +2507,9 @@ function has$$1(obj, key) {
2457
2507
  else if (isObservableMap$$1(obj)) {
2458
2508
  return obj.has(key);
2459
2509
  }
2510
+ else if (isObservableSet$$1(obj)) {
2511
+ return obj.has(key);
2512
+ }
2460
2513
  else if (isObservableArray$$1(obj)) {
2461
2514
  return key >= 0 && key < obj.length;
2462
2515
  }
@@ -2534,20 +2587,36 @@ function toJSHelper(source, options, __alreadySeen) {
2534
2587
  res_1[i] = toAdd[i];
2535
2588
  return res_1;
2536
2589
  }
2590
+ if (isObservableSet$$1(source) || Object.getPrototypeOf(source) === Set.prototype) {
2591
+ if (options.exportMapsAsObjects === false) {
2592
+ var res_2 = cache(__alreadySeen, source, new Set(), options);
2593
+ source.forEach(function (value) {
2594
+ res_2.add(toJSHelper(value, options, __alreadySeen));
2595
+ });
2596
+ return res_2;
2597
+ }
2598
+ else {
2599
+ var res_3 = cache(__alreadySeen, source, [], options);
2600
+ source.forEach(function (value) {
2601
+ res_3.push(toJSHelper(value, options, __alreadySeen));
2602
+ });
2603
+ return res_3;
2604
+ }
2605
+ }
2537
2606
  if (isObservableMap$$1(source) || Object.getPrototypeOf(source) === Map.prototype) {
2538
2607
  if (options.exportMapsAsObjects === false) {
2539
- var res_2 = cache(__alreadySeen, source, new Map(), options);
2608
+ var res_4 = cache(__alreadySeen, source, new Map(), options);
2540
2609
  source.forEach(function (value, key) {
2541
- res_2.set(key, toJSHelper(value, options, __alreadySeen));
2610
+ res_4.set(key, toJSHelper(value, options, __alreadySeen));
2542
2611
  });
2543
- return res_2;
2612
+ return res_4;
2544
2613
  }
2545
2614
  else {
2546
- var res_3 = cache(__alreadySeen, source, {}, options);
2615
+ var res_5 = cache(__alreadySeen, source, {}, options);
2547
2616
  source.forEach(function (value, key) {
2548
- res_3[key] = toJSHelper(value, options, __alreadySeen);
2617
+ res_5[key] = toJSHelper(value, options, __alreadySeen);
2549
2618
  });
2550
- return res_3;
2619
+ return res_5;
2551
2620
  }
2552
2621
  }
2553
2622
  // Fallback to the situation that source is an ObservableObject or a plain object
@@ -3408,8 +3477,11 @@ var ObservableMap$$1 = /** @class */ (function () {
3408
3477
  var _b = __read(_a, 2), key = _b[0], value = _b[1];
3409
3478
  return _this.set(key, value);
3410
3479
  });
3411
- else if (isES6Map$$1(other))
3480
+ else if (isES6Map$$1(other)) {
3481
+ if (other.constructor !== Map)
3482
+ return fail$$1("Cannot initialize from classes that inherit from Map: " + other.constructor.name); // prettier-ignore
3412
3483
  other.forEach(function (value, key) { return _this.set(key, value); });
3484
+ }
3413
3485
  else if (other !== null && other !== undefined)
3414
3486
  fail$$1("Cannot initialize map from " + other);
3415
3487
  });
@@ -3519,6 +3591,224 @@ var ObservableMap$$1 = /** @class */ (function () {
3519
3591
  /* 'var' fixes small-build issue */
3520
3592
  var isObservableMap$$1 = createInstanceofPredicate$$1("ObservableMap", ObservableMap$$1);
3521
3593
 
3594
+ var _a$1;
3595
+ var ObservableSetMarker = {};
3596
+ var ObservableSet$$1 = /** @class */ (function () {
3597
+ function ObservableSet$$1(initialData, enhancer, name) {
3598
+ if (enhancer === void 0) { enhancer = deepEnhancer$$1; }
3599
+ if (name === void 0) { name = "ObservableSet@" + getNextId$$1(); }
3600
+ this.name = name;
3601
+ this[_a$1] = ObservableSetMarker;
3602
+ this._data = new Set();
3603
+ this._atom = createAtom$$1(this.name);
3604
+ this[Symbol.toStringTag] = "Set";
3605
+ if (typeof Set !== "function") {
3606
+ throw new Error("mobx.set requires Set polyfill for the current browser. Check babel-polyfill or core-js/es6/set.js");
3607
+ }
3608
+ this.enhancer = function (newV, oldV) { return enhancer(newV, oldV, name); };
3609
+ if (initialData) {
3610
+ this.replace(initialData);
3611
+ }
3612
+ }
3613
+ ObservableSet$$1.prototype.dehanceValue = function (value) {
3614
+ if (this.dehancer !== undefined) {
3615
+ return this.dehancer(value);
3616
+ }
3617
+ return value;
3618
+ };
3619
+ ObservableSet$$1.prototype.clear = function () {
3620
+ var _this = this;
3621
+ transaction$$1(function () {
3622
+ untracked$$1(function () {
3623
+ var e_1, _a;
3624
+ try {
3625
+ for (var _b = __values(_this._data.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
3626
+ var value = _c.value;
3627
+ _this.delete(value);
3628
+ }
3629
+ }
3630
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
3631
+ finally {
3632
+ try {
3633
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
3634
+ }
3635
+ finally { if (e_1) throw e_1.error; }
3636
+ }
3637
+ });
3638
+ });
3639
+ };
3640
+ ObservableSet$$1.prototype.forEach = function (callbackFn, thisArg) {
3641
+ var e_2, _a;
3642
+ try {
3643
+ for (var _b = __values(this), _c = _b.next(); !_c.done; _c = _b.next()) {
3644
+ var value = _c.value;
3645
+ callbackFn.call(thisArg, value, value, this);
3646
+ }
3647
+ }
3648
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
3649
+ finally {
3650
+ try {
3651
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
3652
+ }
3653
+ finally { if (e_2) throw e_2.error; }
3654
+ }
3655
+ };
3656
+ Object.defineProperty(ObservableSet$$1.prototype, "size", {
3657
+ get: function () {
3658
+ this._atom.reportObserved();
3659
+ return this._data.size;
3660
+ },
3661
+ enumerable: true,
3662
+ configurable: true
3663
+ });
3664
+ ObservableSet$$1.prototype.add = function (value) {
3665
+ var _this = this;
3666
+ checkIfStateModificationsAreAllowed$$1(this._atom);
3667
+ if (hasInterceptors$$1(this)) {
3668
+ var change = interceptChange$$1(this, {
3669
+ type: "add",
3670
+ object: this,
3671
+ newValue: value
3672
+ });
3673
+ if (!change)
3674
+ return this;
3675
+ // TODO: ideally, value = change.value would be done here, so that values can be
3676
+ // changed by interceptor. Same applies for other Set and Map api's.
3677
+ }
3678
+ if (!this.has(value)) {
3679
+ transaction$$1(function () {
3680
+ _this._data.add(_this.enhancer(value, undefined));
3681
+ _this._atom.reportChanged();
3682
+ });
3683
+ var notifySpy = isSpyEnabled$$1();
3684
+ var notify = hasListeners$$1(this);
3685
+ var change = notify || notifySpy
3686
+ ? {
3687
+ type: "add",
3688
+ object: this,
3689
+ newValue: value
3690
+ }
3691
+ : null;
3692
+ if (notifySpy && process.env.NODE_ENV !== "production")
3693
+ spyReportStart$$1(change);
3694
+ if (notify)
3695
+ notifyListeners$$1(this, change);
3696
+ if (notifySpy && process.env.NODE_ENV !== "production")
3697
+ spyReportEnd$$1();
3698
+ }
3699
+ return this;
3700
+ };
3701
+ ObservableSet$$1.prototype.delete = function (value) {
3702
+ var _this = this;
3703
+ if (hasInterceptors$$1(this)) {
3704
+ var change = interceptChange$$1(this, {
3705
+ type: "delete",
3706
+ object: this,
3707
+ oldValue: value
3708
+ });
3709
+ if (!change)
3710
+ return false;
3711
+ }
3712
+ if (this.has(value)) {
3713
+ var notifySpy = isSpyEnabled$$1();
3714
+ var notify = hasListeners$$1(this);
3715
+ var change = notify || notifySpy
3716
+ ? {
3717
+ type: "delete",
3718
+ object: this,
3719
+ oldValue: value
3720
+ }
3721
+ : null;
3722
+ if (notifySpy && process.env.NODE_ENV !== "production")
3723
+ spyReportStart$$1(__assign({}, change, { name: this.name }));
3724
+ transaction$$1(function () {
3725
+ _this._atom.reportChanged();
3726
+ _this._data.delete(value);
3727
+ });
3728
+ if (notify)
3729
+ notifyListeners$$1(this, change);
3730
+ if (notifySpy && process.env.NODE_ENV !== "production")
3731
+ spyReportEnd$$1();
3732
+ return true;
3733
+ }
3734
+ return false;
3735
+ };
3736
+ ObservableSet$$1.prototype.has = function (value) {
3737
+ this._atom.reportObserved();
3738
+ return this._data.has(this.dehanceValue(value));
3739
+ };
3740
+ ObservableSet$$1.prototype.entries = function () {
3741
+ var nextIndex = 0;
3742
+ var keys$$1 = Array.from(this.keys());
3743
+ var values$$1 = Array.from(this.values());
3744
+ return makeIterable({
3745
+ next: function () {
3746
+ var index = nextIndex;
3747
+ nextIndex += 1;
3748
+ return index < values$$1.length
3749
+ ? { value: [keys$$1[index], values$$1[index]], done: false }
3750
+ : { done: true };
3751
+ }
3752
+ });
3753
+ };
3754
+ ObservableSet$$1.prototype.keys = function () {
3755
+ return this.values();
3756
+ };
3757
+ ObservableSet$$1.prototype.values = function () {
3758
+ this._atom.reportObserved();
3759
+ var self = this;
3760
+ var nextIndex = 0;
3761
+ var observableValues = Array.from(this._data.values());
3762
+ return makeIterable({
3763
+ next: function () {
3764
+ return nextIndex < observableValues.length
3765
+ ? { value: self.dehanceValue(observableValues[nextIndex++]), done: false }
3766
+ : { done: true };
3767
+ }
3768
+ });
3769
+ };
3770
+ ObservableSet$$1.prototype.replace = function (other) {
3771
+ var _this = this;
3772
+ if (isObservableSet$$1(other)) {
3773
+ other = other.toJS();
3774
+ }
3775
+ transaction$$1(function () {
3776
+ if (Array.isArray(other)) {
3777
+ _this.clear();
3778
+ other.forEach(function (value) { return _this.add(value); });
3779
+ }
3780
+ else if (isES6Set$$1(other)) {
3781
+ _this.clear();
3782
+ other.forEach(function (value) { return _this.add(value); });
3783
+ }
3784
+ else if (other !== null && other !== undefined) {
3785
+ fail$$1("Cannot initialize set from " + other);
3786
+ }
3787
+ });
3788
+ return this;
3789
+ };
3790
+ ObservableSet$$1.prototype.observe = function (listener, fireImmediately) {
3791
+ // TODO 'fireImmediately' can be true?
3792
+ process.env.NODE_ENV !== "production" &&
3793
+ invariant$$1(fireImmediately !== true, "`observe` doesn't support fireImmediately=true in combination with sets.");
3794
+ return registerListener$$1(this, listener);
3795
+ };
3796
+ ObservableSet$$1.prototype.intercept = function (handler) {
3797
+ return registerInterceptor$$1(this, handler);
3798
+ };
3799
+ ObservableSet$$1.prototype.toJS = function () {
3800
+ return new Set(this);
3801
+ };
3802
+ ObservableSet$$1.prototype.toString = function () {
3803
+ return this.name + "[ " + Array.from(this).join(", ") + " ]";
3804
+ };
3805
+ ObservableSet$$1.prototype[(_a$1 = $mobx$$1, Symbol.iterator)] = function () {
3806
+ return this.values();
3807
+ };
3808
+ return ObservableSet$$1;
3809
+ }());
3810
+ var isObservableSet$$1 = createInstanceofPredicate$$1("ObservableSet", ObservableSet$$1);
3811
+
3522
3812
  var ObservableObjectAdministration$$1 = /** @class */ (function () {
3523
3813
  function ObservableObjectAdministration$$1(target, values$$1, name, defaultEnhancer) {
3524
3814
  if (values$$1 === void 0) { values$$1 = new Map(); }
@@ -3790,7 +4080,7 @@ function getAdministrationForComputedPropOwner(owner) {
3790
4080
  function generateComputedPropConfig$$1(propName) {
3791
4081
  return (computedPropertyConfigs[propName] ||
3792
4082
  (computedPropertyConfigs[propName] = {
3793
- configurable: true,
4083
+ configurable: false,
3794
4084
  enumerable: false,
3795
4085
  get: function () {
3796
4086
  return getAdministrationForComputedPropOwner(this).read(propName);
@@ -3818,6 +4108,9 @@ function getAtom$$1(thing, property) {
3818
4108
  "It is not possible to get index atoms from arrays");
3819
4109
  return thing[$mobx$$1].atom;
3820
4110
  }
4111
+ if (isObservableSet$$1(thing)) {
4112
+ return thing[$mobx$$1];
4113
+ }
3821
4114
  if (isObservableMap$$1(thing)) {
3822
4115
  var anyThing = thing;
3823
4116
  if (property === undefined)
@@ -3860,7 +4153,7 @@ function getAdministration$$1(thing, property) {
3860
4153
  return getAdministration$$1(getAtom$$1(thing, property));
3861
4154
  if (isAtom$$1(thing) || isComputedValue$$1(thing) || isReaction$$1(thing))
3862
4155
  return thing;
3863
- if (isObservableMap$$1(thing))
4156
+ if (isObservableMap$$1(thing) || isObservableSet$$1(thing))
3864
4157
  return thing;
3865
4158
  // Initializers run lazily when transpiling to babel, so make sure they are run...
3866
4159
  initializeInstance$$1(thing);
@@ -3872,7 +4165,7 @@ function getDebugName$$1(thing, property) {
3872
4165
  var named;
3873
4166
  if (property !== undefined)
3874
4167
  named = getAtom$$1(thing, property);
3875
- else if (isObservableObject$$1(thing) || isObservableMap$$1(thing))
4168
+ else if (isObservableObject$$1(thing) || isObservableMap$$1(thing) || isObservableSet$$1(thing))
3876
4169
  named = getAdministration$$1(thing);
3877
4170
  else
3878
4171
  named = getAtom$$1(thing); // valid for arrays as well
@@ -4003,6 +4296,8 @@ function unwrap(a) {
4003
4296
  return a.slice();
4004
4297
  if (isES6Map$$1(a) || isObservableMap$$1(a))
4005
4298
  return Array.from(a.entries());
4299
+ if (isES6Set$$1(a) || isObservableSet$$1(a))
4300
+ return Array.from(a.entries());
4006
4301
  return a;
4007
4302
  }
4008
4303
  function has$1(a, key) {
@@ -4080,4 +4375,4 @@ if (typeof __MOBX_DEVTOOLS_GLOBAL_HOOK__ === "object") {
4080
4375
  });
4081
4376
  }
4082
4377
 
4083
- 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 };
4378
+ 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 };