mobx 5.7.0 → 5.9.4

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.umd.js CHANGED
@@ -191,6 +191,9 @@ function isArrayLike$$1(x) {
191
191
  function isES6Map$$1(thing) {
192
192
  return thing instanceof Map;
193
193
  }
194
+ function isES6Set$$1(thing) {
195
+ return thing instanceof Set;
196
+ }
194
197
  function getMapLikeKeys$$1(map) {
195
198
  if (isPlainObject$$1(map))
196
199
  return Object.keys(map);
@@ -223,11 +226,15 @@ var Atom$$1 = /** @class */ (function () {
223
226
  this.lastAccessedBy = 0;
224
227
  this.lowestObserverState = exports.IDerivationState.NOT_TRACKING;
225
228
  }
226
- Atom$$1.prototype.onBecomeUnobserved = function () {
227
- // noop
228
- };
229
229
  Atom$$1.prototype.onBecomeObserved = function () {
230
- /* noop */
230
+ if (this.onBecomeObservedListeners) {
231
+ this.onBecomeObservedListeners.forEach(function (listener) { return listener(); });
232
+ }
233
+ };
234
+ Atom$$1.prototype.onBecomeUnobserved = function () {
235
+ if (this.onBecomeUnobservedListeners) {
236
+ this.onBecomeUnobservedListeners.forEach(function (listener) { return listener(); });
237
+ }
231
238
  };
232
239
  /**
233
240
  * Invoke this method to notify mobx that your atom has been used somehow.
@@ -254,8 +261,13 @@ function createAtom$$1(name, onBecomeObservedHandler, onBecomeUnobservedHandler)
254
261
  if (onBecomeObservedHandler === void 0) { onBecomeObservedHandler = noop$$1; }
255
262
  if (onBecomeUnobservedHandler === void 0) { onBecomeUnobservedHandler = noop$$1; }
256
263
  var atom = new Atom$$1(name);
257
- onBecomeObserved$$1(atom, onBecomeObservedHandler);
258
- onBecomeUnobserved$$1(atom, onBecomeUnobservedHandler);
264
+ // default `noop` listener will not initialize the hook Set
265
+ if (onBecomeObservedHandler !== noop$$1) {
266
+ onBecomeObserved$$1(atom, onBecomeObservedHandler);
267
+ }
268
+ if (onBecomeUnobservedHandler !== noop$$1) {
269
+ onBecomeUnobserved$$1(atom, onBecomeUnobservedHandler);
270
+ }
259
271
  return atom;
260
272
  }
261
273
 
@@ -360,12 +372,14 @@ function deepEnhancer$$1(v, _, name) {
360
372
  return observable$$1.object(v, undefined, { name: name });
361
373
  if (isES6Map$$1(v))
362
374
  return observable$$1.map(v, { name: name });
375
+ if (isES6Set$$1(v))
376
+ return observable$$1.set(v, { name: name });
363
377
  return v;
364
378
  }
365
379
  function shallowEnhancer$$1(v, _, name) {
366
380
  if (v === undefined || v === null)
367
381
  return v;
368
- if (isObservableObject$$1(v) || isObservableArray$$1(v) || isObservableMap$$1(v))
382
+ if (isObservableObject$$1(v) || isObservableArray$$1(v) || isObservableMap$$1(v) || isObservableSet$$1(v))
369
383
  return v;
370
384
  if (Array.isArray(v))
371
385
  return observable$$1.array(v, { name: name, deep: false });
@@ -373,8 +387,10 @@ function shallowEnhancer$$1(v, _, name) {
373
387
  return observable$$1.object(v, undefined, { name: name, deep: false });
374
388
  if (isES6Map$$1(v))
375
389
  return observable$$1.map(v, { name: name, deep: false });
390
+ if (isES6Set$$1(v))
391
+ return observable$$1.set(v, { name: name, deep: false });
376
392
  return fail$$1(process.env.NODE_ENV !== "production" &&
377
- "The shallow modifier / decorator can only used in combination with arrays, objects and maps");
393
+ "The shallow modifier / decorator can only used in combination with arrays, objects, maps and sets");
378
394
  }
379
395
  function referenceEnhancer$$1(newValue) {
380
396
  // never turn into an observable
@@ -426,7 +442,7 @@ var defaultCreateObservableOptions$$1 = {
426
442
  };
427
443
  Object.freeze(defaultCreateObservableOptions$$1);
428
444
  function assertValidOption(key) {
429
- if (!/^(deep|name|defaultDecorator|proxy)$/.test(key))
445
+ if (!/^(deep|name|equals|defaultDecorator|proxy)$/.test(key))
430
446
  fail$$1("invalid option for (extend)observable: " + key);
431
447
  }
432
448
  function asCreateObservableOptions$$1(thing) {
@@ -471,7 +487,9 @@ function createObservable(v, arg2, arg3) {
471
487
  ? observable$$1.array(v, arg2)
472
488
  : isES6Map$$1(v)
473
489
  ? observable$$1.map(v, arg2)
474
- : v;
490
+ : isES6Set$$1(v)
491
+ ? observable$$1.set(v, arg2)
492
+ : v;
475
493
  // this value could be converted to a new observable data structure, return it
476
494
  if (res !== v)
477
495
  return res;
@@ -484,7 +502,7 @@ var observableFactories = {
484
502
  if (arguments.length > 2)
485
503
  incorrectlyUsedAsDecorator("box");
486
504
  var o = asCreateObservableOptions$$1(options);
487
- return new ObservableValue$$1(value, getEnhancerFromOptions(o), o.name);
505
+ return new ObservableValue$$1(value, getEnhancerFromOptions(o), o.name, true, o.equals);
488
506
  },
489
507
  array: function (initialValues, options) {
490
508
  if (arguments.length > 2)
@@ -498,6 +516,12 @@ var observableFactories = {
498
516
  var o = asCreateObservableOptions$$1(options);
499
517
  return new ObservableMap$$1(initialValues, getEnhancerFromOptions(o), o.name);
500
518
  },
519
+ set: function (initialValues, options) {
520
+ if (arguments.length > 2)
521
+ incorrectlyUsedAsDecorator("set");
522
+ var o = asCreateObservableOptions$$1(options);
523
+ return new ObservableSet$$1(initialValues, getEnhancerFromOptions(o), o.name);
524
+ },
501
525
  object: function (props, decorators, options) {
502
526
  if (typeof arguments[1] === "string")
503
527
  incorrectlyUsedAsDecorator("object");
@@ -563,25 +587,35 @@ var computed$$1 = function computed$$1(arg1, arg2, arg3) {
563
587
  };
564
588
  computed$$1.struct = computedStructDecorator;
565
589
 
566
- function createAction$$1(actionName, fn) {
590
+ function createAction$$1(actionName, fn, ref) {
567
591
  if (process.env.NODE_ENV !== "production") {
568
592
  invariant$$1(typeof fn === "function", "`action` can only be invoked on functions");
569
593
  if (typeof actionName !== "string" || !actionName)
570
594
  fail$$1("actions should have valid names, got: '" + actionName + "'");
571
595
  }
572
596
  var res = function () {
573
- return executeAction$$1(actionName, fn, this, arguments);
597
+ return executeAction$$1(actionName, fn, ref || this, arguments);
574
598
  };
575
599
  res.isMobxAction = true;
576
600
  return res;
577
601
  }
578
602
  function executeAction$$1(actionName, fn, scope, args) {
579
603
  var runInfo = startAction(actionName, fn, scope, args);
604
+ var shouldSupressReactionError = true;
580
605
  try {
581
- return fn.apply(scope, args);
606
+ var res = fn.apply(scope, args);
607
+ shouldSupressReactionError = false;
608
+ return res;
582
609
  }
583
610
  finally {
584
- endAction(runInfo);
611
+ if (shouldSupressReactionError) {
612
+ globalState$$1.suppressReactionErrors = shouldSupressReactionError;
613
+ endAction(runInfo);
614
+ globalState$$1.suppressReactionErrors = false;
615
+ }
616
+ else {
617
+ endAction(runInfo);
618
+ }
585
619
  }
586
620
  }
587
621
  function startAction(actionName, fn, scope, args) {
@@ -652,11 +686,14 @@ function allowStateChangesInsideComputed$$1(func) {
652
686
 
653
687
  var ObservableValue$$1 = /** @class */ (function (_super) {
654
688
  __extends(ObservableValue$$1, _super);
655
- function ObservableValue$$1(value, enhancer, name, notifySpy) {
689
+ function ObservableValue$$1(value, enhancer, name, notifySpy, equals) {
656
690
  if (name === void 0) { name = "ObservableValue@" + getNextId$$1(); }
657
691
  if (notifySpy === void 0) { notifySpy = true; }
692
+ if (equals === void 0) { equals = comparer$$1.default; }
658
693
  var _this = _super.call(this, name) || this;
659
694
  _this.enhancer = enhancer;
695
+ _this.name = name;
696
+ _this.equals = equals;
660
697
  _this.hasUnreportedChange = false;
661
698
  _this.value = enhancer(value, undefined, name);
662
699
  if (notifySpy && isSpyEnabled$$1() && process.env.NODE_ENV !== "production") {
@@ -702,7 +739,7 @@ var ObservableValue$$1 = /** @class */ (function (_super) {
702
739
  }
703
740
  // apply modifier
704
741
  newValue = this.enhancer(newValue, this.value, this.name);
705
- return this.value !== newValue ? newValue : globalState$$1.UNCHANGED;
742
+ return this.equals(this.value, newValue) ? globalState$$1.UNCHANGED : newValue;
706
743
  };
707
744
  ObservableValue$$1.prototype.setNewValue = function (newValue) {
708
745
  var oldValue = this.value;
@@ -817,8 +854,16 @@ var ComputedValue$$1 = /** @class */ (function () {
817
854
  ComputedValue$$1.prototype.onBecomeStale = function () {
818
855
  propagateMaybeChanged$$1(this);
819
856
  };
820
- ComputedValue$$1.prototype.onBecomeUnobserved = function () { };
821
- ComputedValue$$1.prototype.onBecomeObserved = function () { };
857
+ ComputedValue$$1.prototype.onBecomeObserved = function () {
858
+ if (this.onBecomeObservedListeners) {
859
+ this.onBecomeObservedListeners.forEach(function (listener) { return listener(); });
860
+ }
861
+ };
862
+ ComputedValue$$1.prototype.onBecomeUnobserved = function () {
863
+ if (this.onBecomeUnobservedListeners) {
864
+ this.onBecomeUnobservedListeners.forEach(function (listener) { return listener(); });
865
+ }
866
+ };
822
867
  /**
823
868
  * Returns the current value of this computed value.
824
869
  * Will evaluate its computation first if needed.
@@ -1296,6 +1341,11 @@ var MobXGlobals$$1 = /** @class */ (function () {
1296
1341
  * the stack when an exception occurs while debugging.
1297
1342
  */
1298
1343
  this.disableErrorBoundaries = false;
1344
+ /*
1345
+ * If true, we are already handling an exception in an action. Any errors in reactions should be supressed, as
1346
+ * they are not the cause, see: https://github.com/mobxjs/mobx/issues/1836
1347
+ */
1348
+ this.suppressReactionErrors = false;
1299
1349
  }
1300
1350
  return MobXGlobals$$1;
1301
1351
  }());
@@ -1540,7 +1590,7 @@ function logTraceInfo(derivation, observable$$1) {
1540
1590
  var lines = [];
1541
1591
  printDepTree(getDependencyTree$$1(derivation), lines, 1);
1542
1592
  // prettier-ignore
1543
- new Function("debugger;\n/*\nTracing '" + derivation.name + "'\n\nYou are entering this break point because derivation '" + derivation.name + "' is being traced and '" + observable$$1.name + "' is now forcing it to update.\nJust follow the stacktrace you should now see in the devtools to see precisely what piece of your code is causing this update\nThe stackframe you are looking for is at least ~6-8 stack-frames up.\n\n" + (derivation instanceof ComputedValue$$1 ? derivation.derivation.toString() : "") + "\n\nThe dependencies for this derivation are:\n\n" + lines.join("\n") + "\n*/\n ")();
1593
+ new Function("debugger;\n/*\nTracing '" + derivation.name + "'\n\nYou are entering this break point because derivation '" + derivation.name + "' is being traced and '" + observable$$1.name + "' is now forcing it to update.\nJust follow the stacktrace you should now see in the devtools to see precisely what piece of your code is causing this update\nThe stackframe you are looking for is at least ~6-8 stack-frames up.\n\n" + (derivation instanceof ComputedValue$$1 ? derivation.derivation.toString().replace(/[*]\//g, "/") : "") + "\n\nThe dependencies for this derivation are:\n\n" + lines.join("\n") + "\n*/\n ")();
1544
1594
  }
1545
1595
  }
1546
1596
  function printDepTree(tree, lines, depth) {
@@ -1614,6 +1664,9 @@ var Reaction$$1 = /** @class */ (function () {
1614
1664
  }
1615
1665
  };
1616
1666
  Reaction$$1.prototype.track = function (fn) {
1667
+ if (this.isDisposed) {
1668
+ fail$$1("Reaction already disposed");
1669
+ }
1617
1670
  startBatch$$1();
1618
1671
  var notify = isSpyEnabled$$1();
1619
1672
  var startTime;
@@ -1649,9 +1702,14 @@ var Reaction$$1 = /** @class */ (function () {
1649
1702
  }
1650
1703
  if (globalState$$1.disableErrorBoundaries)
1651
1704
  throw error;
1652
- var message = "[mobx] Encountered an uncaught exception that was thrown by a reaction or observer component, in: '" + this;
1653
- console.error(message, error);
1654
- /** If debugging brought you here, please, read the above message :-). Tnx! */
1705
+ var message = "[mobx] Encountered an uncaught exception that was thrown by a reaction or observer component, in: '" + this + "'";
1706
+ if (globalState$$1.suppressReactionErrors) {
1707
+ console.warn("[mobx] (error in reaction '" + this.name + "' suppressed, fix error of causing action below)"); // prettier-ignore
1708
+ }
1709
+ else {
1710
+ console.error(message, error);
1711
+ /** If debugging brought you here, please, read the above message :-). Tnx! */
1712
+ }
1655
1713
  if (isSpyEnabled$$1()) {
1656
1714
  spyReport$$1({
1657
1715
  type: "error",
@@ -1869,7 +1927,7 @@ var action$$1 = function action$$1(arg1, arg2, arg3, arg4) {
1869
1927
  // @action fn() {}
1870
1928
  if (arg4 === true) {
1871
1929
  // apply to instance immediately
1872
- addHiddenProp$$1(arg1, arg2, createAction$$1(arg1.name || arg2, arg3.value));
1930
+ addHiddenProp$$1(arg1, arg2, createAction$$1(arg1.name || arg2, arg3.value, this));
1873
1931
  }
1874
1932
  else {
1875
1933
  return namedActionDecorator$$1(arg2).apply(null, arguments);
@@ -2008,20 +2066,32 @@ function onBecomeUnobserved$$1(thing, arg2, arg3) {
2008
2066
  function interceptHook(hook, thing, arg2, arg3) {
2009
2067
  var atom = typeof arg2 === "string" ? getAtom$$1(thing, arg2) : getAtom$$1(thing);
2010
2068
  var cb = typeof arg2 === "string" ? arg3 : arg2;
2069
+ var listenersKey = hook + "Listeners";
2070
+ if (atom[listenersKey]) {
2071
+ atom[listenersKey].add(cb);
2072
+ }
2073
+ else {
2074
+ atom[listenersKey] = new Set([cb]);
2075
+ }
2011
2076
  var orig = atom[hook];
2012
2077
  if (typeof orig !== "function")
2013
2078
  return fail$$1(process.env.NODE_ENV !== "production" && "Not an atom that can be (un)observed");
2014
- atom[hook] = function () {
2015
- orig.call(this);
2016
- cb.call(this);
2017
- };
2018
2079
  return function () {
2019
- atom[hook] = orig;
2080
+ var hookListeners = atom[listenersKey];
2081
+ if (hookListeners) {
2082
+ hookListeners.delete(cb);
2083
+ if (hookListeners.size === 0) {
2084
+ delete atom[listenersKey];
2085
+ }
2086
+ }
2020
2087
  };
2021
2088
  }
2022
2089
 
2023
2090
  function configure$$1(options) {
2024
2091
  var enforceActions = options.enforceActions, computedRequiresReaction = options.computedRequiresReaction, disableErrorBoundaries = options.disableErrorBoundaries, reactionScheduler = options.reactionScheduler;
2092
+ if (options.isolateGlobalState === true) {
2093
+ isolateGlobalState$$1();
2094
+ }
2025
2095
  if (enforceActions !== undefined) {
2026
2096
  if (typeof enforceActions === "boolean" || enforceActions === "strict")
2027
2097
  deprecated$$1("Deprecated value for 'enforceActions', use 'false' => '\"never\"', 'true' => '\"observed\"', '\"strict\"' => \"'always'\" instead");
@@ -2048,9 +2118,6 @@ function configure$$1(options) {
2048
2118
  if (computedRequiresReaction !== undefined) {
2049
2119
  globalState$$1.computedRequiresReaction = !!computedRequiresReaction;
2050
2120
  }
2051
- if (options.isolateGlobalState === true) {
2052
- isolateGlobalState$$1();
2053
- }
2054
2121
  if (disableErrorBoundaries !== undefined) {
2055
2122
  if (disableErrorBoundaries === true)
2056
2123
  console.warn("WARNING: Debug feature only. MobX will NOT recover from errors when `disableErrorBoundaries` is enabled.");
@@ -2172,7 +2239,7 @@ function flow$$1(generator) {
2172
2239
  var gen = action$$1(name + " - runid: " + runId + " - init", generator).apply(ctx, args);
2173
2240
  var rejector;
2174
2241
  var pendingPromise = undefined;
2175
- var res = new Promise(function (resolve, reject) {
2242
+ var promise = new Promise(function (resolve, reject) {
2176
2243
  var stepId = 0;
2177
2244
  rejector = reject;
2178
2245
  function onFulfilled(res) {
@@ -2210,14 +2277,14 @@ function flow$$1(generator) {
2210
2277
  }
2211
2278
  onFulfilled(undefined); // kick off the process
2212
2279
  });
2213
- res.cancel = action$$1(name + " - runid: " + runId + " - cancel", function () {
2280
+ promise.cancel = action$$1(name + " - runid: " + runId + " - cancel", function () {
2214
2281
  try {
2215
2282
  if (pendingPromise)
2216
2283
  cancelPromise(pendingPromise);
2217
2284
  // Finally block can return (or yield) stuff..
2218
- var res_1 = gen.return();
2285
+ var res = gen.return();
2219
2286
  // eat anything that promise would do, it's cancelled!
2220
- var yieldedPromise = Promise.resolve(res_1.value);
2287
+ var yieldedPromise = Promise.resolve(res.value);
2221
2288
  yieldedPromise.then(noop$$1, noop$$1);
2222
2289
  cancelPromise(yieldedPromise); // maybe it can be cancelled :)
2223
2290
  // reject our original promise
@@ -2227,7 +2294,7 @@ function flow$$1(generator) {
2227
2294
  rejector(e); // there could be a throwing finally block
2228
2295
  }
2229
2296
  });
2230
- return res;
2297
+ return promise;
2231
2298
  };
2232
2299
  }
2233
2300
  function cancelPromise(promise) {
@@ -2335,11 +2402,14 @@ function keys$$1(obj) {
2335
2402
  if (isObservableMap$$1(obj)) {
2336
2403
  return Array.from(obj.keys());
2337
2404
  }
2405
+ if (isObservableSet$$1(obj)) {
2406
+ return Array.from(obj.keys());
2407
+ }
2338
2408
  if (isObservableArray$$1(obj)) {
2339
2409
  return obj.map(function (_, index) { return index; });
2340
2410
  }
2341
2411
  return fail$$1(process.env.NODE_ENV !== "production" &&
2342
- "'keys()' can only be used on observable objects, arrays and maps");
2412
+ "'keys()' can only be used on observable objects, arrays, sets and maps");
2343
2413
  }
2344
2414
  function values$$1(obj) {
2345
2415
  if (isObservableObject$$1(obj)) {
@@ -2348,11 +2418,14 @@ function values$$1(obj) {
2348
2418
  if (isObservableMap$$1(obj)) {
2349
2419
  return keys$$1(obj).map(function (key) { return obj.get(key); });
2350
2420
  }
2421
+ if (isObservableSet$$1(obj)) {
2422
+ return Array.from(obj.values());
2423
+ }
2351
2424
  if (isObservableArray$$1(obj)) {
2352
2425
  return obj.slice();
2353
2426
  }
2354
2427
  return fail$$1(process.env.NODE_ENV !== "production" &&
2355
- "'values()' can only be used on observable objects, arrays and maps");
2428
+ "'values()' can only be used on observable objects, arrays, sets and maps");
2356
2429
  }
2357
2430
  function entries$$1(obj) {
2358
2431
  if (isObservableObject$$1(obj)) {
@@ -2361,6 +2434,9 @@ function entries$$1(obj) {
2361
2434
  if (isObservableMap$$1(obj)) {
2362
2435
  return keys$$1(obj).map(function (key) { return [key, obj.get(key)]; });
2363
2436
  }
2437
+ if (isObservableSet$$1(obj)) {
2438
+ return Array.from(obj.entries());
2439
+ }
2364
2440
  if (isObservableArray$$1(obj)) {
2365
2441
  return obj.map(function (key, index) { return [index, key]; });
2366
2442
  }
@@ -2416,6 +2492,9 @@ function remove$$1(obj, key) {
2416
2492
  else if (isObservableMap$$1(obj)) {
2417
2493
  obj.delete(key);
2418
2494
  }
2495
+ else if (isObservableSet$$1(obj)) {
2496
+ obj.delete(key);
2497
+ }
2419
2498
  else if (isObservableArray$$1(obj)) {
2420
2499
  if (typeof key !== "number")
2421
2500
  key = parseInt(key, 10);
@@ -2436,6 +2515,9 @@ function has$$1(obj, key) {
2436
2515
  else if (isObservableMap$$1(obj)) {
2437
2516
  return obj.has(key);
2438
2517
  }
2518
+ else if (isObservableSet$$1(obj)) {
2519
+ return obj.has(key);
2520
+ }
2439
2521
  else if (isObservableArray$$1(obj)) {
2440
2522
  return key >= 0 && key < obj.length;
2441
2523
  }
@@ -2513,20 +2595,36 @@ function toJSHelper(source, options, __alreadySeen) {
2513
2595
  res_1[i] = toAdd[i];
2514
2596
  return res_1;
2515
2597
  }
2598
+ if (isObservableSet$$1(source) || Object.getPrototypeOf(source) === Set.prototype) {
2599
+ if (options.exportMapsAsObjects === false) {
2600
+ var res_2 = cache(__alreadySeen, source, new Set(), options);
2601
+ source.forEach(function (value) {
2602
+ res_2.add(toJSHelper(value, options, __alreadySeen));
2603
+ });
2604
+ return res_2;
2605
+ }
2606
+ else {
2607
+ var res_3 = cache(__alreadySeen, source, [], options);
2608
+ source.forEach(function (value) {
2609
+ res_3.push(toJSHelper(value, options, __alreadySeen));
2610
+ });
2611
+ return res_3;
2612
+ }
2613
+ }
2516
2614
  if (isObservableMap$$1(source) || Object.getPrototypeOf(source) === Map.prototype) {
2517
2615
  if (options.exportMapsAsObjects === false) {
2518
- var res_2 = cache(__alreadySeen, source, new Map(), options);
2616
+ var res_4 = cache(__alreadySeen, source, new Map(), options);
2519
2617
  source.forEach(function (value, key) {
2520
- res_2.set(key, toJSHelper(value, options, __alreadySeen));
2618
+ res_4.set(key, toJSHelper(value, options, __alreadySeen));
2521
2619
  });
2522
- return res_2;
2620
+ return res_4;
2523
2621
  }
2524
2622
  else {
2525
- var res_3 = cache(__alreadySeen, source, {}, options);
2623
+ var res_5 = cache(__alreadySeen, source, {}, options);
2526
2624
  source.forEach(function (value, key) {
2527
- res_3[key] = toJSHelper(value, options, __alreadySeen);
2625
+ res_5[key] = toJSHelper(value, options, __alreadySeen);
2528
2626
  });
2529
- return res_3;
2627
+ return res_5;
2530
2628
  }
2531
2629
  }
2532
2630
  // Fallback to the situation that source is an ObservableObject or a plain object
@@ -2833,7 +2931,7 @@ var ObservableArrayAdministration = /** @class */ (function () {
2833
2931
  return value;
2834
2932
  };
2835
2933
  ObservableArrayAdministration.prototype.dehanceValues = function (values$$1) {
2836
- if (this.dehancer !== undefined && this.values.length > 0)
2934
+ if (this.dehancer !== undefined && values$$1.length > 0)
2837
2935
  return values$$1.map(this.dehancer);
2838
2936
  return values$$1;
2839
2937
  };
@@ -3254,7 +3352,7 @@ var ObservableMap$$1 = /** @class */ (function () {
3254
3352
  entry.setNewValue(value);
3255
3353
  }
3256
3354
  else {
3257
- entry = new ObservableValue$$1(value, referenceEnhancer$$1, this.name + "." + key + "?", false);
3355
+ entry = new ObservableValue$$1(value, referenceEnhancer$$1, this.name + "." + stringifyKey(key) + "?", false);
3258
3356
  this._hasMap.set(key, entry);
3259
3357
  }
3260
3358
  return entry;
@@ -3287,7 +3385,7 @@ var ObservableMap$$1 = /** @class */ (function () {
3287
3385
  var _this = this;
3288
3386
  checkIfStateModificationsAreAllowed$$1(this._keysAtom);
3289
3387
  transaction$$1(function () {
3290
- var observable$$1 = new ObservableValue$$1(newValue, _this.enhancer, _this.name + "." + key, false);
3388
+ var observable$$1 = new ObservableValue$$1(newValue, _this.enhancer, _this.name + "." + stringifyKey(key), false);
3291
3389
  _this._data.set(key, observable$$1);
3292
3390
  newValue = observable$$1.value; // value might have been changed
3293
3391
  _this._updateHasMapEntry(key, true);
@@ -3387,8 +3485,11 @@ var ObservableMap$$1 = /** @class */ (function () {
3387
3485
  var _b = __read(_a, 2), key = _b[0], value = _b[1];
3388
3486
  return _this.set(key, value);
3389
3487
  });
3390
- else if (isES6Map$$1(other))
3488
+ else if (isES6Map$$1(other)) {
3489
+ if (other.constructor !== Map)
3490
+ fail$$1("Cannot initialize from classes that inherit from Map: " + other.constructor.name); // prettier-ignore
3391
3491
  other.forEach(function (value, key) { return _this.set(key, value); });
3492
+ }
3392
3493
  else if (other !== null && other !== undefined)
3393
3494
  fail$$1("Cannot initialize map from " + other);
3394
3495
  });
@@ -3448,7 +3549,8 @@ var ObservableMap$$1 = /** @class */ (function () {
3448
3549
  try {
3449
3550
  for (var _b = __values(this), _c = _b.next(); !_c.done; _c = _b.next()) {
3450
3551
  var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
3451
- res["" + key] = value;
3552
+ // We lie about symbol key types due to https://github.com/Microsoft/TypeScript/issues/1863
3553
+ res[typeof key === "symbol" ? key : stringifyKey(key)] = value;
3452
3554
  }
3453
3555
  }
3454
3556
  catch (e_3_1) { e_3 = { error: e_3_1 }; }
@@ -3476,7 +3578,7 @@ var ObservableMap$$1 = /** @class */ (function () {
3476
3578
  return (this.name +
3477
3579
  "[{ " +
3478
3580
  Array.from(this.keys())
3479
- .map(function (key) { return key + ": " + ("" + _this.get(key)); })
3581
+ .map(function (key) { return stringifyKey(key) + ": " + ("" + _this.get(key)); })
3480
3582
  .join(", ") +
3481
3583
  " }]");
3482
3584
  };
@@ -3495,9 +3597,233 @@ var ObservableMap$$1 = /** @class */ (function () {
3495
3597
  };
3496
3598
  return ObservableMap$$1;
3497
3599
  }());
3600
+ function stringifyKey(key) {
3601
+ if (key && key.toString)
3602
+ return key.toString();
3603
+ else
3604
+ return new String(key).toString();
3605
+ }
3498
3606
  /* 'var' fixes small-build issue */
3499
3607
  var isObservableMap$$1 = createInstanceofPredicate$$1("ObservableMap", ObservableMap$$1);
3500
3608
 
3609
+ var _a$1;
3610
+ var ObservableSetMarker = {};
3611
+ var ObservableSet$$1 = /** @class */ (function () {
3612
+ function ObservableSet$$1(initialData, enhancer, name) {
3613
+ if (enhancer === void 0) { enhancer = deepEnhancer$$1; }
3614
+ if (name === void 0) { name = "ObservableSet@" + getNextId$$1(); }
3615
+ this.name = name;
3616
+ this[_a$1] = ObservableSetMarker;
3617
+ this._data = new Set();
3618
+ this._atom = createAtom$$1(this.name);
3619
+ this[Symbol.toStringTag] = "Set";
3620
+ if (typeof Set !== "function") {
3621
+ throw new Error("mobx.set requires Set polyfill for the current browser. Check babel-polyfill or core-js/es6/set.js");
3622
+ }
3623
+ this.enhancer = function (newV, oldV) { return enhancer(newV, oldV, name); };
3624
+ if (initialData) {
3625
+ this.replace(initialData);
3626
+ }
3627
+ }
3628
+ ObservableSet$$1.prototype.dehanceValue = function (value) {
3629
+ if (this.dehancer !== undefined) {
3630
+ return this.dehancer(value);
3631
+ }
3632
+ return value;
3633
+ };
3634
+ ObservableSet$$1.prototype.clear = function () {
3635
+ var _this = this;
3636
+ transaction$$1(function () {
3637
+ untracked$$1(function () {
3638
+ var e_1, _a;
3639
+ try {
3640
+ for (var _b = __values(_this._data.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
3641
+ var value = _c.value;
3642
+ _this.delete(value);
3643
+ }
3644
+ }
3645
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
3646
+ finally {
3647
+ try {
3648
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
3649
+ }
3650
+ finally { if (e_1) throw e_1.error; }
3651
+ }
3652
+ });
3653
+ });
3654
+ };
3655
+ ObservableSet$$1.prototype.forEach = function (callbackFn, thisArg) {
3656
+ var e_2, _a;
3657
+ try {
3658
+ for (var _b = __values(this), _c = _b.next(); !_c.done; _c = _b.next()) {
3659
+ var value = _c.value;
3660
+ callbackFn.call(thisArg, value, value, this);
3661
+ }
3662
+ }
3663
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
3664
+ finally {
3665
+ try {
3666
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
3667
+ }
3668
+ finally { if (e_2) throw e_2.error; }
3669
+ }
3670
+ };
3671
+ Object.defineProperty(ObservableSet$$1.prototype, "size", {
3672
+ get: function () {
3673
+ this._atom.reportObserved();
3674
+ return this._data.size;
3675
+ },
3676
+ enumerable: true,
3677
+ configurable: true
3678
+ });
3679
+ ObservableSet$$1.prototype.add = function (value) {
3680
+ var _this = this;
3681
+ checkIfStateModificationsAreAllowed$$1(this._atom);
3682
+ if (hasInterceptors$$1(this)) {
3683
+ var change = interceptChange$$1(this, {
3684
+ type: "add",
3685
+ object: this,
3686
+ newValue: value
3687
+ });
3688
+ if (!change)
3689
+ return this;
3690
+ // TODO: ideally, value = change.value would be done here, so that values can be
3691
+ // changed by interceptor. Same applies for other Set and Map api's.
3692
+ }
3693
+ if (!this.has(value)) {
3694
+ transaction$$1(function () {
3695
+ _this._data.add(_this.enhancer(value, undefined));
3696
+ _this._atom.reportChanged();
3697
+ });
3698
+ var notifySpy = isSpyEnabled$$1();
3699
+ var notify = hasListeners$$1(this);
3700
+ var change = notify || notifySpy
3701
+ ? {
3702
+ type: "add",
3703
+ object: this,
3704
+ newValue: value
3705
+ }
3706
+ : null;
3707
+ if (notifySpy && process.env.NODE_ENV !== "production")
3708
+ spyReportStart$$1(change);
3709
+ if (notify)
3710
+ notifyListeners$$1(this, change);
3711
+ if (notifySpy && process.env.NODE_ENV !== "production")
3712
+ spyReportEnd$$1();
3713
+ }
3714
+ return this;
3715
+ };
3716
+ ObservableSet$$1.prototype.delete = function (value) {
3717
+ var _this = this;
3718
+ if (hasInterceptors$$1(this)) {
3719
+ var change = interceptChange$$1(this, {
3720
+ type: "delete",
3721
+ object: this,
3722
+ oldValue: value
3723
+ });
3724
+ if (!change)
3725
+ return false;
3726
+ }
3727
+ if (this.has(value)) {
3728
+ var notifySpy = isSpyEnabled$$1();
3729
+ var notify = hasListeners$$1(this);
3730
+ var change = notify || notifySpy
3731
+ ? {
3732
+ type: "delete",
3733
+ object: this,
3734
+ oldValue: value
3735
+ }
3736
+ : null;
3737
+ if (notifySpy && process.env.NODE_ENV !== "production")
3738
+ spyReportStart$$1(__assign({}, change, { name: this.name }));
3739
+ transaction$$1(function () {
3740
+ _this._atom.reportChanged();
3741
+ _this._data.delete(value);
3742
+ });
3743
+ if (notify)
3744
+ notifyListeners$$1(this, change);
3745
+ if (notifySpy && process.env.NODE_ENV !== "production")
3746
+ spyReportEnd$$1();
3747
+ return true;
3748
+ }
3749
+ return false;
3750
+ };
3751
+ ObservableSet$$1.prototype.has = function (value) {
3752
+ this._atom.reportObserved();
3753
+ return this._data.has(this.dehanceValue(value));
3754
+ };
3755
+ ObservableSet$$1.prototype.entries = function () {
3756
+ var nextIndex = 0;
3757
+ var keys$$1 = Array.from(this.keys());
3758
+ var values$$1 = Array.from(this.values());
3759
+ return makeIterable({
3760
+ next: function () {
3761
+ var index = nextIndex;
3762
+ nextIndex += 1;
3763
+ return index < values$$1.length
3764
+ ? { value: [keys$$1[index], values$$1[index]], done: false }
3765
+ : { done: true };
3766
+ }
3767
+ });
3768
+ };
3769
+ ObservableSet$$1.prototype.keys = function () {
3770
+ return this.values();
3771
+ };
3772
+ ObservableSet$$1.prototype.values = function () {
3773
+ this._atom.reportObserved();
3774
+ var self = this;
3775
+ var nextIndex = 0;
3776
+ var observableValues = Array.from(this._data.values());
3777
+ return makeIterable({
3778
+ next: function () {
3779
+ return nextIndex < observableValues.length
3780
+ ? { value: self.dehanceValue(observableValues[nextIndex++]), done: false }
3781
+ : { done: true };
3782
+ }
3783
+ });
3784
+ };
3785
+ ObservableSet$$1.prototype.replace = function (other) {
3786
+ var _this = this;
3787
+ if (isObservableSet$$1(other)) {
3788
+ other = other.toJS();
3789
+ }
3790
+ transaction$$1(function () {
3791
+ if (Array.isArray(other)) {
3792
+ _this.clear();
3793
+ other.forEach(function (value) { return _this.add(value); });
3794
+ }
3795
+ else if (isES6Set$$1(other)) {
3796
+ _this.clear();
3797
+ other.forEach(function (value) { return _this.add(value); });
3798
+ }
3799
+ else if (other !== null && other !== undefined) {
3800
+ fail$$1("Cannot initialize set from " + other);
3801
+ }
3802
+ });
3803
+ return this;
3804
+ };
3805
+ ObservableSet$$1.prototype.observe = function (listener, fireImmediately) {
3806
+ // TODO 'fireImmediately' can be true?
3807
+ process.env.NODE_ENV !== "production" &&
3808
+ invariant$$1(fireImmediately !== true, "`observe` doesn't support fireImmediately=true in combination with sets.");
3809
+ return registerListener$$1(this, listener);
3810
+ };
3811
+ ObservableSet$$1.prototype.intercept = function (handler) {
3812
+ return registerInterceptor$$1(this, handler);
3813
+ };
3814
+ ObservableSet$$1.prototype.toJS = function () {
3815
+ return new Set(this);
3816
+ };
3817
+ ObservableSet$$1.prototype.toString = function () {
3818
+ return this.name + "[ " + Array.from(this).join(", ") + " ]";
3819
+ };
3820
+ ObservableSet$$1.prototype[(_a$1 = $mobx$$1, Symbol.iterator)] = function () {
3821
+ return this.values();
3822
+ };
3823
+ return ObservableSet$$1;
3824
+ }());
3825
+ var isObservableSet$$1 = createInstanceofPredicate$$1("ObservableSet", ObservableSet$$1);
3826
+
3501
3827
  var ObservableObjectAdministration$$1 = /** @class */ (function () {
3502
3828
  function ObservableObjectAdministration$$1(target, values$$1, name, defaultEnhancer) {
3503
3829
  if (values$$1 === void 0) { values$$1 = new Map(); }
@@ -3769,7 +4095,7 @@ function getAdministrationForComputedPropOwner(owner) {
3769
4095
  function generateComputedPropConfig$$1(propName) {
3770
4096
  return (computedPropertyConfigs[propName] ||
3771
4097
  (computedPropertyConfigs[propName] = {
3772
- configurable: true,
4098
+ configurable: false,
3773
4099
  enumerable: false,
3774
4100
  get: function () {
3775
4101
  return getAdministrationForComputedPropOwner(this).read(propName);
@@ -3797,6 +4123,9 @@ function getAtom$$1(thing, property) {
3797
4123
  "It is not possible to get index atoms from arrays");
3798
4124
  return thing[$mobx$$1].atom;
3799
4125
  }
4126
+ if (isObservableSet$$1(thing)) {
4127
+ return thing[$mobx$$1];
4128
+ }
3800
4129
  if (isObservableMap$$1(thing)) {
3801
4130
  var anyThing = thing;
3802
4131
  if (property === undefined)
@@ -3839,7 +4168,7 @@ function getAdministration$$1(thing, property) {
3839
4168
  return getAdministration$$1(getAtom$$1(thing, property));
3840
4169
  if (isAtom$$1(thing) || isComputedValue$$1(thing) || isReaction$$1(thing))
3841
4170
  return thing;
3842
- if (isObservableMap$$1(thing))
4171
+ if (isObservableMap$$1(thing) || isObservableSet$$1(thing))
3843
4172
  return thing;
3844
4173
  // Initializers run lazily when transpiling to babel, so make sure they are run...
3845
4174
  initializeInstance$$1(thing);
@@ -3851,7 +4180,7 @@ function getDebugName$$1(thing, property) {
3851
4180
  var named;
3852
4181
  if (property !== undefined)
3853
4182
  named = getAtom$$1(thing, property);
3854
- else if (isObservableObject$$1(thing) || isObservableMap$$1(thing))
4183
+ else if (isObservableObject$$1(thing) || isObservableMap$$1(thing) || isObservableSet$$1(thing))
3855
4184
  named = getAdministration$$1(thing);
3856
4185
  else
3857
4186
  named = getAtom$$1(thing); // valid for arrays as well
@@ -3960,7 +4289,8 @@ function deepEq(a, b, aStack, bStack) {
3960
4289
  }
3961
4290
  else {
3962
4291
  // Deep compare objects.
3963
- var keys$$1 = Object.keys(a), key;
4292
+ var keys$$1 = Object.keys(a);
4293
+ var key = void 0;
3964
4294
  length = keys$$1.length;
3965
4295
  // Ensure that both objects contain the same number of properties before comparing deep equality.
3966
4296
  if (Object.keys(b).length !== length)
@@ -3982,6 +4312,8 @@ function unwrap(a) {
3982
4312
  return a.slice();
3983
4313
  if (isES6Map$$1(a) || isObservableMap$$1(a))
3984
4314
  return Array.from(a.entries());
4315
+ if (isES6Set$$1(a) || isObservableSet$$1(a))
4316
+ return Array.from(a.entries());
3985
4317
  return a;
3986
4318
  }
3987
4319
  function has$1(a, key) {
@@ -4022,7 +4354,7 @@ but at least in this file we can magically reorder the imports with trial and er
4022
4354
  *
4023
4355
  */
4024
4356
  if (typeof Proxy === "undefined" || typeof Symbol === "undefined") {
4025
- throw new Error("[mobx] MobX 5+ requires Proxy and Symbol objects. If your environment doesn't support Proxy objects, please downgrade to MobX 4. For React Native Android, consider upgrading JSCore.");
4357
+ throw new Error("[mobx] MobX 5+ requires Proxy and Symbol objects. If your environment doesn't support Symbol or Proxy objects, please downgrade to MobX 4. For React Native Android, consider upgrading JSCore.");
4026
4358
  }
4027
4359
  try {
4028
4360
  // define process.env if needed
@@ -4040,7 +4372,8 @@ catch (e) {
4040
4372
  (function () {
4041
4373
  function testCodeMinification() { }
4042
4374
  if (testCodeMinification.name !== "testCodeMinification" &&
4043
- process.env.NODE_ENV !== "production") {
4375
+ process.env.NODE_ENV !== "production" &&
4376
+ process.env.IGNORE_MOBX_MINIFY_WARNING !== "true") {
4044
4377
  console.warn(
4045
4378
  // Template literal(backtick) is used for fix issue with rollup-plugin-commonjs https://github.com/rollup/rollup-plugin-commonjs/issues/344
4046
4379
  "[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");
@@ -4068,6 +4401,8 @@ exports.isBoxedObservable = isObservableValue$$1;
4068
4401
  exports.isObservableArray = isObservableArray$$1;
4069
4402
  exports.ObservableMap = ObservableMap$$1;
4070
4403
  exports.isObservableMap = isObservableMap$$1;
4404
+ exports.ObservableSet = ObservableSet$$1;
4405
+ exports.isObservableSet = isObservableSet$$1;
4071
4406
  exports.transaction = transaction$$1;
4072
4407
  exports.observable = observable$$1;
4073
4408
  exports.computed = computed$$1;