mobx 5.5.2 → 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);
@@ -217,11 +220,15 @@ var Atom$$1 = /** @class */ (function () {
217
220
  this.lastAccessedBy = 0;
218
221
  this.lowestObserverState = IDerivationState.NOT_TRACKING;
219
222
  }
220
- Atom$$1.prototype.onBecomeUnobserved = function () {
221
- // noop
222
- };
223
223
  Atom$$1.prototype.onBecomeObserved = function () {
224
- /* noop */
224
+ if (this.onBecomeObservedListeners) {
225
+ this.onBecomeObservedListeners.forEach(function (listener) { return listener(); });
226
+ }
227
+ };
228
+ Atom$$1.prototype.onBecomeUnobserved = function () {
229
+ if (this.onBecomeUnobservedListeners) {
230
+ this.onBecomeUnobservedListeners.forEach(function (listener) { return listener(); });
231
+ }
225
232
  };
226
233
  /**
227
234
  * Invoke this method to notify mobx that your atom has been used somehow.
@@ -248,8 +255,13 @@ function createAtom$$1(name, onBecomeObservedHandler, onBecomeUnobservedHandler)
248
255
  if (onBecomeObservedHandler === void 0) { onBecomeObservedHandler = noop$$1; }
249
256
  if (onBecomeUnobservedHandler === void 0) { onBecomeUnobservedHandler = noop$$1; }
250
257
  var atom = new Atom$$1(name);
251
- onBecomeObserved$$1(atom, onBecomeObservedHandler);
252
- onBecomeUnobserved$$1(atom, onBecomeUnobservedHandler);
258
+ // default `noop` listener will not initialize the hook Set
259
+ if (onBecomeObservedHandler !== noop$$1) {
260
+ onBecomeObserved$$1(atom, onBecomeObservedHandler);
261
+ }
262
+ if (onBecomeUnobservedHandler !== noop$$1) {
263
+ onBecomeUnobserved$$1(atom, onBecomeUnobservedHandler);
264
+ }
253
265
  return atom;
254
266
  }
255
267
 
@@ -354,12 +366,14 @@ function deepEnhancer$$1(v, _, name) {
354
366
  return observable$$1.object(v, undefined, { name: name });
355
367
  if (isES6Map$$1(v))
356
368
  return observable$$1.map(v, { name: name });
369
+ if (isES6Set$$1(v))
370
+ return observable$$1.set(v, { name: name });
357
371
  return v;
358
372
  }
359
373
  function shallowEnhancer$$1(v, _, name) {
360
374
  if (v === undefined || v === null)
361
375
  return v;
362
- if (isObservableObject$$1(v) || isObservableArray$$1(v) || isObservableMap$$1(v))
376
+ if (isObservableObject$$1(v) || isObservableArray$$1(v) || isObservableMap$$1(v) || isObservableSet$$1(v))
363
377
  return v;
364
378
  if (Array.isArray(v))
365
379
  return observable$$1.array(v, { name: name, deep: false });
@@ -367,8 +381,10 @@ function shallowEnhancer$$1(v, _, name) {
367
381
  return observable$$1.object(v, undefined, { name: name, deep: false });
368
382
  if (isES6Map$$1(v))
369
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 });
370
386
  return fail$$1(process.env.NODE_ENV !== "production" &&
371
- "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");
372
388
  }
373
389
  function referenceEnhancer$$1(newValue) {
374
390
  // never turn into an observable
@@ -420,7 +436,7 @@ var defaultCreateObservableOptions$$1 = {
420
436
  };
421
437
  Object.freeze(defaultCreateObservableOptions$$1);
422
438
  function assertValidOption(key) {
423
- if (!/^(deep|name|defaultDecorator|proxy)$/.test(key))
439
+ if (!/^(deep|name|equals|defaultDecorator|proxy)$/.test(key))
424
440
  fail$$1("invalid option for (extend)observable: " + key);
425
441
  }
426
442
  function asCreateObservableOptions$$1(thing) {
@@ -465,7 +481,9 @@ function createObservable(v, arg2, arg3) {
465
481
  ? observable$$1.array(v, arg2)
466
482
  : isES6Map$$1(v)
467
483
  ? observable$$1.map(v, arg2)
468
- : v;
484
+ : isES6Set$$1(v)
485
+ ? observable$$1.set(v, arg2)
486
+ : v;
469
487
  // this value could be converted to a new observable data structure, return it
470
488
  if (res !== v)
471
489
  return res;
@@ -478,7 +496,7 @@ var observableFactories = {
478
496
  if (arguments.length > 2)
479
497
  incorrectlyUsedAsDecorator("box");
480
498
  var o = asCreateObservableOptions$$1(options);
481
- return new ObservableValue$$1(value, getEnhancerFromOptions(o), o.name);
499
+ return new ObservableValue$$1(value, getEnhancerFromOptions(o), o.name, true, o.equals);
482
500
  },
483
501
  array: function (initialValues, options) {
484
502
  if (arguments.length > 2)
@@ -492,6 +510,12 @@ var observableFactories = {
492
510
  var o = asCreateObservableOptions$$1(options);
493
511
  return new ObservableMap$$1(initialValues, getEnhancerFromOptions(o), o.name);
494
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
+ },
495
519
  object: function (props, decorators, options) {
496
520
  if (typeof arguments[1] === "string")
497
521
  incorrectlyUsedAsDecorator("object");
@@ -525,8 +549,9 @@ var computedDecorator$$1 = createPropDecorator$$1(false, function (instance, pro
525
549
  var get$$1 = descriptor.get, set$$1 = descriptor.set; // initialValue is the descriptor for get / set props
526
550
  // Optimization: faster on decorator target or instance? Assuming target
527
551
  // Optimization: find out if declaring on instance isn't just faster. (also makes the property descriptor simpler). But, more memory usage..
552
+ // Forcing instance now, fixes hot reloadig issues on React Native:
528
553
  var options = decoratorArgs[0] || {};
529
- asObservableObject$$1(instance).addComputedProp(decoratorTarget, propertyName, __assign({ get: get$$1,
554
+ asObservableObject$$1(instance).addComputedProp(instance, propertyName, __assign({ get: get$$1,
530
555
  set: set$$1, context: instance }, options));
531
556
  });
532
557
  var computedStructDecorator = computedDecorator$$1({ equals: comparer$$1.structural });
@@ -570,11 +595,21 @@ function createAction$$1(actionName, fn) {
570
595
  }
571
596
  function executeAction$$1(actionName, fn, scope, args) {
572
597
  var runInfo = startAction(actionName, fn, scope, args);
598
+ var shouldSupressReactionError = true;
573
599
  try {
574
- return fn.apply(scope, args);
600
+ var res = fn.apply(scope, args);
601
+ shouldSupressReactionError = false;
602
+ return res;
575
603
  }
576
604
  finally {
577
- 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
+ }
578
613
  }
579
614
  }
580
615
  function startAction(actionName, fn, scope, args) {
@@ -643,14 +678,16 @@ function allowStateChangesInsideComputed$$1(func) {
643
678
  return res;
644
679
  }
645
680
 
646
- var UNCHANGED$$1 = {};
647
681
  var ObservableValue$$1 = /** @class */ (function (_super) {
648
682
  __extends(ObservableValue$$1, _super);
649
- function ObservableValue$$1(value, enhancer, name, notifySpy) {
683
+ function ObservableValue$$1(value, enhancer, name, notifySpy, equals) {
650
684
  if (name === void 0) { name = "ObservableValue@" + getNextId$$1(); }
651
685
  if (notifySpy === void 0) { notifySpy = true; }
686
+ if (equals === void 0) { equals = comparer$$1.default; }
652
687
  var _this = _super.call(this, name) || this;
653
688
  _this.enhancer = enhancer;
689
+ _this.name = name;
690
+ _this.equals = equals;
654
691
  _this.hasUnreportedChange = false;
655
692
  _this.value = enhancer(value, undefined, name);
656
693
  if (notifySpy && isSpyEnabled$$1() && process.env.NODE_ENV !== "production") {
@@ -667,7 +704,7 @@ var ObservableValue$$1 = /** @class */ (function (_super) {
667
704
  ObservableValue$$1.prototype.set = function (newValue) {
668
705
  var oldValue = this.value;
669
706
  newValue = this.prepareNewValue(newValue);
670
- if (newValue !== UNCHANGED$$1) {
707
+ if (newValue !== globalState$$1.UNCHANGED) {
671
708
  var notifySpy = isSpyEnabled$$1();
672
709
  if (notifySpy && process.env.NODE_ENV !== "production") {
673
710
  spyReportStart$$1({
@@ -691,12 +728,12 @@ var ObservableValue$$1 = /** @class */ (function (_super) {
691
728
  newValue: newValue
692
729
  });
693
730
  if (!change)
694
- return UNCHANGED$$1;
731
+ return globalState$$1.UNCHANGED;
695
732
  newValue = change.newValue;
696
733
  }
697
734
  // apply modifier
698
735
  newValue = this.enhancer(newValue, this.value, this.name);
699
- return this.value !== newValue ? newValue : UNCHANGED$$1;
736
+ return this.equals(this.value, newValue) ? globalState$$1.UNCHANGED : newValue;
700
737
  };
701
738
  ObservableValue$$1.prototype.setNewValue = function (newValue) {
702
739
  var oldValue = this.value;
@@ -793,7 +830,6 @@ var ComputedValue$$1 = /** @class */ (function () {
793
830
  this.isComputing = false; // to check for cycles
794
831
  this.isRunningSetter = false;
795
832
  this.isTracing = TraceMode$$1.NONE;
796
- this.firstGet = true;
797
833
  if (process.env.NODE_ENV !== "production" && !options.get)
798
834
  throw "[mobx] missing option for computed: get";
799
835
  this.derivation = options.get;
@@ -812,21 +848,24 @@ var ComputedValue$$1 = /** @class */ (function () {
812
848
  ComputedValue$$1.prototype.onBecomeStale = function () {
813
849
  propagateMaybeChanged$$1(this);
814
850
  };
815
- ComputedValue$$1.prototype.onBecomeUnobserved = function () { };
816
- ComputedValue$$1.prototype.onBecomeObserved = function () { };
851
+ ComputedValue$$1.prototype.onBecomeObserved = function () {
852
+ if (this.onBecomeObservedListeners) {
853
+ this.onBecomeObservedListeners.forEach(function (listener) { return listener(); });
854
+ }
855
+ };
856
+ ComputedValue$$1.prototype.onBecomeUnobserved = function () {
857
+ if (this.onBecomeUnobservedListeners) {
858
+ this.onBecomeUnobservedListeners.forEach(function (listener) { return listener(); });
859
+ }
860
+ };
817
861
  /**
818
862
  * Returns the current value of this computed value.
819
863
  * Will evaluate its computation first if needed.
820
864
  */
821
865
  ComputedValue$$1.prototype.get = function () {
822
- var _this = this;
823
- if (this.keepAlive && this.firstGet) {
824
- this.firstGet = false;
825
- autorun$$1(function () { return _this.get(); });
826
- }
827
866
  if (this.isComputing)
828
867
  fail$$1("Cycle detected in computation " + this.name + ": " + this.derivation);
829
- if (globalState$$1.inBatch === 0 && this.observers.size === 0) {
868
+ if (globalState$$1.inBatch === 0 && this.observers.size === 0 && !this.keepAlive) {
830
869
  if (shouldCompute$$1(this)) {
831
870
  this.warnAboutUntrackedRead();
832
871
  startBatch$$1(); // See perf test 'computed memoization'
@@ -912,8 +951,10 @@ var ComputedValue$$1 = /** @class */ (function () {
912
951
  return res;
913
952
  };
914
953
  ComputedValue$$1.prototype.suspend = function () {
915
- clearObserving$$1(this);
916
- this.value = undefined; // don't hold on to computed value!
954
+ if (!this.keepAlive) {
955
+ clearObserving$$1(this);
956
+ this.value = undefined; // don't hold on to computed value!
957
+ }
917
958
  };
918
959
  ComputedValue$$1.prototype.observe = function (listener, fireImmediately) {
919
960
  var _this = this;
@@ -1215,7 +1256,8 @@ var persistentKeys = [
1215
1256
  "enforceActions",
1216
1257
  "computedRequiresReaction",
1217
1258
  "disableErrorBoundaries",
1218
- "runId"
1259
+ "runId",
1260
+ "UNCHANGED"
1219
1261
  ];
1220
1262
  var MobXGlobals$$1 = /** @class */ (function () {
1221
1263
  function MobXGlobals$$1() {
@@ -1228,6 +1270,10 @@ var MobXGlobals$$1 = /** @class */ (function () {
1228
1270
  * internal state storage of MobX, and can be the same across many different package versions
1229
1271
  */
1230
1272
  this.version = 5;
1273
+ /**
1274
+ * globally unique token to signal unchanged
1275
+ */
1276
+ this.UNCHANGED = {};
1231
1277
  /**
1232
1278
  * Currently running derivation
1233
1279
  */
@@ -1290,6 +1336,11 @@ var MobXGlobals$$1 = /** @class */ (function () {
1290
1336
  * the stack when an exception occurs while debugging.
1291
1337
  */
1292
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;
1293
1344
  }
1294
1345
  return MobXGlobals$$1;
1295
1346
  }());
@@ -1311,6 +1362,8 @@ var globalState$$1 = (function () {
1311
1362
  }
1312
1363
  else if (global.__mobxGlobals) {
1313
1364
  global.__mobxInstanceCount += 1;
1365
+ if (!global.__mobxGlobals.UNCHANGED)
1366
+ global.__mobxGlobals.UNCHANGED = {}; // make merge backward compatible
1314
1367
  return global.__mobxGlobals;
1315
1368
  }
1316
1369
  else {
@@ -1532,7 +1585,7 @@ function logTraceInfo(derivation, observable$$1) {
1532
1585
  var lines = [];
1533
1586
  printDepTree(getDependencyTree$$1(derivation), lines, 1);
1534
1587
  // prettier-ignore
1535
- 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 ")();
1536
1589
  }
1537
1590
  }
1538
1591
  function printDepTree(tree, lines, depth) {
@@ -1641,9 +1694,14 @@ var Reaction$$1 = /** @class */ (function () {
1641
1694
  }
1642
1695
  if (globalState$$1.disableErrorBoundaries)
1643
1696
  throw error;
1644
- var message = "[mobx] Encountered an uncaught exception that was thrown by a reaction or observer component, in: '" + this;
1645
- console.error(message, error);
1646
- /** 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
+ }
1647
1705
  if (isSpyEnabled$$1()) {
1648
1706
  spyReport$$1({
1649
1707
  type: "error",
@@ -2000,20 +2058,32 @@ function onBecomeUnobserved$$1(thing, arg2, arg3) {
2000
2058
  function interceptHook(hook, thing, arg2, arg3) {
2001
2059
  var atom = typeof arg2 === "string" ? getAtom$$1(thing, arg2) : getAtom$$1(thing);
2002
2060
  var cb = typeof arg2 === "string" ? arg3 : arg2;
2061
+ var listenersKey = hook + "Listeners";
2062
+ if (atom[listenersKey]) {
2063
+ atom[listenersKey].add(cb);
2064
+ }
2065
+ else {
2066
+ atom[listenersKey] = new Set([cb]);
2067
+ }
2003
2068
  var orig = atom[hook];
2004
2069
  if (typeof orig !== "function")
2005
2070
  return fail$$1(process.env.NODE_ENV !== "production" && "Not an atom that can be (un)observed");
2006
- atom[hook] = function () {
2007
- orig.call(this);
2008
- cb.call(this);
2009
- };
2010
2071
  return function () {
2011
- atom[hook] = orig;
2072
+ var hookListeners = atom[listenersKey];
2073
+ if (hookListeners) {
2074
+ hookListeners.delete(cb);
2075
+ if (hookListeners.size === 0) {
2076
+ delete atom[listenersKey];
2077
+ }
2078
+ }
2012
2079
  };
2013
2080
  }
2014
2081
 
2015
2082
  function configure$$1(options) {
2016
2083
  var enforceActions = options.enforceActions, computedRequiresReaction = options.computedRequiresReaction, disableErrorBoundaries = options.disableErrorBoundaries, reactionScheduler = options.reactionScheduler;
2084
+ if (options.isolateGlobalState === true) {
2085
+ isolateGlobalState$$1();
2086
+ }
2017
2087
  if (enforceActions !== undefined) {
2018
2088
  if (typeof enforceActions === "boolean" || enforceActions === "strict")
2019
2089
  deprecated$$1("Deprecated value for 'enforceActions', use 'false' => '\"never\"', 'true' => '\"observed\"', '\"strict\"' => \"'always'\" instead");
@@ -2040,9 +2110,6 @@ function configure$$1(options) {
2040
2110
  if (computedRequiresReaction !== undefined) {
2041
2111
  globalState$$1.computedRequiresReaction = !!computedRequiresReaction;
2042
2112
  }
2043
- if (options.isolateGlobalState === true) {
2044
- isolateGlobalState$$1();
2045
- }
2046
2113
  if (disableErrorBoundaries !== undefined) {
2047
2114
  if (disableErrorBoundaries === true)
2048
2115
  console.warn("WARNING: Debug feature only. MobX will NOT recover from errors when `disableErrorBoundaries` is enabled.");
@@ -2164,7 +2231,7 @@ function flow$$1(generator) {
2164
2231
  var gen = action$$1(name + " - runid: " + runId + " - init", generator).apply(ctx, args);
2165
2232
  var rejector;
2166
2233
  var pendingPromise = undefined;
2167
- var res = new Promise(function (resolve, reject) {
2234
+ var promise = new Promise(function (resolve, reject) {
2168
2235
  var stepId = 0;
2169
2236
  rejector = reject;
2170
2237
  function onFulfilled(res) {
@@ -2202,14 +2269,14 @@ function flow$$1(generator) {
2202
2269
  }
2203
2270
  onFulfilled(undefined); // kick off the process
2204
2271
  });
2205
- res.cancel = action$$1(name + " - runid: " + runId + " - cancel", function () {
2272
+ promise.cancel = action$$1(name + " - runid: " + runId + " - cancel", function () {
2206
2273
  try {
2207
2274
  if (pendingPromise)
2208
2275
  cancelPromise(pendingPromise);
2209
2276
  // Finally block can return (or yield) stuff..
2210
- var res_1 = gen.return();
2277
+ var res = gen.return();
2211
2278
  // eat anything that promise would do, it's cancelled!
2212
- var yieldedPromise = Promise.resolve(res_1.value);
2279
+ var yieldedPromise = Promise.resolve(res.value);
2213
2280
  yieldedPromise.then(noop$$1, noop$$1);
2214
2281
  cancelPromise(yieldedPromise); // maybe it can be cancelled :)
2215
2282
  // reject our original promise
@@ -2219,7 +2286,7 @@ function flow$$1(generator) {
2219
2286
  rejector(e); // there could be a throwing finally block
2220
2287
  }
2221
2288
  });
2222
- return res;
2289
+ return promise;
2223
2290
  };
2224
2291
  }
2225
2292
  function cancelPromise(promise) {
@@ -2327,11 +2394,14 @@ function keys$$1(obj) {
2327
2394
  if (isObservableMap$$1(obj)) {
2328
2395
  return Array.from(obj.keys());
2329
2396
  }
2397
+ if (isObservableSet$$1(obj)) {
2398
+ return Array.from(obj.keys());
2399
+ }
2330
2400
  if (isObservableArray$$1(obj)) {
2331
2401
  return obj.map(function (_, index) { return index; });
2332
2402
  }
2333
2403
  return fail$$1(process.env.NODE_ENV !== "production" &&
2334
- "'keys()' can only be used on observable objects, arrays and maps");
2404
+ "'keys()' can only be used on observable objects, arrays, sets and maps");
2335
2405
  }
2336
2406
  function values$$1(obj) {
2337
2407
  if (isObservableObject$$1(obj)) {
@@ -2340,11 +2410,14 @@ function values$$1(obj) {
2340
2410
  if (isObservableMap$$1(obj)) {
2341
2411
  return keys$$1(obj).map(function (key) { return obj.get(key); });
2342
2412
  }
2413
+ if (isObservableSet$$1(obj)) {
2414
+ return Array.from(obj.values());
2415
+ }
2343
2416
  if (isObservableArray$$1(obj)) {
2344
2417
  return obj.slice();
2345
2418
  }
2346
2419
  return fail$$1(process.env.NODE_ENV !== "production" &&
2347
- "'values()' can only be used on observable objects, arrays and maps");
2420
+ "'values()' can only be used on observable objects, arrays, sets and maps");
2348
2421
  }
2349
2422
  function entries$$1(obj) {
2350
2423
  if (isObservableObject$$1(obj)) {
@@ -2353,6 +2426,9 @@ function entries$$1(obj) {
2353
2426
  if (isObservableMap$$1(obj)) {
2354
2427
  return keys$$1(obj).map(function (key) { return [key, obj.get(key)]; });
2355
2428
  }
2429
+ if (isObservableSet$$1(obj)) {
2430
+ return Array.from(obj.entries());
2431
+ }
2356
2432
  if (isObservableArray$$1(obj)) {
2357
2433
  return obj.map(function (key, index) { return [index, key]; });
2358
2434
  }
@@ -2408,6 +2484,9 @@ function remove$$1(obj, key) {
2408
2484
  else if (isObservableMap$$1(obj)) {
2409
2485
  obj.delete(key);
2410
2486
  }
2487
+ else if (isObservableSet$$1(obj)) {
2488
+ obj.delete(key);
2489
+ }
2411
2490
  else if (isObservableArray$$1(obj)) {
2412
2491
  if (typeof key !== "number")
2413
2492
  key = parseInt(key, 10);
@@ -2428,6 +2507,9 @@ function has$$1(obj, key) {
2428
2507
  else if (isObservableMap$$1(obj)) {
2429
2508
  return obj.has(key);
2430
2509
  }
2510
+ else if (isObservableSet$$1(obj)) {
2511
+ return obj.has(key);
2512
+ }
2431
2513
  else if (isObservableArray$$1(obj)) {
2432
2514
  return key >= 0 && key < obj.length;
2433
2515
  }
@@ -2505,20 +2587,36 @@ function toJSHelper(source, options, __alreadySeen) {
2505
2587
  res_1[i] = toAdd[i];
2506
2588
  return res_1;
2507
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
+ }
2508
2606
  if (isObservableMap$$1(source) || Object.getPrototypeOf(source) === Map.prototype) {
2509
2607
  if (options.exportMapsAsObjects === false) {
2510
- var res_2 = cache(__alreadySeen, source, new Map(), options);
2608
+ var res_4 = cache(__alreadySeen, source, new Map(), options);
2511
2609
  source.forEach(function (value, key) {
2512
- res_2.set(key, toJSHelper(value, options, __alreadySeen));
2610
+ res_4.set(key, toJSHelper(value, options, __alreadySeen));
2513
2611
  });
2514
- return res_2;
2612
+ return res_4;
2515
2613
  }
2516
2614
  else {
2517
- var res_3 = cache(__alreadySeen, source, {}, options);
2615
+ var res_5 = cache(__alreadySeen, source, {}, options);
2518
2616
  source.forEach(function (value, key) {
2519
- res_3[key] = toJSHelper(value, options, __alreadySeen);
2617
+ res_5[key] = toJSHelper(value, options, __alreadySeen);
2520
2618
  });
2521
- return res_3;
2619
+ return res_5;
2522
2620
  }
2523
2621
  }
2524
2622
  // Fallback to the situation that source is an ObservableObject or a plain object
@@ -2659,8 +2757,16 @@ var objectProxyTraps = {
2659
2757
  return target[name];
2660
2758
  var adm = getAdm(target);
2661
2759
  var observable$$1 = adm.values.get(name);
2662
- if (observable$$1 instanceof Atom$$1)
2663
- return observable$$1.get();
2760
+ if (observable$$1 instanceof Atom$$1) {
2761
+ var result = observable$$1.get();
2762
+ if (result === undefined) {
2763
+ // This fixes #1796, because deleting a prop that has an
2764
+ // undefined value won't retrigger a observer (no visible effect),
2765
+ // the autorun wouldn't subscribe to future key changes (see also next comment)
2766
+ adm.has(name);
2767
+ }
2768
+ return result;
2769
+ }
2664
2770
  // make sure we start listening to future keys
2665
2771
  // note that we only do this here for optimization
2666
2772
  if (typeof name === "string")
@@ -2817,7 +2923,7 @@ var ObservableArrayAdministration = /** @class */ (function () {
2817
2923
  return value;
2818
2924
  };
2819
2925
  ObservableArrayAdministration.prototype.dehanceValues = function (values$$1) {
2820
- if (this.dehancer !== undefined && this.values.length > 0)
2926
+ if (this.dehancer !== undefined && values$$1.length > 0)
2821
2927
  return values$$1.map(this.dehancer);
2822
2928
  return values$$1;
2823
2929
  };
@@ -3246,7 +3352,7 @@ var ObservableMap$$1 = /** @class */ (function () {
3246
3352
  ObservableMap$$1.prototype._updateValue = function (key, newValue) {
3247
3353
  var observable$$1 = this._data.get(key);
3248
3354
  newValue = observable$$1.prepareNewValue(newValue);
3249
- if (newValue !== UNCHANGED$$1) {
3355
+ if (newValue !== globalState$$1.UNCHANGED) {
3250
3356
  var notifySpy = isSpyEnabled$$1();
3251
3357
  var notify = hasListeners$$1(this);
3252
3358
  var change = notify || notifySpy
@@ -3371,8 +3477,11 @@ var ObservableMap$$1 = /** @class */ (function () {
3371
3477
  var _b = __read(_a, 2), key = _b[0], value = _b[1];
3372
3478
  return _this.set(key, value);
3373
3479
  });
3374
- 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
3375
3483
  other.forEach(function (value, key) { return _this.set(key, value); });
3484
+ }
3376
3485
  else if (other !== null && other !== undefined)
3377
3486
  fail$$1("Cannot initialize map from " + other);
3378
3487
  });
@@ -3482,6 +3591,224 @@ var ObservableMap$$1 = /** @class */ (function () {
3482
3591
  /* 'var' fixes small-build issue */
3483
3592
  var isObservableMap$$1 = createInstanceofPredicate$$1("ObservableMap", ObservableMap$$1);
3484
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
+
3485
3812
  var ObservableObjectAdministration$$1 = /** @class */ (function () {
3486
3813
  function ObservableObjectAdministration$$1(target, values$$1, name, defaultEnhancer) {
3487
3814
  if (values$$1 === void 0) { values$$1 = new Map(); }
@@ -3515,7 +3842,7 @@ var ObservableObjectAdministration$$1 = /** @class */ (function () {
3515
3842
  }
3516
3843
  newValue = observable$$1.prepareNewValue(newValue);
3517
3844
  // notify spy & observers
3518
- if (newValue !== UNCHANGED$$1) {
3845
+ if (newValue !== globalState$$1.UNCHANGED) {
3519
3846
  var notify = hasListeners$$1(this);
3520
3847
  var notifySpy = isSpyEnabled$$1();
3521
3848
  var change = notify || notifySpy
@@ -3753,7 +4080,7 @@ function getAdministrationForComputedPropOwner(owner) {
3753
4080
  function generateComputedPropConfig$$1(propName) {
3754
4081
  return (computedPropertyConfigs[propName] ||
3755
4082
  (computedPropertyConfigs[propName] = {
3756
- configurable: true,
4083
+ configurable: false,
3757
4084
  enumerable: false,
3758
4085
  get: function () {
3759
4086
  return getAdministrationForComputedPropOwner(this).read(propName);
@@ -3781,6 +4108,9 @@ function getAtom$$1(thing, property) {
3781
4108
  "It is not possible to get index atoms from arrays");
3782
4109
  return thing[$mobx$$1].atom;
3783
4110
  }
4111
+ if (isObservableSet$$1(thing)) {
4112
+ return thing[$mobx$$1];
4113
+ }
3784
4114
  if (isObservableMap$$1(thing)) {
3785
4115
  var anyThing = thing;
3786
4116
  if (property === undefined)
@@ -3823,7 +4153,7 @@ function getAdministration$$1(thing, property) {
3823
4153
  return getAdministration$$1(getAtom$$1(thing, property));
3824
4154
  if (isAtom$$1(thing) || isComputedValue$$1(thing) || isReaction$$1(thing))
3825
4155
  return thing;
3826
- if (isObservableMap$$1(thing))
4156
+ if (isObservableMap$$1(thing) || isObservableSet$$1(thing))
3827
4157
  return thing;
3828
4158
  // Initializers run lazily when transpiling to babel, so make sure they are run...
3829
4159
  initializeInstance$$1(thing);
@@ -3835,7 +4165,7 @@ function getDebugName$$1(thing, property) {
3835
4165
  var named;
3836
4166
  if (property !== undefined)
3837
4167
  named = getAtom$$1(thing, property);
3838
- else if (isObservableObject$$1(thing) || isObservableMap$$1(thing))
4168
+ else if (isObservableObject$$1(thing) || isObservableMap$$1(thing) || isObservableSet$$1(thing))
3839
4169
  named = getAdministration$$1(thing);
3840
4170
  else
3841
4171
  named = getAtom$$1(thing); // valid for arrays as well
@@ -3966,6 +4296,8 @@ function unwrap(a) {
3966
4296
  return a.slice();
3967
4297
  if (isES6Map$$1(a) || isObservableMap$$1(a))
3968
4298
  return Array.from(a.entries());
4299
+ if (isES6Set$$1(a) || isObservableSet$$1(a))
4300
+ return Array.from(a.entries());
3969
4301
  return a;
3970
4302
  }
3971
4303
  function has$1(a, key) {
@@ -4024,7 +4356,8 @@ catch (e) {
4024
4356
  (function () {
4025
4357
  function testCodeMinification() { }
4026
4358
  if (testCodeMinification.name !== "testCodeMinification" &&
4027
- process.env.NODE_ENV !== "production") {
4359
+ process.env.NODE_ENV !== "production" &&
4360
+ process.env.IGNORE_MOBX_MINIFY_WARNING !== "true") {
4028
4361
  console.warn(
4029
4362
  // Template literal(backtick) is used for fix issue with rollup-plugin-commonjs https://github.com/rollup/rollup-plugin-commonjs/issues/344
4030
4363
  "[mobx] you are running a minified build, but 'process.env.NODE_ENV' was not set to 'production' in your bundler. This results in an unnecessarily large and slow bundle");
@@ -4042,4 +4375,4 @@ if (typeof __MOBX_DEVTOOLS_GLOBAL_HOOK__ === "object") {
4042
4375
  });
4043
4376
  }
4044
4377
 
4045
- 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 };