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.
package/lib/mobx.js CHANGED
@@ -189,6 +189,9 @@ function isArrayLike$$1(x) {
189
189
  function isES6Map$$1(thing) {
190
190
  return thing instanceof Map;
191
191
  }
192
+ function isES6Set$$1(thing) {
193
+ return thing instanceof Set;
194
+ }
192
195
  function getMapLikeKeys$$1(map) {
193
196
  if (isPlainObject$$1(map))
194
197
  return Object.keys(map);
@@ -221,11 +224,15 @@ var Atom$$1 = /** @class */ (function () {
221
224
  this.lastAccessedBy = 0;
222
225
  this.lowestObserverState = exports.IDerivationState.NOT_TRACKING;
223
226
  }
224
- Atom$$1.prototype.onBecomeUnobserved = function () {
225
- // noop
226
- };
227
227
  Atom$$1.prototype.onBecomeObserved = function () {
228
- /* noop */
228
+ if (this.onBecomeObservedListeners) {
229
+ this.onBecomeObservedListeners.forEach(function (listener) { return listener(); });
230
+ }
231
+ };
232
+ Atom$$1.prototype.onBecomeUnobserved = function () {
233
+ if (this.onBecomeUnobservedListeners) {
234
+ this.onBecomeUnobservedListeners.forEach(function (listener) { return listener(); });
235
+ }
229
236
  };
230
237
  /**
231
238
  * Invoke this method to notify mobx that your atom has been used somehow.
@@ -252,8 +259,13 @@ function createAtom$$1(name, onBecomeObservedHandler, onBecomeUnobservedHandler)
252
259
  if (onBecomeObservedHandler === void 0) { onBecomeObservedHandler = noop$$1; }
253
260
  if (onBecomeUnobservedHandler === void 0) { onBecomeUnobservedHandler = noop$$1; }
254
261
  var atom = new Atom$$1(name);
255
- onBecomeObserved$$1(atom, onBecomeObservedHandler);
256
- onBecomeUnobserved$$1(atom, onBecomeUnobservedHandler);
262
+ // default `noop` listener will not initialize the hook Set
263
+ if (onBecomeObservedHandler !== noop$$1) {
264
+ onBecomeObserved$$1(atom, onBecomeObservedHandler);
265
+ }
266
+ if (onBecomeUnobservedHandler !== noop$$1) {
267
+ onBecomeUnobserved$$1(atom, onBecomeUnobservedHandler);
268
+ }
257
269
  return atom;
258
270
  }
259
271
 
@@ -358,12 +370,14 @@ function deepEnhancer$$1(v, _, name) {
358
370
  return observable$$1.object(v, undefined, { name: name });
359
371
  if (isES6Map$$1(v))
360
372
  return observable$$1.map(v, { name: name });
373
+ if (isES6Set$$1(v))
374
+ return observable$$1.set(v, { name: name });
361
375
  return v;
362
376
  }
363
377
  function shallowEnhancer$$1(v, _, name) {
364
378
  if (v === undefined || v === null)
365
379
  return v;
366
- if (isObservableObject$$1(v) || isObservableArray$$1(v) || isObservableMap$$1(v))
380
+ if (isObservableObject$$1(v) || isObservableArray$$1(v) || isObservableMap$$1(v) || isObservableSet$$1(v))
367
381
  return v;
368
382
  if (Array.isArray(v))
369
383
  return observable$$1.array(v, { name: name, deep: false });
@@ -371,8 +385,10 @@ function shallowEnhancer$$1(v, _, name) {
371
385
  return observable$$1.object(v, undefined, { name: name, deep: false });
372
386
  if (isES6Map$$1(v))
373
387
  return observable$$1.map(v, { name: name, deep: false });
388
+ if (isES6Set$$1(v))
389
+ return observable$$1.set(v, { name: name, deep: false });
374
390
  return fail$$1(process.env.NODE_ENV !== "production" &&
375
- "The shallow modifier / decorator can only used in combination with arrays, objects and maps");
391
+ "The shallow modifier / decorator can only used in combination with arrays, objects, maps and sets");
376
392
  }
377
393
  function referenceEnhancer$$1(newValue) {
378
394
  // never turn into an observable
@@ -424,7 +440,7 @@ var defaultCreateObservableOptions$$1 = {
424
440
  };
425
441
  Object.freeze(defaultCreateObservableOptions$$1);
426
442
  function assertValidOption(key) {
427
- if (!/^(deep|name|defaultDecorator|proxy)$/.test(key))
443
+ if (!/^(deep|name|equals|defaultDecorator|proxy)$/.test(key))
428
444
  fail$$1("invalid option for (extend)observable: " + key);
429
445
  }
430
446
  function asCreateObservableOptions$$1(thing) {
@@ -469,7 +485,9 @@ function createObservable(v, arg2, arg3) {
469
485
  ? observable$$1.array(v, arg2)
470
486
  : isES6Map$$1(v)
471
487
  ? observable$$1.map(v, arg2)
472
- : v;
488
+ : isES6Set$$1(v)
489
+ ? observable$$1.set(v, arg2)
490
+ : v;
473
491
  // this value could be converted to a new observable data structure, return it
474
492
  if (res !== v)
475
493
  return res;
@@ -482,7 +500,7 @@ var observableFactories = {
482
500
  if (arguments.length > 2)
483
501
  incorrectlyUsedAsDecorator("box");
484
502
  var o = asCreateObservableOptions$$1(options);
485
- return new ObservableValue$$1(value, getEnhancerFromOptions(o), o.name);
503
+ return new ObservableValue$$1(value, getEnhancerFromOptions(o), o.name, true, o.equals);
486
504
  },
487
505
  array: function (initialValues, options) {
488
506
  if (arguments.length > 2)
@@ -496,6 +514,12 @@ var observableFactories = {
496
514
  var o = asCreateObservableOptions$$1(options);
497
515
  return new ObservableMap$$1(initialValues, getEnhancerFromOptions(o), o.name);
498
516
  },
517
+ set: function (initialValues, options) {
518
+ if (arguments.length > 2)
519
+ incorrectlyUsedAsDecorator("set");
520
+ var o = asCreateObservableOptions$$1(options);
521
+ return new ObservableSet$$1(initialValues, getEnhancerFromOptions(o), o.name);
522
+ },
499
523
  object: function (props, decorators, options) {
500
524
  if (typeof arguments[1] === "string")
501
525
  incorrectlyUsedAsDecorator("object");
@@ -529,8 +553,9 @@ var computedDecorator$$1 = createPropDecorator$$1(false, function (instance, pro
529
553
  var get$$1 = descriptor.get, set$$1 = descriptor.set; // initialValue is the descriptor for get / set props
530
554
  // Optimization: faster on decorator target or instance? Assuming target
531
555
  // Optimization: find out if declaring on instance isn't just faster. (also makes the property descriptor simpler). But, more memory usage..
556
+ // Forcing instance now, fixes hot reloadig issues on React Native:
532
557
  var options = decoratorArgs[0] || {};
533
- asObservableObject$$1(instance).addComputedProp(decoratorTarget, propertyName, __assign({ get: get$$1,
558
+ asObservableObject$$1(instance).addComputedProp(instance, propertyName, __assign({ get: get$$1,
534
559
  set: set$$1, context: instance }, options));
535
560
  });
536
561
  var computedStructDecorator = computedDecorator$$1({ equals: comparer$$1.structural });
@@ -574,11 +599,21 @@ function createAction$$1(actionName, fn) {
574
599
  }
575
600
  function executeAction$$1(actionName, fn, scope, args) {
576
601
  var runInfo = startAction(actionName, fn, scope, args);
602
+ var shouldSupressReactionError = true;
577
603
  try {
578
- return fn.apply(scope, args);
604
+ var res = fn.apply(scope, args);
605
+ shouldSupressReactionError = false;
606
+ return res;
579
607
  }
580
608
  finally {
581
- endAction(runInfo);
609
+ if (shouldSupressReactionError) {
610
+ globalState$$1.suppressReactionErrors = shouldSupressReactionError;
611
+ endAction(runInfo);
612
+ globalState$$1.suppressReactionErrors = false;
613
+ }
614
+ else {
615
+ endAction(runInfo);
616
+ }
582
617
  }
583
618
  }
584
619
  function startAction(actionName, fn, scope, args) {
@@ -647,14 +682,16 @@ function allowStateChangesInsideComputed$$1(func) {
647
682
  return res;
648
683
  }
649
684
 
650
- var UNCHANGED$$1 = {};
651
685
  var ObservableValue$$1 = /** @class */ (function (_super) {
652
686
  __extends(ObservableValue$$1, _super);
653
- function ObservableValue$$1(value, enhancer, name, notifySpy) {
687
+ function ObservableValue$$1(value, enhancer, name, notifySpy, equals) {
654
688
  if (name === void 0) { name = "ObservableValue@" + getNextId$$1(); }
655
689
  if (notifySpy === void 0) { notifySpy = true; }
690
+ if (equals === void 0) { equals = comparer$$1.default; }
656
691
  var _this = _super.call(this, name) || this;
657
692
  _this.enhancer = enhancer;
693
+ _this.name = name;
694
+ _this.equals = equals;
658
695
  _this.hasUnreportedChange = false;
659
696
  _this.value = enhancer(value, undefined, name);
660
697
  if (notifySpy && isSpyEnabled$$1() && process.env.NODE_ENV !== "production") {
@@ -671,7 +708,7 @@ var ObservableValue$$1 = /** @class */ (function (_super) {
671
708
  ObservableValue$$1.prototype.set = function (newValue) {
672
709
  var oldValue = this.value;
673
710
  newValue = this.prepareNewValue(newValue);
674
- if (newValue !== UNCHANGED$$1) {
711
+ if (newValue !== globalState$$1.UNCHANGED) {
675
712
  var notifySpy = isSpyEnabled$$1();
676
713
  if (notifySpy && process.env.NODE_ENV !== "production") {
677
714
  spyReportStart$$1({
@@ -695,12 +732,12 @@ var ObservableValue$$1 = /** @class */ (function (_super) {
695
732
  newValue: newValue
696
733
  });
697
734
  if (!change)
698
- return UNCHANGED$$1;
735
+ return globalState$$1.UNCHANGED;
699
736
  newValue = change.newValue;
700
737
  }
701
738
  // apply modifier
702
739
  newValue = this.enhancer(newValue, this.value, this.name);
703
- return this.value !== newValue ? newValue : UNCHANGED$$1;
740
+ return this.equals(this.value, newValue) ? globalState$$1.UNCHANGED : newValue;
704
741
  };
705
742
  ObservableValue$$1.prototype.setNewValue = function (newValue) {
706
743
  var oldValue = this.value;
@@ -797,7 +834,6 @@ var ComputedValue$$1 = /** @class */ (function () {
797
834
  this.isComputing = false; // to check for cycles
798
835
  this.isRunningSetter = false;
799
836
  this.isTracing = TraceMode$$1.NONE;
800
- this.firstGet = true;
801
837
  if (process.env.NODE_ENV !== "production" && !options.get)
802
838
  throw "[mobx] missing option for computed: get";
803
839
  this.derivation = options.get;
@@ -816,21 +852,24 @@ var ComputedValue$$1 = /** @class */ (function () {
816
852
  ComputedValue$$1.prototype.onBecomeStale = function () {
817
853
  propagateMaybeChanged$$1(this);
818
854
  };
819
- ComputedValue$$1.prototype.onBecomeUnobserved = function () { };
820
- ComputedValue$$1.prototype.onBecomeObserved = function () { };
855
+ ComputedValue$$1.prototype.onBecomeObserved = function () {
856
+ if (this.onBecomeObservedListeners) {
857
+ this.onBecomeObservedListeners.forEach(function (listener) { return listener(); });
858
+ }
859
+ };
860
+ ComputedValue$$1.prototype.onBecomeUnobserved = function () {
861
+ if (this.onBecomeUnobservedListeners) {
862
+ this.onBecomeUnobservedListeners.forEach(function (listener) { return listener(); });
863
+ }
864
+ };
821
865
  /**
822
866
  * Returns the current value of this computed value.
823
867
  * Will evaluate its computation first if needed.
824
868
  */
825
869
  ComputedValue$$1.prototype.get = function () {
826
- var _this = this;
827
- if (this.keepAlive && this.firstGet) {
828
- this.firstGet = false;
829
- autorun$$1(function () { return _this.get(); });
830
- }
831
870
  if (this.isComputing)
832
871
  fail$$1("Cycle detected in computation " + this.name + ": " + this.derivation);
833
- if (globalState$$1.inBatch === 0 && this.observers.size === 0) {
872
+ if (globalState$$1.inBatch === 0 && this.observers.size === 0 && !this.keepAlive) {
834
873
  if (shouldCompute$$1(this)) {
835
874
  this.warnAboutUntrackedRead();
836
875
  startBatch$$1(); // See perf test 'computed memoization'
@@ -916,8 +955,10 @@ var ComputedValue$$1 = /** @class */ (function () {
916
955
  return res;
917
956
  };
918
957
  ComputedValue$$1.prototype.suspend = function () {
919
- clearObserving$$1(this);
920
- this.value = undefined; // don't hold on to computed value!
958
+ if (!this.keepAlive) {
959
+ clearObserving$$1(this);
960
+ this.value = undefined; // don't hold on to computed value!
961
+ }
921
962
  };
922
963
  ComputedValue$$1.prototype.observe = function (listener, fireImmediately) {
923
964
  var _this = this;
@@ -1218,7 +1259,8 @@ var persistentKeys = [
1218
1259
  "enforceActions",
1219
1260
  "computedRequiresReaction",
1220
1261
  "disableErrorBoundaries",
1221
- "runId"
1262
+ "runId",
1263
+ "UNCHANGED"
1222
1264
  ];
1223
1265
  var MobXGlobals$$1 = /** @class */ (function () {
1224
1266
  function MobXGlobals$$1() {
@@ -1231,6 +1273,10 @@ var MobXGlobals$$1 = /** @class */ (function () {
1231
1273
  * internal state storage of MobX, and can be the same across many different package versions
1232
1274
  */
1233
1275
  this.version = 5;
1276
+ /**
1277
+ * globally unique token to signal unchanged
1278
+ */
1279
+ this.UNCHANGED = {};
1234
1280
  /**
1235
1281
  * Currently running derivation
1236
1282
  */
@@ -1293,6 +1339,11 @@ var MobXGlobals$$1 = /** @class */ (function () {
1293
1339
  * the stack when an exception occurs while debugging.
1294
1340
  */
1295
1341
  this.disableErrorBoundaries = false;
1342
+ /*
1343
+ * If true, we are already handling an exception in an action. Any errors in reactions should be supressed, as
1344
+ * they are not the cause, see: https://github.com/mobxjs/mobx/issues/1836
1345
+ */
1346
+ this.suppressReactionErrors = false;
1296
1347
  }
1297
1348
  return MobXGlobals$$1;
1298
1349
  }());
@@ -1314,6 +1365,8 @@ var globalState$$1 = (function () {
1314
1365
  }
1315
1366
  else if (global.__mobxGlobals) {
1316
1367
  global.__mobxInstanceCount += 1;
1368
+ if (!global.__mobxGlobals.UNCHANGED)
1369
+ global.__mobxGlobals.UNCHANGED = {}; // make merge backward compatible
1317
1370
  return global.__mobxGlobals;
1318
1371
  }
1319
1372
  else {
@@ -1535,7 +1588,7 @@ function logTraceInfo(derivation, observable$$1) {
1535
1588
  var lines = [];
1536
1589
  printDepTree(getDependencyTree$$1(derivation), lines, 1);
1537
1590
  // prettier-ignore
1538
- new Function("debugger;\n/*\nTracing '" + derivation.name + "'\n\nYou are entering this break point because derivation '" + derivation.name + "' is being traced and '" + observable$$1.name + "' is now forcing it to update.\nJust follow the stacktrace you should now see in the devtools to see precisely what piece of your code is causing this update\nThe stackframe you are looking for is at least ~6-8 stack-frames up.\n\n" + (derivation instanceof ComputedValue$$1 ? derivation.derivation.toString() : "") + "\n\nThe dependencies for this derivation are:\n\n" + lines.join("\n") + "\n*/\n ")();
1591
+ new Function("debugger;\n/*\nTracing '" + derivation.name + "'\n\nYou are entering this break point because derivation '" + derivation.name + "' is being traced and '" + observable$$1.name + "' is now forcing it to update.\nJust follow the stacktrace you should now see in the devtools to see precisely what piece of your code is causing this update\nThe stackframe you are looking for is at least ~6-8 stack-frames up.\n\n" + (derivation instanceof ComputedValue$$1 ? derivation.derivation.toString().replace(/[*]\//g, "/") : "") + "\n\nThe dependencies for this derivation are:\n\n" + lines.join("\n") + "\n*/\n ")();
1539
1592
  }
1540
1593
  }
1541
1594
  function printDepTree(tree, lines, depth) {
@@ -1644,9 +1697,14 @@ var Reaction$$1 = /** @class */ (function () {
1644
1697
  }
1645
1698
  if (globalState$$1.disableErrorBoundaries)
1646
1699
  throw error;
1647
- var message = "[mobx] Encountered an uncaught exception that was thrown by a reaction or observer component, in: '" + this;
1648
- console.error(message, error);
1649
- /** If debugging brought you here, please, read the above message :-). Tnx! */
1700
+ var message = "[mobx] Encountered an uncaught exception that was thrown by a reaction or observer component, in: '" + this + "'";
1701
+ if (globalState$$1.suppressReactionErrors) {
1702
+ console.warn("[mobx] (error in reaction '" + this.name + "' suppressed, fix error of causing action below)"); // prettier-ignore
1703
+ }
1704
+ else {
1705
+ console.error(message, error);
1706
+ /** If debugging brought you here, please, read the above message :-). Tnx! */
1707
+ }
1650
1708
  if (isSpyEnabled$$1()) {
1651
1709
  spyReport$$1({
1652
1710
  type: "error",
@@ -2003,20 +2061,32 @@ function onBecomeUnobserved$$1(thing, arg2, arg3) {
2003
2061
  function interceptHook(hook, thing, arg2, arg3) {
2004
2062
  var atom = typeof arg2 === "string" ? getAtom$$1(thing, arg2) : getAtom$$1(thing);
2005
2063
  var cb = typeof arg2 === "string" ? arg3 : arg2;
2064
+ var listenersKey = hook + "Listeners";
2065
+ if (atom[listenersKey]) {
2066
+ atom[listenersKey].add(cb);
2067
+ }
2068
+ else {
2069
+ atom[listenersKey] = new Set([cb]);
2070
+ }
2006
2071
  var orig = atom[hook];
2007
2072
  if (typeof orig !== "function")
2008
2073
  return fail$$1(process.env.NODE_ENV !== "production" && "Not an atom that can be (un)observed");
2009
- atom[hook] = function () {
2010
- orig.call(this);
2011
- cb.call(this);
2012
- };
2013
2074
  return function () {
2014
- atom[hook] = orig;
2075
+ var hookListeners = atom[listenersKey];
2076
+ if (hookListeners) {
2077
+ hookListeners.delete(cb);
2078
+ if (hookListeners.size === 0) {
2079
+ delete atom[listenersKey];
2080
+ }
2081
+ }
2015
2082
  };
2016
2083
  }
2017
2084
 
2018
2085
  function configure$$1(options) {
2019
2086
  var enforceActions = options.enforceActions, computedRequiresReaction = options.computedRequiresReaction, disableErrorBoundaries = options.disableErrorBoundaries, reactionScheduler = options.reactionScheduler;
2087
+ if (options.isolateGlobalState === true) {
2088
+ isolateGlobalState$$1();
2089
+ }
2020
2090
  if (enforceActions !== undefined) {
2021
2091
  if (typeof enforceActions === "boolean" || enforceActions === "strict")
2022
2092
  deprecated$$1("Deprecated value for 'enforceActions', use 'false' => '\"never\"', 'true' => '\"observed\"', '\"strict\"' => \"'always'\" instead");
@@ -2043,9 +2113,6 @@ function configure$$1(options) {
2043
2113
  if (computedRequiresReaction !== undefined) {
2044
2114
  globalState$$1.computedRequiresReaction = !!computedRequiresReaction;
2045
2115
  }
2046
- if (options.isolateGlobalState === true) {
2047
- isolateGlobalState$$1();
2048
- }
2049
2116
  if (disableErrorBoundaries !== undefined) {
2050
2117
  if (disableErrorBoundaries === true)
2051
2118
  console.warn("WARNING: Debug feature only. MobX will NOT recover from errors when `disableErrorBoundaries` is enabled.");
@@ -2167,7 +2234,7 @@ function flow$$1(generator) {
2167
2234
  var gen = action$$1(name + " - runid: " + runId + " - init", generator).apply(ctx, args);
2168
2235
  var rejector;
2169
2236
  var pendingPromise = undefined;
2170
- var res = new Promise(function (resolve, reject) {
2237
+ var promise = new Promise(function (resolve, reject) {
2171
2238
  var stepId = 0;
2172
2239
  rejector = reject;
2173
2240
  function onFulfilled(res) {
@@ -2205,14 +2272,14 @@ function flow$$1(generator) {
2205
2272
  }
2206
2273
  onFulfilled(undefined); // kick off the process
2207
2274
  });
2208
- res.cancel = action$$1(name + " - runid: " + runId + " - cancel", function () {
2275
+ promise.cancel = action$$1(name + " - runid: " + runId + " - cancel", function () {
2209
2276
  try {
2210
2277
  if (pendingPromise)
2211
2278
  cancelPromise(pendingPromise);
2212
2279
  // Finally block can return (or yield) stuff..
2213
- var res_1 = gen.return();
2280
+ var res = gen.return();
2214
2281
  // eat anything that promise would do, it's cancelled!
2215
- var yieldedPromise = Promise.resolve(res_1.value);
2282
+ var yieldedPromise = Promise.resolve(res.value);
2216
2283
  yieldedPromise.then(noop$$1, noop$$1);
2217
2284
  cancelPromise(yieldedPromise); // maybe it can be cancelled :)
2218
2285
  // reject our original promise
@@ -2222,7 +2289,7 @@ function flow$$1(generator) {
2222
2289
  rejector(e); // there could be a throwing finally block
2223
2290
  }
2224
2291
  });
2225
- return res;
2292
+ return promise;
2226
2293
  };
2227
2294
  }
2228
2295
  function cancelPromise(promise) {
@@ -2330,11 +2397,14 @@ function keys$$1(obj) {
2330
2397
  if (isObservableMap$$1(obj)) {
2331
2398
  return Array.from(obj.keys());
2332
2399
  }
2400
+ if (isObservableSet$$1(obj)) {
2401
+ return Array.from(obj.keys());
2402
+ }
2333
2403
  if (isObservableArray$$1(obj)) {
2334
2404
  return obj.map(function (_, index) { return index; });
2335
2405
  }
2336
2406
  return fail$$1(process.env.NODE_ENV !== "production" &&
2337
- "'keys()' can only be used on observable objects, arrays and maps");
2407
+ "'keys()' can only be used on observable objects, arrays, sets and maps");
2338
2408
  }
2339
2409
  function values$$1(obj) {
2340
2410
  if (isObservableObject$$1(obj)) {
@@ -2343,11 +2413,14 @@ function values$$1(obj) {
2343
2413
  if (isObservableMap$$1(obj)) {
2344
2414
  return keys$$1(obj).map(function (key) { return obj.get(key); });
2345
2415
  }
2416
+ if (isObservableSet$$1(obj)) {
2417
+ return Array.from(obj.values());
2418
+ }
2346
2419
  if (isObservableArray$$1(obj)) {
2347
2420
  return obj.slice();
2348
2421
  }
2349
2422
  return fail$$1(process.env.NODE_ENV !== "production" &&
2350
- "'values()' can only be used on observable objects, arrays and maps");
2423
+ "'values()' can only be used on observable objects, arrays, sets and maps");
2351
2424
  }
2352
2425
  function entries$$1(obj) {
2353
2426
  if (isObservableObject$$1(obj)) {
@@ -2356,6 +2429,9 @@ function entries$$1(obj) {
2356
2429
  if (isObservableMap$$1(obj)) {
2357
2430
  return keys$$1(obj).map(function (key) { return [key, obj.get(key)]; });
2358
2431
  }
2432
+ if (isObservableSet$$1(obj)) {
2433
+ return Array.from(obj.entries());
2434
+ }
2359
2435
  if (isObservableArray$$1(obj)) {
2360
2436
  return obj.map(function (key, index) { return [index, key]; });
2361
2437
  }
@@ -2411,6 +2487,9 @@ function remove$$1(obj, key) {
2411
2487
  else if (isObservableMap$$1(obj)) {
2412
2488
  obj.delete(key);
2413
2489
  }
2490
+ else if (isObservableSet$$1(obj)) {
2491
+ obj.delete(key);
2492
+ }
2414
2493
  else if (isObservableArray$$1(obj)) {
2415
2494
  if (typeof key !== "number")
2416
2495
  key = parseInt(key, 10);
@@ -2431,6 +2510,9 @@ function has$$1(obj, key) {
2431
2510
  else if (isObservableMap$$1(obj)) {
2432
2511
  return obj.has(key);
2433
2512
  }
2513
+ else if (isObservableSet$$1(obj)) {
2514
+ return obj.has(key);
2515
+ }
2434
2516
  else if (isObservableArray$$1(obj)) {
2435
2517
  return key >= 0 && key < obj.length;
2436
2518
  }
@@ -2508,20 +2590,36 @@ function toJSHelper(source, options, __alreadySeen) {
2508
2590
  res_1[i] = toAdd[i];
2509
2591
  return res_1;
2510
2592
  }
2593
+ if (isObservableSet$$1(source) || Object.getPrototypeOf(source) === Set.prototype) {
2594
+ if (options.exportMapsAsObjects === false) {
2595
+ var res_2 = cache(__alreadySeen, source, new Set(), options);
2596
+ source.forEach(function (value) {
2597
+ res_2.add(toJSHelper(value, options, __alreadySeen));
2598
+ });
2599
+ return res_2;
2600
+ }
2601
+ else {
2602
+ var res_3 = cache(__alreadySeen, source, [], options);
2603
+ source.forEach(function (value) {
2604
+ res_3.push(toJSHelper(value, options, __alreadySeen));
2605
+ });
2606
+ return res_3;
2607
+ }
2608
+ }
2511
2609
  if (isObservableMap$$1(source) || Object.getPrototypeOf(source) === Map.prototype) {
2512
2610
  if (options.exportMapsAsObjects === false) {
2513
- var res_2 = cache(__alreadySeen, source, new Map(), options);
2611
+ var res_4 = cache(__alreadySeen, source, new Map(), options);
2514
2612
  source.forEach(function (value, key) {
2515
- res_2.set(key, toJSHelper(value, options, __alreadySeen));
2613
+ res_4.set(key, toJSHelper(value, options, __alreadySeen));
2516
2614
  });
2517
- return res_2;
2615
+ return res_4;
2518
2616
  }
2519
2617
  else {
2520
- var res_3 = cache(__alreadySeen, source, {}, options);
2618
+ var res_5 = cache(__alreadySeen, source, {}, options);
2521
2619
  source.forEach(function (value, key) {
2522
- res_3[key] = toJSHelper(value, options, __alreadySeen);
2620
+ res_5[key] = toJSHelper(value, options, __alreadySeen);
2523
2621
  });
2524
- return res_3;
2622
+ return res_5;
2525
2623
  }
2526
2624
  }
2527
2625
  // Fallback to the situation that source is an ObservableObject or a plain object
@@ -2662,8 +2760,16 @@ var objectProxyTraps = {
2662
2760
  return target[name];
2663
2761
  var adm = getAdm(target);
2664
2762
  var observable$$1 = adm.values.get(name);
2665
- if (observable$$1 instanceof Atom$$1)
2666
- return observable$$1.get();
2763
+ if (observable$$1 instanceof Atom$$1) {
2764
+ var result = observable$$1.get();
2765
+ if (result === undefined) {
2766
+ // This fixes #1796, because deleting a prop that has an
2767
+ // undefined value won't retrigger a observer (no visible effect),
2768
+ // the autorun wouldn't subscribe to future key changes (see also next comment)
2769
+ adm.has(name);
2770
+ }
2771
+ return result;
2772
+ }
2667
2773
  // make sure we start listening to future keys
2668
2774
  // note that we only do this here for optimization
2669
2775
  if (typeof name === "string")
@@ -2820,7 +2926,7 @@ var ObservableArrayAdministration = /** @class */ (function () {
2820
2926
  return value;
2821
2927
  };
2822
2928
  ObservableArrayAdministration.prototype.dehanceValues = function (values$$1) {
2823
- if (this.dehancer !== undefined && this.values.length > 0)
2929
+ if (this.dehancer !== undefined && values$$1.length > 0)
2824
2930
  return values$$1.map(this.dehancer);
2825
2931
  return values$$1;
2826
2932
  };
@@ -3249,7 +3355,7 @@ var ObservableMap$$1 = /** @class */ (function () {
3249
3355
  ObservableMap$$1.prototype._updateValue = function (key, newValue) {
3250
3356
  var observable$$1 = this._data.get(key);
3251
3357
  newValue = observable$$1.prepareNewValue(newValue);
3252
- if (newValue !== UNCHANGED$$1) {
3358
+ if (newValue !== globalState$$1.UNCHANGED) {
3253
3359
  var notifySpy = isSpyEnabled$$1();
3254
3360
  var notify = hasListeners$$1(this);
3255
3361
  var change = notify || notifySpy
@@ -3374,8 +3480,11 @@ var ObservableMap$$1 = /** @class */ (function () {
3374
3480
  var _b = __read(_a, 2), key = _b[0], value = _b[1];
3375
3481
  return _this.set(key, value);
3376
3482
  });
3377
- else if (isES6Map$$1(other))
3483
+ else if (isES6Map$$1(other)) {
3484
+ if (other.constructor !== Map)
3485
+ return fail$$1("Cannot initialize from classes that inherit from Map: " + other.constructor.name); // prettier-ignore
3378
3486
  other.forEach(function (value, key) { return _this.set(key, value); });
3487
+ }
3379
3488
  else if (other !== null && other !== undefined)
3380
3489
  fail$$1("Cannot initialize map from " + other);
3381
3490
  });
@@ -3485,6 +3594,224 @@ var ObservableMap$$1 = /** @class */ (function () {
3485
3594
  /* 'var' fixes small-build issue */
3486
3595
  var isObservableMap$$1 = createInstanceofPredicate$$1("ObservableMap", ObservableMap$$1);
3487
3596
 
3597
+ var _a$1;
3598
+ var ObservableSetMarker = {};
3599
+ var ObservableSet$$1 = /** @class */ (function () {
3600
+ function ObservableSet$$1(initialData, enhancer, name) {
3601
+ if (enhancer === void 0) { enhancer = deepEnhancer$$1; }
3602
+ if (name === void 0) { name = "ObservableSet@" + getNextId$$1(); }
3603
+ this.name = name;
3604
+ this[_a$1] = ObservableSetMarker;
3605
+ this._data = new Set();
3606
+ this._atom = createAtom$$1(this.name);
3607
+ this[Symbol.toStringTag] = "Set";
3608
+ if (typeof Set !== "function") {
3609
+ throw new Error("mobx.set requires Set polyfill for the current browser. Check babel-polyfill or core-js/es6/set.js");
3610
+ }
3611
+ this.enhancer = function (newV, oldV) { return enhancer(newV, oldV, name); };
3612
+ if (initialData) {
3613
+ this.replace(initialData);
3614
+ }
3615
+ }
3616
+ ObservableSet$$1.prototype.dehanceValue = function (value) {
3617
+ if (this.dehancer !== undefined) {
3618
+ return this.dehancer(value);
3619
+ }
3620
+ return value;
3621
+ };
3622
+ ObservableSet$$1.prototype.clear = function () {
3623
+ var _this = this;
3624
+ transaction$$1(function () {
3625
+ untracked$$1(function () {
3626
+ var e_1, _a;
3627
+ try {
3628
+ for (var _b = __values(_this._data.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
3629
+ var value = _c.value;
3630
+ _this.delete(value);
3631
+ }
3632
+ }
3633
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
3634
+ finally {
3635
+ try {
3636
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
3637
+ }
3638
+ finally { if (e_1) throw e_1.error; }
3639
+ }
3640
+ });
3641
+ });
3642
+ };
3643
+ ObservableSet$$1.prototype.forEach = function (callbackFn, thisArg) {
3644
+ var e_2, _a;
3645
+ try {
3646
+ for (var _b = __values(this), _c = _b.next(); !_c.done; _c = _b.next()) {
3647
+ var value = _c.value;
3648
+ callbackFn.call(thisArg, value, value, this);
3649
+ }
3650
+ }
3651
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
3652
+ finally {
3653
+ try {
3654
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
3655
+ }
3656
+ finally { if (e_2) throw e_2.error; }
3657
+ }
3658
+ };
3659
+ Object.defineProperty(ObservableSet$$1.prototype, "size", {
3660
+ get: function () {
3661
+ this._atom.reportObserved();
3662
+ return this._data.size;
3663
+ },
3664
+ enumerable: true,
3665
+ configurable: true
3666
+ });
3667
+ ObservableSet$$1.prototype.add = function (value) {
3668
+ var _this = this;
3669
+ checkIfStateModificationsAreAllowed$$1(this._atom);
3670
+ if (hasInterceptors$$1(this)) {
3671
+ var change = interceptChange$$1(this, {
3672
+ type: "add",
3673
+ object: this,
3674
+ newValue: value
3675
+ });
3676
+ if (!change)
3677
+ return this;
3678
+ // TODO: ideally, value = change.value would be done here, so that values can be
3679
+ // changed by interceptor. Same applies for other Set and Map api's.
3680
+ }
3681
+ if (!this.has(value)) {
3682
+ transaction$$1(function () {
3683
+ _this._data.add(_this.enhancer(value, undefined));
3684
+ _this._atom.reportChanged();
3685
+ });
3686
+ var notifySpy = isSpyEnabled$$1();
3687
+ var notify = hasListeners$$1(this);
3688
+ var change = notify || notifySpy
3689
+ ? {
3690
+ type: "add",
3691
+ object: this,
3692
+ newValue: value
3693
+ }
3694
+ : null;
3695
+ if (notifySpy && process.env.NODE_ENV !== "production")
3696
+ spyReportStart$$1(change);
3697
+ if (notify)
3698
+ notifyListeners$$1(this, change);
3699
+ if (notifySpy && process.env.NODE_ENV !== "production")
3700
+ spyReportEnd$$1();
3701
+ }
3702
+ return this;
3703
+ };
3704
+ ObservableSet$$1.prototype.delete = function (value) {
3705
+ var _this = this;
3706
+ if (hasInterceptors$$1(this)) {
3707
+ var change = interceptChange$$1(this, {
3708
+ type: "delete",
3709
+ object: this,
3710
+ oldValue: value
3711
+ });
3712
+ if (!change)
3713
+ return false;
3714
+ }
3715
+ if (this.has(value)) {
3716
+ var notifySpy = isSpyEnabled$$1();
3717
+ var notify = hasListeners$$1(this);
3718
+ var change = notify || notifySpy
3719
+ ? {
3720
+ type: "delete",
3721
+ object: this,
3722
+ oldValue: value
3723
+ }
3724
+ : null;
3725
+ if (notifySpy && process.env.NODE_ENV !== "production")
3726
+ spyReportStart$$1(__assign({}, change, { name: this.name }));
3727
+ transaction$$1(function () {
3728
+ _this._atom.reportChanged();
3729
+ _this._data.delete(value);
3730
+ });
3731
+ if (notify)
3732
+ notifyListeners$$1(this, change);
3733
+ if (notifySpy && process.env.NODE_ENV !== "production")
3734
+ spyReportEnd$$1();
3735
+ return true;
3736
+ }
3737
+ return false;
3738
+ };
3739
+ ObservableSet$$1.prototype.has = function (value) {
3740
+ this._atom.reportObserved();
3741
+ return this._data.has(this.dehanceValue(value));
3742
+ };
3743
+ ObservableSet$$1.prototype.entries = function () {
3744
+ var nextIndex = 0;
3745
+ var keys$$1 = Array.from(this.keys());
3746
+ var values$$1 = Array.from(this.values());
3747
+ return makeIterable({
3748
+ next: function () {
3749
+ var index = nextIndex;
3750
+ nextIndex += 1;
3751
+ return index < values$$1.length
3752
+ ? { value: [keys$$1[index], values$$1[index]], done: false }
3753
+ : { done: true };
3754
+ }
3755
+ });
3756
+ };
3757
+ ObservableSet$$1.prototype.keys = function () {
3758
+ return this.values();
3759
+ };
3760
+ ObservableSet$$1.prototype.values = function () {
3761
+ this._atom.reportObserved();
3762
+ var self = this;
3763
+ var nextIndex = 0;
3764
+ var observableValues = Array.from(this._data.values());
3765
+ return makeIterable({
3766
+ next: function () {
3767
+ return nextIndex < observableValues.length
3768
+ ? { value: self.dehanceValue(observableValues[nextIndex++]), done: false }
3769
+ : { done: true };
3770
+ }
3771
+ });
3772
+ };
3773
+ ObservableSet$$1.prototype.replace = function (other) {
3774
+ var _this = this;
3775
+ if (isObservableSet$$1(other)) {
3776
+ other = other.toJS();
3777
+ }
3778
+ transaction$$1(function () {
3779
+ if (Array.isArray(other)) {
3780
+ _this.clear();
3781
+ other.forEach(function (value) { return _this.add(value); });
3782
+ }
3783
+ else if (isES6Set$$1(other)) {
3784
+ _this.clear();
3785
+ other.forEach(function (value) { return _this.add(value); });
3786
+ }
3787
+ else if (other !== null && other !== undefined) {
3788
+ fail$$1("Cannot initialize set from " + other);
3789
+ }
3790
+ });
3791
+ return this;
3792
+ };
3793
+ ObservableSet$$1.prototype.observe = function (listener, fireImmediately) {
3794
+ // TODO 'fireImmediately' can be true?
3795
+ process.env.NODE_ENV !== "production" &&
3796
+ invariant$$1(fireImmediately !== true, "`observe` doesn't support fireImmediately=true in combination with sets.");
3797
+ return registerListener$$1(this, listener);
3798
+ };
3799
+ ObservableSet$$1.prototype.intercept = function (handler) {
3800
+ return registerInterceptor$$1(this, handler);
3801
+ };
3802
+ ObservableSet$$1.prototype.toJS = function () {
3803
+ return new Set(this);
3804
+ };
3805
+ ObservableSet$$1.prototype.toString = function () {
3806
+ return this.name + "[ " + Array.from(this).join(", ") + " ]";
3807
+ };
3808
+ ObservableSet$$1.prototype[(_a$1 = $mobx$$1, Symbol.iterator)] = function () {
3809
+ return this.values();
3810
+ };
3811
+ return ObservableSet$$1;
3812
+ }());
3813
+ var isObservableSet$$1 = createInstanceofPredicate$$1("ObservableSet", ObservableSet$$1);
3814
+
3488
3815
  var ObservableObjectAdministration$$1 = /** @class */ (function () {
3489
3816
  function ObservableObjectAdministration$$1(target, values$$1, name, defaultEnhancer) {
3490
3817
  if (values$$1 === void 0) { values$$1 = new Map(); }
@@ -3518,7 +3845,7 @@ var ObservableObjectAdministration$$1 = /** @class */ (function () {
3518
3845
  }
3519
3846
  newValue = observable$$1.prepareNewValue(newValue);
3520
3847
  // notify spy & observers
3521
- if (newValue !== UNCHANGED$$1) {
3848
+ if (newValue !== globalState$$1.UNCHANGED) {
3522
3849
  var notify = hasListeners$$1(this);
3523
3850
  var notifySpy = isSpyEnabled$$1();
3524
3851
  var change = notify || notifySpy
@@ -3756,7 +4083,7 @@ function getAdministrationForComputedPropOwner(owner) {
3756
4083
  function generateComputedPropConfig$$1(propName) {
3757
4084
  return (computedPropertyConfigs[propName] ||
3758
4085
  (computedPropertyConfigs[propName] = {
3759
- configurable: true,
4086
+ configurable: false,
3760
4087
  enumerable: false,
3761
4088
  get: function () {
3762
4089
  return getAdministrationForComputedPropOwner(this).read(propName);
@@ -3784,6 +4111,9 @@ function getAtom$$1(thing, property) {
3784
4111
  "It is not possible to get index atoms from arrays");
3785
4112
  return thing[$mobx$$1].atom;
3786
4113
  }
4114
+ if (isObservableSet$$1(thing)) {
4115
+ return thing[$mobx$$1];
4116
+ }
3787
4117
  if (isObservableMap$$1(thing)) {
3788
4118
  var anyThing = thing;
3789
4119
  if (property === undefined)
@@ -3826,7 +4156,7 @@ function getAdministration$$1(thing, property) {
3826
4156
  return getAdministration$$1(getAtom$$1(thing, property));
3827
4157
  if (isAtom$$1(thing) || isComputedValue$$1(thing) || isReaction$$1(thing))
3828
4158
  return thing;
3829
- if (isObservableMap$$1(thing))
4159
+ if (isObservableMap$$1(thing) || isObservableSet$$1(thing))
3830
4160
  return thing;
3831
4161
  // Initializers run lazily when transpiling to babel, so make sure they are run...
3832
4162
  initializeInstance$$1(thing);
@@ -3838,7 +4168,7 @@ function getDebugName$$1(thing, property) {
3838
4168
  var named;
3839
4169
  if (property !== undefined)
3840
4170
  named = getAtom$$1(thing, property);
3841
- else if (isObservableObject$$1(thing) || isObservableMap$$1(thing))
4171
+ else if (isObservableObject$$1(thing) || isObservableMap$$1(thing) || isObservableSet$$1(thing))
3842
4172
  named = getAdministration$$1(thing);
3843
4173
  else
3844
4174
  named = getAtom$$1(thing); // valid for arrays as well
@@ -3969,6 +4299,8 @@ function unwrap(a) {
3969
4299
  return a.slice();
3970
4300
  if (isES6Map$$1(a) || isObservableMap$$1(a))
3971
4301
  return Array.from(a.entries());
4302
+ if (isES6Set$$1(a) || isObservableSet$$1(a))
4303
+ return Array.from(a.entries());
3972
4304
  return a;
3973
4305
  }
3974
4306
  function has$1(a, key) {
@@ -4027,7 +4359,8 @@ catch (e) {
4027
4359
  (function () {
4028
4360
  function testCodeMinification() { }
4029
4361
  if (testCodeMinification.name !== "testCodeMinification" &&
4030
- process.env.NODE_ENV !== "production") {
4362
+ process.env.NODE_ENV !== "production" &&
4363
+ process.env.IGNORE_MOBX_MINIFY_WARNING !== "true") {
4031
4364
  console.warn(
4032
4365
  // Template literal(backtick) is used for fix issue with rollup-plugin-commonjs https://github.com/rollup/rollup-plugin-commonjs/issues/344
4033
4366
  "[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");
@@ -4055,6 +4388,8 @@ exports.isBoxedObservable = isObservableValue$$1;
4055
4388
  exports.isObservableArray = isObservableArray$$1;
4056
4389
  exports.ObservableMap = ObservableMap$$1;
4057
4390
  exports.isObservableMap = isObservableMap$$1;
4391
+ exports.ObservableSet = ObservableSet$$1;
4392
+ exports.isObservableSet = isObservableSet$$1;
4058
4393
  exports.transaction = transaction$$1;
4059
4394
  exports.observable = observable$$1;
4060
4395
  exports.computed = computed$$1;