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.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");
@@ -561,25 +585,35 @@ var computed$$1 = function computed$$1(arg1, arg2, arg3) {
561
585
  };
562
586
  computed$$1.struct = computedStructDecorator;
563
587
 
564
- function createAction$$1(actionName, fn) {
588
+ function createAction$$1(actionName, fn, ref) {
565
589
  if (process.env.NODE_ENV !== "production") {
566
590
  invariant$$1(typeof fn === "function", "`action` can only be invoked on functions");
567
591
  if (typeof actionName !== "string" || !actionName)
568
592
  fail$$1("actions should have valid names, got: '" + actionName + "'");
569
593
  }
570
594
  var res = function () {
571
- return executeAction$$1(actionName, fn, this, arguments);
595
+ return executeAction$$1(actionName, fn, ref || this, arguments);
572
596
  };
573
597
  res.isMobxAction = true;
574
598
  return res;
575
599
  }
576
600
  function executeAction$$1(actionName, fn, scope, args) {
577
601
  var runInfo = startAction(actionName, fn, scope, args);
602
+ var shouldSupressReactionError = true;
578
603
  try {
579
- return fn.apply(scope, args);
604
+ var res = fn.apply(scope, args);
605
+ shouldSupressReactionError = false;
606
+ return res;
580
607
  }
581
608
  finally {
582
- 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
+ }
583
617
  }
584
618
  }
585
619
  function startAction(actionName, fn, scope, args) {
@@ -650,11 +684,14 @@ function allowStateChangesInsideComputed$$1(func) {
650
684
 
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") {
@@ -700,7 +737,7 @@ var ObservableValue$$1 = /** @class */ (function (_super) {
700
737
  }
701
738
  // apply modifier
702
739
  newValue = this.enhancer(newValue, this.value, this.name);
703
- return this.value !== newValue ? newValue : globalState$$1.UNCHANGED;
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;
@@ -815,8 +852,16 @@ var ComputedValue$$1 = /** @class */ (function () {
815
852
  ComputedValue$$1.prototype.onBecomeStale = function () {
816
853
  propagateMaybeChanged$$1(this);
817
854
  };
818
- ComputedValue$$1.prototype.onBecomeUnobserved = function () { };
819
- 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
+ };
820
865
  /**
821
866
  * Returns the current value of this computed value.
822
867
  * Will evaluate its computation first if needed.
@@ -1294,6 +1339,11 @@ var MobXGlobals$$1 = /** @class */ (function () {
1294
1339
  * the stack when an exception occurs while debugging.
1295
1340
  */
1296
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;
1297
1347
  }
1298
1348
  return MobXGlobals$$1;
1299
1349
  }());
@@ -1538,7 +1588,7 @@ function logTraceInfo(derivation, observable$$1) {
1538
1588
  var lines = [];
1539
1589
  printDepTree(getDependencyTree$$1(derivation), lines, 1);
1540
1590
  // prettier-ignore
1541
- 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 ")();
1542
1592
  }
1543
1593
  }
1544
1594
  function printDepTree(tree, lines, depth) {
@@ -1612,6 +1662,9 @@ var Reaction$$1 = /** @class */ (function () {
1612
1662
  }
1613
1663
  };
1614
1664
  Reaction$$1.prototype.track = function (fn) {
1665
+ if (this.isDisposed) {
1666
+ fail$$1("Reaction already disposed");
1667
+ }
1615
1668
  startBatch$$1();
1616
1669
  var notify = isSpyEnabled$$1();
1617
1670
  var startTime;
@@ -1647,9 +1700,14 @@ var Reaction$$1 = /** @class */ (function () {
1647
1700
  }
1648
1701
  if (globalState$$1.disableErrorBoundaries)
1649
1702
  throw error;
1650
- var message = "[mobx] Encountered an uncaught exception that was thrown by a reaction or observer component, in: '" + this;
1651
- console.error(message, error);
1652
- /** If debugging brought you here, please, read the above message :-). Tnx! */
1703
+ var message = "[mobx] Encountered an uncaught exception that was thrown by a reaction or observer component, in: '" + this + "'";
1704
+ if (globalState$$1.suppressReactionErrors) {
1705
+ console.warn("[mobx] (error in reaction '" + this.name + "' suppressed, fix error of causing action below)"); // prettier-ignore
1706
+ }
1707
+ else {
1708
+ console.error(message, error);
1709
+ /** If debugging brought you here, please, read the above message :-). Tnx! */
1710
+ }
1653
1711
  if (isSpyEnabled$$1()) {
1654
1712
  spyReport$$1({
1655
1713
  type: "error",
@@ -1867,7 +1925,7 @@ var action$$1 = function action$$1(arg1, arg2, arg3, arg4) {
1867
1925
  // @action fn() {}
1868
1926
  if (arg4 === true) {
1869
1927
  // apply to instance immediately
1870
- addHiddenProp$$1(arg1, arg2, createAction$$1(arg1.name || arg2, arg3.value));
1928
+ addHiddenProp$$1(arg1, arg2, createAction$$1(arg1.name || arg2, arg3.value, this));
1871
1929
  }
1872
1930
  else {
1873
1931
  return namedActionDecorator$$1(arg2).apply(null, arguments);
@@ -2006,20 +2064,32 @@ function onBecomeUnobserved$$1(thing, arg2, arg3) {
2006
2064
  function interceptHook(hook, thing, arg2, arg3) {
2007
2065
  var atom = typeof arg2 === "string" ? getAtom$$1(thing, arg2) : getAtom$$1(thing);
2008
2066
  var cb = typeof arg2 === "string" ? arg3 : arg2;
2067
+ var listenersKey = hook + "Listeners";
2068
+ if (atom[listenersKey]) {
2069
+ atom[listenersKey].add(cb);
2070
+ }
2071
+ else {
2072
+ atom[listenersKey] = new Set([cb]);
2073
+ }
2009
2074
  var orig = atom[hook];
2010
2075
  if (typeof orig !== "function")
2011
2076
  return fail$$1(process.env.NODE_ENV !== "production" && "Not an atom that can be (un)observed");
2012
- atom[hook] = function () {
2013
- orig.call(this);
2014
- cb.call(this);
2015
- };
2016
2077
  return function () {
2017
- atom[hook] = orig;
2078
+ var hookListeners = atom[listenersKey];
2079
+ if (hookListeners) {
2080
+ hookListeners.delete(cb);
2081
+ if (hookListeners.size === 0) {
2082
+ delete atom[listenersKey];
2083
+ }
2084
+ }
2018
2085
  };
2019
2086
  }
2020
2087
 
2021
2088
  function configure$$1(options) {
2022
2089
  var enforceActions = options.enforceActions, computedRequiresReaction = options.computedRequiresReaction, disableErrorBoundaries = options.disableErrorBoundaries, reactionScheduler = options.reactionScheduler;
2090
+ if (options.isolateGlobalState === true) {
2091
+ isolateGlobalState$$1();
2092
+ }
2023
2093
  if (enforceActions !== undefined) {
2024
2094
  if (typeof enforceActions === "boolean" || enforceActions === "strict")
2025
2095
  deprecated$$1("Deprecated value for 'enforceActions', use 'false' => '\"never\"', 'true' => '\"observed\"', '\"strict\"' => \"'always'\" instead");
@@ -2046,9 +2116,6 @@ function configure$$1(options) {
2046
2116
  if (computedRequiresReaction !== undefined) {
2047
2117
  globalState$$1.computedRequiresReaction = !!computedRequiresReaction;
2048
2118
  }
2049
- if (options.isolateGlobalState === true) {
2050
- isolateGlobalState$$1();
2051
- }
2052
2119
  if (disableErrorBoundaries !== undefined) {
2053
2120
  if (disableErrorBoundaries === true)
2054
2121
  console.warn("WARNING: Debug feature only. MobX will NOT recover from errors when `disableErrorBoundaries` is enabled.");
@@ -2170,7 +2237,7 @@ function flow$$1(generator) {
2170
2237
  var gen = action$$1(name + " - runid: " + runId + " - init", generator).apply(ctx, args);
2171
2238
  var rejector;
2172
2239
  var pendingPromise = undefined;
2173
- var res = new Promise(function (resolve, reject) {
2240
+ var promise = new Promise(function (resolve, reject) {
2174
2241
  var stepId = 0;
2175
2242
  rejector = reject;
2176
2243
  function onFulfilled(res) {
@@ -2208,14 +2275,14 @@ function flow$$1(generator) {
2208
2275
  }
2209
2276
  onFulfilled(undefined); // kick off the process
2210
2277
  });
2211
- res.cancel = action$$1(name + " - runid: " + runId + " - cancel", function () {
2278
+ promise.cancel = action$$1(name + " - runid: " + runId + " - cancel", function () {
2212
2279
  try {
2213
2280
  if (pendingPromise)
2214
2281
  cancelPromise(pendingPromise);
2215
2282
  // Finally block can return (or yield) stuff..
2216
- var res_1 = gen.return();
2283
+ var res = gen.return();
2217
2284
  // eat anything that promise would do, it's cancelled!
2218
- var yieldedPromise = Promise.resolve(res_1.value);
2285
+ var yieldedPromise = Promise.resolve(res.value);
2219
2286
  yieldedPromise.then(noop$$1, noop$$1);
2220
2287
  cancelPromise(yieldedPromise); // maybe it can be cancelled :)
2221
2288
  // reject our original promise
@@ -2225,7 +2292,7 @@ function flow$$1(generator) {
2225
2292
  rejector(e); // there could be a throwing finally block
2226
2293
  }
2227
2294
  });
2228
- return res;
2295
+ return promise;
2229
2296
  };
2230
2297
  }
2231
2298
  function cancelPromise(promise) {
@@ -2333,11 +2400,14 @@ function keys$$1(obj) {
2333
2400
  if (isObservableMap$$1(obj)) {
2334
2401
  return Array.from(obj.keys());
2335
2402
  }
2403
+ if (isObservableSet$$1(obj)) {
2404
+ return Array.from(obj.keys());
2405
+ }
2336
2406
  if (isObservableArray$$1(obj)) {
2337
2407
  return obj.map(function (_, index) { return index; });
2338
2408
  }
2339
2409
  return fail$$1(process.env.NODE_ENV !== "production" &&
2340
- "'keys()' can only be used on observable objects, arrays and maps");
2410
+ "'keys()' can only be used on observable objects, arrays, sets and maps");
2341
2411
  }
2342
2412
  function values$$1(obj) {
2343
2413
  if (isObservableObject$$1(obj)) {
@@ -2346,11 +2416,14 @@ function values$$1(obj) {
2346
2416
  if (isObservableMap$$1(obj)) {
2347
2417
  return keys$$1(obj).map(function (key) { return obj.get(key); });
2348
2418
  }
2419
+ if (isObservableSet$$1(obj)) {
2420
+ return Array.from(obj.values());
2421
+ }
2349
2422
  if (isObservableArray$$1(obj)) {
2350
2423
  return obj.slice();
2351
2424
  }
2352
2425
  return fail$$1(process.env.NODE_ENV !== "production" &&
2353
- "'values()' can only be used on observable objects, arrays and maps");
2426
+ "'values()' can only be used on observable objects, arrays, sets and maps");
2354
2427
  }
2355
2428
  function entries$$1(obj) {
2356
2429
  if (isObservableObject$$1(obj)) {
@@ -2359,6 +2432,9 @@ function entries$$1(obj) {
2359
2432
  if (isObservableMap$$1(obj)) {
2360
2433
  return keys$$1(obj).map(function (key) { return [key, obj.get(key)]; });
2361
2434
  }
2435
+ if (isObservableSet$$1(obj)) {
2436
+ return Array.from(obj.entries());
2437
+ }
2362
2438
  if (isObservableArray$$1(obj)) {
2363
2439
  return obj.map(function (key, index) { return [index, key]; });
2364
2440
  }
@@ -2414,6 +2490,9 @@ function remove$$1(obj, key) {
2414
2490
  else if (isObservableMap$$1(obj)) {
2415
2491
  obj.delete(key);
2416
2492
  }
2493
+ else if (isObservableSet$$1(obj)) {
2494
+ obj.delete(key);
2495
+ }
2417
2496
  else if (isObservableArray$$1(obj)) {
2418
2497
  if (typeof key !== "number")
2419
2498
  key = parseInt(key, 10);
@@ -2434,6 +2513,9 @@ function has$$1(obj, key) {
2434
2513
  else if (isObservableMap$$1(obj)) {
2435
2514
  return obj.has(key);
2436
2515
  }
2516
+ else if (isObservableSet$$1(obj)) {
2517
+ return obj.has(key);
2518
+ }
2437
2519
  else if (isObservableArray$$1(obj)) {
2438
2520
  return key >= 0 && key < obj.length;
2439
2521
  }
@@ -2511,20 +2593,36 @@ function toJSHelper(source, options, __alreadySeen) {
2511
2593
  res_1[i] = toAdd[i];
2512
2594
  return res_1;
2513
2595
  }
2596
+ if (isObservableSet$$1(source) || Object.getPrototypeOf(source) === Set.prototype) {
2597
+ if (options.exportMapsAsObjects === false) {
2598
+ var res_2 = cache(__alreadySeen, source, new Set(), options);
2599
+ source.forEach(function (value) {
2600
+ res_2.add(toJSHelper(value, options, __alreadySeen));
2601
+ });
2602
+ return res_2;
2603
+ }
2604
+ else {
2605
+ var res_3 = cache(__alreadySeen, source, [], options);
2606
+ source.forEach(function (value) {
2607
+ res_3.push(toJSHelper(value, options, __alreadySeen));
2608
+ });
2609
+ return res_3;
2610
+ }
2611
+ }
2514
2612
  if (isObservableMap$$1(source) || Object.getPrototypeOf(source) === Map.prototype) {
2515
2613
  if (options.exportMapsAsObjects === false) {
2516
- var res_2 = cache(__alreadySeen, source, new Map(), options);
2614
+ var res_4 = cache(__alreadySeen, source, new Map(), options);
2517
2615
  source.forEach(function (value, key) {
2518
- res_2.set(key, toJSHelper(value, options, __alreadySeen));
2616
+ res_4.set(key, toJSHelper(value, options, __alreadySeen));
2519
2617
  });
2520
- return res_2;
2618
+ return res_4;
2521
2619
  }
2522
2620
  else {
2523
- var res_3 = cache(__alreadySeen, source, {}, options);
2621
+ var res_5 = cache(__alreadySeen, source, {}, options);
2524
2622
  source.forEach(function (value, key) {
2525
- res_3[key] = toJSHelper(value, options, __alreadySeen);
2623
+ res_5[key] = toJSHelper(value, options, __alreadySeen);
2526
2624
  });
2527
- return res_3;
2625
+ return res_5;
2528
2626
  }
2529
2627
  }
2530
2628
  // Fallback to the situation that source is an ObservableObject or a plain object
@@ -2831,7 +2929,7 @@ var ObservableArrayAdministration = /** @class */ (function () {
2831
2929
  return value;
2832
2930
  };
2833
2931
  ObservableArrayAdministration.prototype.dehanceValues = function (values$$1) {
2834
- if (this.dehancer !== undefined && this.values.length > 0)
2932
+ if (this.dehancer !== undefined && values$$1.length > 0)
2835
2933
  return values$$1.map(this.dehancer);
2836
2934
  return values$$1;
2837
2935
  };
@@ -3252,7 +3350,7 @@ var ObservableMap$$1 = /** @class */ (function () {
3252
3350
  entry.setNewValue(value);
3253
3351
  }
3254
3352
  else {
3255
- entry = new ObservableValue$$1(value, referenceEnhancer$$1, this.name + "." + key + "?", false);
3353
+ entry = new ObservableValue$$1(value, referenceEnhancer$$1, this.name + "." + stringifyKey(key) + "?", false);
3256
3354
  this._hasMap.set(key, entry);
3257
3355
  }
3258
3356
  return entry;
@@ -3285,7 +3383,7 @@ var ObservableMap$$1 = /** @class */ (function () {
3285
3383
  var _this = this;
3286
3384
  checkIfStateModificationsAreAllowed$$1(this._keysAtom);
3287
3385
  transaction$$1(function () {
3288
- var observable$$1 = new ObservableValue$$1(newValue, _this.enhancer, _this.name + "." + key, false);
3386
+ var observable$$1 = new ObservableValue$$1(newValue, _this.enhancer, _this.name + "." + stringifyKey(key), false);
3289
3387
  _this._data.set(key, observable$$1);
3290
3388
  newValue = observable$$1.value; // value might have been changed
3291
3389
  _this._updateHasMapEntry(key, true);
@@ -3385,8 +3483,11 @@ var ObservableMap$$1 = /** @class */ (function () {
3385
3483
  var _b = __read(_a, 2), key = _b[0], value = _b[1];
3386
3484
  return _this.set(key, value);
3387
3485
  });
3388
- else if (isES6Map$$1(other))
3486
+ else if (isES6Map$$1(other)) {
3487
+ if (other.constructor !== Map)
3488
+ fail$$1("Cannot initialize from classes that inherit from Map: " + other.constructor.name); // prettier-ignore
3389
3489
  other.forEach(function (value, key) { return _this.set(key, value); });
3490
+ }
3390
3491
  else if (other !== null && other !== undefined)
3391
3492
  fail$$1("Cannot initialize map from " + other);
3392
3493
  });
@@ -3446,7 +3547,8 @@ var ObservableMap$$1 = /** @class */ (function () {
3446
3547
  try {
3447
3548
  for (var _b = __values(this), _c = _b.next(); !_c.done; _c = _b.next()) {
3448
3549
  var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
3449
- res["" + key] = value;
3550
+ // We lie about symbol key types due to https://github.com/Microsoft/TypeScript/issues/1863
3551
+ res[typeof key === "symbol" ? key : stringifyKey(key)] = value;
3450
3552
  }
3451
3553
  }
3452
3554
  catch (e_3_1) { e_3 = { error: e_3_1 }; }
@@ -3474,7 +3576,7 @@ var ObservableMap$$1 = /** @class */ (function () {
3474
3576
  return (this.name +
3475
3577
  "[{ " +
3476
3578
  Array.from(this.keys())
3477
- .map(function (key) { return key + ": " + ("" + _this.get(key)); })
3579
+ .map(function (key) { return stringifyKey(key) + ": " + ("" + _this.get(key)); })
3478
3580
  .join(", ") +
3479
3581
  " }]");
3480
3582
  };
@@ -3493,9 +3595,233 @@ var ObservableMap$$1 = /** @class */ (function () {
3493
3595
  };
3494
3596
  return ObservableMap$$1;
3495
3597
  }());
3598
+ function stringifyKey(key) {
3599
+ if (key && key.toString)
3600
+ return key.toString();
3601
+ else
3602
+ return new String(key).toString();
3603
+ }
3496
3604
  /* 'var' fixes small-build issue */
3497
3605
  var isObservableMap$$1 = createInstanceofPredicate$$1("ObservableMap", ObservableMap$$1);
3498
3606
 
3607
+ var _a$1;
3608
+ var ObservableSetMarker = {};
3609
+ var ObservableSet$$1 = /** @class */ (function () {
3610
+ function ObservableSet$$1(initialData, enhancer, name) {
3611
+ if (enhancer === void 0) { enhancer = deepEnhancer$$1; }
3612
+ if (name === void 0) { name = "ObservableSet@" + getNextId$$1(); }
3613
+ this.name = name;
3614
+ this[_a$1] = ObservableSetMarker;
3615
+ this._data = new Set();
3616
+ this._atom = createAtom$$1(this.name);
3617
+ this[Symbol.toStringTag] = "Set";
3618
+ if (typeof Set !== "function") {
3619
+ throw new Error("mobx.set requires Set polyfill for the current browser. Check babel-polyfill or core-js/es6/set.js");
3620
+ }
3621
+ this.enhancer = function (newV, oldV) { return enhancer(newV, oldV, name); };
3622
+ if (initialData) {
3623
+ this.replace(initialData);
3624
+ }
3625
+ }
3626
+ ObservableSet$$1.prototype.dehanceValue = function (value) {
3627
+ if (this.dehancer !== undefined) {
3628
+ return this.dehancer(value);
3629
+ }
3630
+ return value;
3631
+ };
3632
+ ObservableSet$$1.prototype.clear = function () {
3633
+ var _this = this;
3634
+ transaction$$1(function () {
3635
+ untracked$$1(function () {
3636
+ var e_1, _a;
3637
+ try {
3638
+ for (var _b = __values(_this._data.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
3639
+ var value = _c.value;
3640
+ _this.delete(value);
3641
+ }
3642
+ }
3643
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
3644
+ finally {
3645
+ try {
3646
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
3647
+ }
3648
+ finally { if (e_1) throw e_1.error; }
3649
+ }
3650
+ });
3651
+ });
3652
+ };
3653
+ ObservableSet$$1.prototype.forEach = function (callbackFn, thisArg) {
3654
+ var e_2, _a;
3655
+ try {
3656
+ for (var _b = __values(this), _c = _b.next(); !_c.done; _c = _b.next()) {
3657
+ var value = _c.value;
3658
+ callbackFn.call(thisArg, value, value, this);
3659
+ }
3660
+ }
3661
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
3662
+ finally {
3663
+ try {
3664
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
3665
+ }
3666
+ finally { if (e_2) throw e_2.error; }
3667
+ }
3668
+ };
3669
+ Object.defineProperty(ObservableSet$$1.prototype, "size", {
3670
+ get: function () {
3671
+ this._atom.reportObserved();
3672
+ return this._data.size;
3673
+ },
3674
+ enumerable: true,
3675
+ configurable: true
3676
+ });
3677
+ ObservableSet$$1.prototype.add = function (value) {
3678
+ var _this = this;
3679
+ checkIfStateModificationsAreAllowed$$1(this._atom);
3680
+ if (hasInterceptors$$1(this)) {
3681
+ var change = interceptChange$$1(this, {
3682
+ type: "add",
3683
+ object: this,
3684
+ newValue: value
3685
+ });
3686
+ if (!change)
3687
+ return this;
3688
+ // TODO: ideally, value = change.value would be done here, so that values can be
3689
+ // changed by interceptor. Same applies for other Set and Map api's.
3690
+ }
3691
+ if (!this.has(value)) {
3692
+ transaction$$1(function () {
3693
+ _this._data.add(_this.enhancer(value, undefined));
3694
+ _this._atom.reportChanged();
3695
+ });
3696
+ var notifySpy = isSpyEnabled$$1();
3697
+ var notify = hasListeners$$1(this);
3698
+ var change = notify || notifySpy
3699
+ ? {
3700
+ type: "add",
3701
+ object: this,
3702
+ newValue: value
3703
+ }
3704
+ : null;
3705
+ if (notifySpy && process.env.NODE_ENV !== "production")
3706
+ spyReportStart$$1(change);
3707
+ if (notify)
3708
+ notifyListeners$$1(this, change);
3709
+ if (notifySpy && process.env.NODE_ENV !== "production")
3710
+ spyReportEnd$$1();
3711
+ }
3712
+ return this;
3713
+ };
3714
+ ObservableSet$$1.prototype.delete = function (value) {
3715
+ var _this = this;
3716
+ if (hasInterceptors$$1(this)) {
3717
+ var change = interceptChange$$1(this, {
3718
+ type: "delete",
3719
+ object: this,
3720
+ oldValue: value
3721
+ });
3722
+ if (!change)
3723
+ return false;
3724
+ }
3725
+ if (this.has(value)) {
3726
+ var notifySpy = isSpyEnabled$$1();
3727
+ var notify = hasListeners$$1(this);
3728
+ var change = notify || notifySpy
3729
+ ? {
3730
+ type: "delete",
3731
+ object: this,
3732
+ oldValue: value
3733
+ }
3734
+ : null;
3735
+ if (notifySpy && process.env.NODE_ENV !== "production")
3736
+ spyReportStart$$1(__assign({}, change, { name: this.name }));
3737
+ transaction$$1(function () {
3738
+ _this._atom.reportChanged();
3739
+ _this._data.delete(value);
3740
+ });
3741
+ if (notify)
3742
+ notifyListeners$$1(this, change);
3743
+ if (notifySpy && process.env.NODE_ENV !== "production")
3744
+ spyReportEnd$$1();
3745
+ return true;
3746
+ }
3747
+ return false;
3748
+ };
3749
+ ObservableSet$$1.prototype.has = function (value) {
3750
+ this._atom.reportObserved();
3751
+ return this._data.has(this.dehanceValue(value));
3752
+ };
3753
+ ObservableSet$$1.prototype.entries = function () {
3754
+ var nextIndex = 0;
3755
+ var keys$$1 = Array.from(this.keys());
3756
+ var values$$1 = Array.from(this.values());
3757
+ return makeIterable({
3758
+ next: function () {
3759
+ var index = nextIndex;
3760
+ nextIndex += 1;
3761
+ return index < values$$1.length
3762
+ ? { value: [keys$$1[index], values$$1[index]], done: false }
3763
+ : { done: true };
3764
+ }
3765
+ });
3766
+ };
3767
+ ObservableSet$$1.prototype.keys = function () {
3768
+ return this.values();
3769
+ };
3770
+ ObservableSet$$1.prototype.values = function () {
3771
+ this._atom.reportObserved();
3772
+ var self = this;
3773
+ var nextIndex = 0;
3774
+ var observableValues = Array.from(this._data.values());
3775
+ return makeIterable({
3776
+ next: function () {
3777
+ return nextIndex < observableValues.length
3778
+ ? { value: self.dehanceValue(observableValues[nextIndex++]), done: false }
3779
+ : { done: true };
3780
+ }
3781
+ });
3782
+ };
3783
+ ObservableSet$$1.prototype.replace = function (other) {
3784
+ var _this = this;
3785
+ if (isObservableSet$$1(other)) {
3786
+ other = other.toJS();
3787
+ }
3788
+ transaction$$1(function () {
3789
+ if (Array.isArray(other)) {
3790
+ _this.clear();
3791
+ other.forEach(function (value) { return _this.add(value); });
3792
+ }
3793
+ else if (isES6Set$$1(other)) {
3794
+ _this.clear();
3795
+ other.forEach(function (value) { return _this.add(value); });
3796
+ }
3797
+ else if (other !== null && other !== undefined) {
3798
+ fail$$1("Cannot initialize set from " + other);
3799
+ }
3800
+ });
3801
+ return this;
3802
+ };
3803
+ ObservableSet$$1.prototype.observe = function (listener, fireImmediately) {
3804
+ // TODO 'fireImmediately' can be true?
3805
+ process.env.NODE_ENV !== "production" &&
3806
+ invariant$$1(fireImmediately !== true, "`observe` doesn't support fireImmediately=true in combination with sets.");
3807
+ return registerListener$$1(this, listener);
3808
+ };
3809
+ ObservableSet$$1.prototype.intercept = function (handler) {
3810
+ return registerInterceptor$$1(this, handler);
3811
+ };
3812
+ ObservableSet$$1.prototype.toJS = function () {
3813
+ return new Set(this);
3814
+ };
3815
+ ObservableSet$$1.prototype.toString = function () {
3816
+ return this.name + "[ " + Array.from(this).join(", ") + " ]";
3817
+ };
3818
+ ObservableSet$$1.prototype[(_a$1 = $mobx$$1, Symbol.iterator)] = function () {
3819
+ return this.values();
3820
+ };
3821
+ return ObservableSet$$1;
3822
+ }());
3823
+ var isObservableSet$$1 = createInstanceofPredicate$$1("ObservableSet", ObservableSet$$1);
3824
+
3499
3825
  var ObservableObjectAdministration$$1 = /** @class */ (function () {
3500
3826
  function ObservableObjectAdministration$$1(target, values$$1, name, defaultEnhancer) {
3501
3827
  if (values$$1 === void 0) { values$$1 = new Map(); }
@@ -3767,7 +4093,7 @@ function getAdministrationForComputedPropOwner(owner) {
3767
4093
  function generateComputedPropConfig$$1(propName) {
3768
4094
  return (computedPropertyConfigs[propName] ||
3769
4095
  (computedPropertyConfigs[propName] = {
3770
- configurable: true,
4096
+ configurable: false,
3771
4097
  enumerable: false,
3772
4098
  get: function () {
3773
4099
  return getAdministrationForComputedPropOwner(this).read(propName);
@@ -3795,6 +4121,9 @@ function getAtom$$1(thing, property) {
3795
4121
  "It is not possible to get index atoms from arrays");
3796
4122
  return thing[$mobx$$1].atom;
3797
4123
  }
4124
+ if (isObservableSet$$1(thing)) {
4125
+ return thing[$mobx$$1];
4126
+ }
3798
4127
  if (isObservableMap$$1(thing)) {
3799
4128
  var anyThing = thing;
3800
4129
  if (property === undefined)
@@ -3837,7 +4166,7 @@ function getAdministration$$1(thing, property) {
3837
4166
  return getAdministration$$1(getAtom$$1(thing, property));
3838
4167
  if (isAtom$$1(thing) || isComputedValue$$1(thing) || isReaction$$1(thing))
3839
4168
  return thing;
3840
- if (isObservableMap$$1(thing))
4169
+ if (isObservableMap$$1(thing) || isObservableSet$$1(thing))
3841
4170
  return thing;
3842
4171
  // Initializers run lazily when transpiling to babel, so make sure they are run...
3843
4172
  initializeInstance$$1(thing);
@@ -3849,7 +4178,7 @@ function getDebugName$$1(thing, property) {
3849
4178
  var named;
3850
4179
  if (property !== undefined)
3851
4180
  named = getAtom$$1(thing, property);
3852
- else if (isObservableObject$$1(thing) || isObservableMap$$1(thing))
4181
+ else if (isObservableObject$$1(thing) || isObservableMap$$1(thing) || isObservableSet$$1(thing))
3853
4182
  named = getAdministration$$1(thing);
3854
4183
  else
3855
4184
  named = getAtom$$1(thing); // valid for arrays as well
@@ -3958,7 +4287,8 @@ function deepEq(a, b, aStack, bStack) {
3958
4287
  }
3959
4288
  else {
3960
4289
  // Deep compare objects.
3961
- var keys$$1 = Object.keys(a), key;
4290
+ var keys$$1 = Object.keys(a);
4291
+ var key = void 0;
3962
4292
  length = keys$$1.length;
3963
4293
  // Ensure that both objects contain the same number of properties before comparing deep equality.
3964
4294
  if (Object.keys(b).length !== length)
@@ -3980,6 +4310,8 @@ function unwrap(a) {
3980
4310
  return a.slice();
3981
4311
  if (isES6Map$$1(a) || isObservableMap$$1(a))
3982
4312
  return Array.from(a.entries());
4313
+ if (isES6Set$$1(a) || isObservableSet$$1(a))
4314
+ return Array.from(a.entries());
3983
4315
  return a;
3984
4316
  }
3985
4317
  function has$1(a, key) {
@@ -4020,7 +4352,7 @@ but at least in this file we can magically reorder the imports with trial and er
4020
4352
  *
4021
4353
  */
4022
4354
  if (typeof Proxy === "undefined" || typeof Symbol === "undefined") {
4023
- 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.");
4355
+ 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.");
4024
4356
  }
4025
4357
  try {
4026
4358
  // define process.env if needed
@@ -4038,7 +4370,8 @@ catch (e) {
4038
4370
  (function () {
4039
4371
  function testCodeMinification() { }
4040
4372
  if (testCodeMinification.name !== "testCodeMinification" &&
4041
- process.env.NODE_ENV !== "production") {
4373
+ process.env.NODE_ENV !== "production" &&
4374
+ process.env.IGNORE_MOBX_MINIFY_WARNING !== "true") {
4042
4375
  console.warn(
4043
4376
  // Template literal(backtick) is used for fix issue with rollup-plugin-commonjs https://github.com/rollup/rollup-plugin-commonjs/issues/344
4044
4377
  "[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");
@@ -4066,6 +4399,8 @@ exports.isBoxedObservable = isObservableValue$$1;
4066
4399
  exports.isObservableArray = isObservableArray$$1;
4067
4400
  exports.ObservableMap = ObservableMap$$1;
4068
4401
  exports.isObservableMap = isObservableMap$$1;
4402
+ exports.ObservableSet = ObservableSet$$1;
4403
+ exports.isObservableSet = isObservableSet$$1;
4069
4404
  exports.transaction = transaction$$1;
4070
4405
  exports.observable = observable$$1;
4071
4406
  exports.computed = computed$$1;