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.es6.js CHANGED
@@ -103,6 +103,9 @@ function isArrayLike$$1(x) {
103
103
  function isES6Map$$1(thing) {
104
104
  return thing instanceof Map;
105
105
  }
106
+ function isES6Set$$1(thing) {
107
+ return thing instanceof Set;
108
+ }
106
109
  function getMapLikeKeys$$1(map) {
107
110
  if (isPlainObject$$1(map))
108
111
  return Object.keys(map);
@@ -131,11 +134,15 @@ class Atom$$1 {
131
134
  this.lastAccessedBy = 0;
132
135
  this.lowestObserverState = IDerivationState.NOT_TRACKING;
133
136
  }
134
- onBecomeUnobserved() {
135
- // noop
136
- }
137
137
  onBecomeObserved() {
138
- /* noop */
138
+ if (this.onBecomeObservedListeners) {
139
+ this.onBecomeObservedListeners.forEach(listener => listener());
140
+ }
141
+ }
142
+ onBecomeUnobserved() {
143
+ if (this.onBecomeUnobservedListeners) {
144
+ this.onBecomeUnobservedListeners.forEach(listener => listener());
145
+ }
139
146
  }
140
147
  /**
141
148
  * Invoke this method to notify mobx that your atom has been used somehow.
@@ -159,8 +166,13 @@ class Atom$$1 {
159
166
  const isAtom$$1 = createInstanceofPredicate$$1("Atom", Atom$$1);
160
167
  function createAtom$$1(name, onBecomeObservedHandler = noop$$1, onBecomeUnobservedHandler = noop$$1) {
161
168
  const atom = new Atom$$1(name);
162
- onBecomeObserved$$1(atom, onBecomeObservedHandler);
163
- onBecomeUnobserved$$1(atom, onBecomeUnobservedHandler);
169
+ // default `noop` listener will not initialize the hook Set
170
+ if (onBecomeObservedHandler !== noop$$1) {
171
+ onBecomeObserved$$1(atom, onBecomeObservedHandler);
172
+ }
173
+ if (onBecomeUnobservedHandler !== noop$$1) {
174
+ onBecomeUnobserved$$1(atom, onBecomeUnobservedHandler);
175
+ }
164
176
  return atom;
165
177
  }
166
178
 
@@ -265,12 +277,14 @@ function deepEnhancer$$1(v, _, name) {
265
277
  return observable$$1.object(v, undefined, { name });
266
278
  if (isES6Map$$1(v))
267
279
  return observable$$1.map(v, { name });
280
+ if (isES6Set$$1(v))
281
+ return observable$$1.set(v, { name });
268
282
  return v;
269
283
  }
270
284
  function shallowEnhancer$$1(v, _, name) {
271
285
  if (v === undefined || v === null)
272
286
  return v;
273
- if (isObservableObject$$1(v) || isObservableArray$$1(v) || isObservableMap$$1(v))
287
+ if (isObservableObject$$1(v) || isObservableArray$$1(v) || isObservableMap$$1(v) || isObservableSet$$1(v))
274
288
  return v;
275
289
  if (Array.isArray(v))
276
290
  return observable$$1.array(v, { name, deep: false });
@@ -278,8 +292,10 @@ function shallowEnhancer$$1(v, _, name) {
278
292
  return observable$$1.object(v, undefined, { name, deep: false });
279
293
  if (isES6Map$$1(v))
280
294
  return observable$$1.map(v, { name, deep: false });
295
+ if (isES6Set$$1(v))
296
+ return observable$$1.set(v, { name, deep: false });
281
297
  return fail$$1(process.env.NODE_ENV !== "production" &&
282
- "The shallow modifier / decorator can only used in combination with arrays, objects and maps");
298
+ "The shallow modifier / decorator can only used in combination with arrays, objects, maps and sets");
283
299
  }
284
300
  function referenceEnhancer$$1(newValue) {
285
301
  // never turn into an observable
@@ -331,7 +347,7 @@ const defaultCreateObservableOptions$$1 = {
331
347
  };
332
348
  Object.freeze(defaultCreateObservableOptions$$1);
333
349
  function assertValidOption(key) {
334
- if (!/^(deep|name|defaultDecorator|proxy)$/.test(key))
350
+ if (!/^(deep|name|equals|defaultDecorator|proxy)$/.test(key))
335
351
  fail$$1(`invalid option for (extend)observable: ${key}`);
336
352
  }
337
353
  function asCreateObservableOptions$$1(thing) {
@@ -376,7 +392,9 @@ function createObservable(v, arg2, arg3) {
376
392
  ? observable$$1.array(v, arg2)
377
393
  : isES6Map$$1(v)
378
394
  ? observable$$1.map(v, arg2)
379
- : v;
395
+ : isES6Set$$1(v)
396
+ ? observable$$1.set(v, arg2)
397
+ : v;
380
398
  // this value could be converted to a new observable data structure, return it
381
399
  if (res !== v)
382
400
  return res;
@@ -389,7 +407,7 @@ const observableFactories = {
389
407
  if (arguments.length > 2)
390
408
  incorrectlyUsedAsDecorator("box");
391
409
  const o = asCreateObservableOptions$$1(options);
392
- return new ObservableValue$$1(value, getEnhancerFromOptions(o), o.name);
410
+ return new ObservableValue$$1(value, getEnhancerFromOptions(o), o.name, true, o.equals);
393
411
  },
394
412
  array(initialValues, options) {
395
413
  if (arguments.length > 2)
@@ -403,6 +421,12 @@ const observableFactories = {
403
421
  const o = asCreateObservableOptions$$1(options);
404
422
  return new ObservableMap$$1(initialValues, getEnhancerFromOptions(o), o.name);
405
423
  },
424
+ set(initialValues, options) {
425
+ if (arguments.length > 2)
426
+ incorrectlyUsedAsDecorator("set");
427
+ const o = asCreateObservableOptions$$1(options);
428
+ return new ObservableSet$$1(initialValues, getEnhancerFromOptions(o), o.name);
429
+ },
406
430
  object(props, decorators, options) {
407
431
  if (typeof arguments[1] === "string")
408
432
  incorrectlyUsedAsDecorator("object");
@@ -436,8 +460,9 @@ const computedDecorator$$1 = createPropDecorator$$1(false, (instance, propertyNa
436
460
  const { get: get$$1, set: set$$1 } = descriptor; // initialValue is the descriptor for get / set props
437
461
  // Optimization: faster on decorator target or instance? Assuming target
438
462
  // Optimization: find out if declaring on instance isn't just faster. (also makes the property descriptor simpler). But, more memory usage..
463
+ // Forcing instance now, fixes hot reloadig issues on React Native:
439
464
  const options = decoratorArgs[0] || {};
440
- asObservableObject$$1(instance).addComputedProp(decoratorTarget, propertyName, Object.assign({ get: get$$1,
465
+ asObservableObject$$1(instance).addComputedProp(instance, propertyName, Object.assign({ get: get$$1,
441
466
  set: set$$1, context: instance }, options));
442
467
  });
443
468
  const computedStructDecorator = computedDecorator$$1({ equals: comparer$$1.structural });
@@ -481,11 +506,21 @@ function createAction$$1(actionName, fn) {
481
506
  }
482
507
  function executeAction$$1(actionName, fn, scope, args) {
483
508
  const runInfo = startAction(actionName, fn, scope, args);
509
+ let shouldSupressReactionError = true;
484
510
  try {
485
- return fn.apply(scope, args);
511
+ const res = fn.apply(scope, args);
512
+ shouldSupressReactionError = false;
513
+ return res;
486
514
  }
487
515
  finally {
488
- endAction(runInfo);
516
+ if (shouldSupressReactionError) {
517
+ globalState$$1.suppressReactionErrors = shouldSupressReactionError;
518
+ endAction(runInfo);
519
+ globalState$$1.suppressReactionErrors = false;
520
+ }
521
+ else {
522
+ endAction(runInfo);
523
+ }
489
524
  }
490
525
  }
491
526
  function startAction(actionName, fn, scope, args) {
@@ -554,11 +589,12 @@ function allowStateChangesInsideComputed$$1(func) {
554
589
  return res;
555
590
  }
556
591
 
557
- const UNCHANGED$$1 = {};
558
592
  class ObservableValue$$1 extends Atom$$1 {
559
- constructor(value, enhancer, name = "ObservableValue@" + getNextId$$1(), notifySpy = true) {
593
+ constructor(value, enhancer, name = "ObservableValue@" + getNextId$$1(), notifySpy = true, equals = comparer$$1.default) {
560
594
  super(name);
561
595
  this.enhancer = enhancer;
596
+ this.name = name;
597
+ this.equals = equals;
562
598
  this.hasUnreportedChange = false;
563
599
  this.value = enhancer(value, undefined, name);
564
600
  if (notifySpy && isSpyEnabled$$1() && process.env.NODE_ENV !== "production") {
@@ -574,7 +610,7 @@ class ObservableValue$$1 extends Atom$$1 {
574
610
  set(newValue) {
575
611
  const oldValue = this.value;
576
612
  newValue = this.prepareNewValue(newValue);
577
- if (newValue !== UNCHANGED$$1) {
613
+ if (newValue !== globalState$$1.UNCHANGED) {
578
614
  const notifySpy = isSpyEnabled$$1();
579
615
  if (notifySpy && process.env.NODE_ENV !== "production") {
580
616
  spyReportStart$$1({
@@ -598,12 +634,12 @@ class ObservableValue$$1 extends Atom$$1 {
598
634
  newValue
599
635
  });
600
636
  if (!change)
601
- return UNCHANGED$$1;
637
+ return globalState$$1.UNCHANGED;
602
638
  newValue = change.newValue;
603
639
  }
604
640
  // apply modifier
605
641
  newValue = this.enhancer(newValue, this.value, this.name);
606
- return this.value !== newValue ? newValue : UNCHANGED$$1;
642
+ return this.equals(this.value, newValue) ? globalState$$1.UNCHANGED : newValue;
607
643
  }
608
644
  setNewValue(newValue) {
609
645
  const oldValue = this.value;
@@ -699,7 +735,6 @@ class ComputedValue$$1 {
699
735
  this.isComputing = false; // to check for cycles
700
736
  this.isRunningSetter = false;
701
737
  this.isTracing = TraceMode$$1.NONE;
702
- this.firstGet = true;
703
738
  if (process.env.NODE_ENV !== "production" && !options.get)
704
739
  throw "[mobx] missing option for computed: get";
705
740
  this.derivation = options.get;
@@ -718,20 +753,24 @@ class ComputedValue$$1 {
718
753
  onBecomeStale() {
719
754
  propagateMaybeChanged$$1(this);
720
755
  }
721
- onBecomeUnobserved() { }
722
- onBecomeObserved() { }
756
+ onBecomeObserved() {
757
+ if (this.onBecomeObservedListeners) {
758
+ this.onBecomeObservedListeners.forEach(listener => listener());
759
+ }
760
+ }
761
+ onBecomeUnobserved() {
762
+ if (this.onBecomeUnobservedListeners) {
763
+ this.onBecomeUnobservedListeners.forEach(listener => listener());
764
+ }
765
+ }
723
766
  /**
724
767
  * Returns the current value of this computed value.
725
768
  * Will evaluate its computation first if needed.
726
769
  */
727
770
  get() {
728
- if (this.keepAlive && this.firstGet) {
729
- this.firstGet = false;
730
- autorun$$1(() => this.get());
731
- }
732
771
  if (this.isComputing)
733
772
  fail$$1(`Cycle detected in computation ${this.name}: ${this.derivation}`);
734
- if (globalState$$1.inBatch === 0 && this.observers.size === 0) {
773
+ if (globalState$$1.inBatch === 0 && this.observers.size === 0 && !this.keepAlive) {
735
774
  if (shouldCompute$$1(this)) {
736
775
  this.warnAboutUntrackedRead();
737
776
  startBatch$$1(); // See perf test 'computed memoization'
@@ -817,8 +856,10 @@ class ComputedValue$$1 {
817
856
  return res;
818
857
  }
819
858
  suspend() {
820
- clearObserving$$1(this);
821
- this.value = undefined; // don't hold on to computed value!
859
+ if (!this.keepAlive) {
860
+ clearObserving$$1(this);
861
+ this.value = undefined; // don't hold on to computed value!
862
+ }
822
863
  }
823
864
  observe(listener, fireImmediately) {
824
865
  let firstTime = true;
@@ -1117,7 +1158,8 @@ const persistentKeys = [
1117
1158
  "enforceActions",
1118
1159
  "computedRequiresReaction",
1119
1160
  "disableErrorBoundaries",
1120
- "runId"
1161
+ "runId",
1162
+ "UNCHANGED"
1121
1163
  ];
1122
1164
  class MobXGlobals$$1 {
1123
1165
  constructor() {
@@ -1130,6 +1172,10 @@ class MobXGlobals$$1 {
1130
1172
  * internal state storage of MobX, and can be the same across many different package versions
1131
1173
  */
1132
1174
  this.version = 5;
1175
+ /**
1176
+ * globally unique token to signal unchanged
1177
+ */
1178
+ this.UNCHANGED = {};
1133
1179
  /**
1134
1180
  * Currently running derivation
1135
1181
  */
@@ -1192,6 +1238,11 @@ class MobXGlobals$$1 {
1192
1238
  * the stack when an exception occurs while debugging.
1193
1239
  */
1194
1240
  this.disableErrorBoundaries = false;
1241
+ /*
1242
+ * If true, we are already handling an exception in an action. Any errors in reactions should be supressed, as
1243
+ * they are not the cause, see: https://github.com/mobxjs/mobx/issues/1836
1244
+ */
1245
+ this.suppressReactionErrors = false;
1195
1246
  }
1196
1247
  }
1197
1248
  let canMergeGlobalState = true;
@@ -1212,6 +1263,8 @@ let globalState$$1 = (function () {
1212
1263
  }
1213
1264
  else if (global.__mobxGlobals) {
1214
1265
  global.__mobxInstanceCount += 1;
1266
+ if (!global.__mobxGlobals.UNCHANGED)
1267
+ global.__mobxGlobals.UNCHANGED = {}; // make merge backward compatible
1215
1268
  return global.__mobxGlobals;
1216
1269
  }
1217
1270
  else {
@@ -1441,7 +1494,7 @@ You are entering this break point because derivation '${derivation.name}' is bei
1441
1494
  Just follow the stacktrace you should now see in the devtools to see precisely what piece of your code is causing this update
1442
1495
  The stackframe you are looking for is at least ~6-8 stack-frames up.
1443
1496
 
1444
- ${derivation instanceof ComputedValue$$1 ? derivation.derivation.toString() : ""}
1497
+ ${derivation instanceof ComputedValue$$1 ? derivation.derivation.toString().replace(/[*]\//g, "/") : ""}
1445
1498
 
1446
1499
  The dependencies for this derivation are:
1447
1500
 
@@ -1554,9 +1607,14 @@ class Reaction$$1 {
1554
1607
  }
1555
1608
  if (globalState$$1.disableErrorBoundaries)
1556
1609
  throw error;
1557
- const message = `[mobx] Encountered an uncaught exception that was thrown by a reaction or observer component, in: '${this}`;
1558
- console.error(message, error);
1559
- /** If debugging brought you here, please, read the above message :-). Tnx! */
1610
+ const message = `[mobx] Encountered an uncaught exception that was thrown by a reaction or observer component, in: '${this}'`;
1611
+ if (globalState$$1.suppressReactionErrors) {
1612
+ console.warn(`[mobx] (error in reaction '${this.name}' suppressed, fix error of causing action below)`); // prettier-ignore
1613
+ }
1614
+ else {
1615
+ console.error(message, error);
1616
+ /** If debugging brought you here, please, read the above message :-). Tnx! */
1617
+ }
1560
1618
  if (isSpyEnabled$$1()) {
1561
1619
  spyReport$$1({
1562
1620
  type: "error",
@@ -1909,20 +1967,32 @@ function onBecomeUnobserved$$1(thing, arg2, arg3) {
1909
1967
  function interceptHook(hook, thing, arg2, arg3) {
1910
1968
  const atom = typeof arg2 === "string" ? getAtom$$1(thing, arg2) : getAtom$$1(thing);
1911
1969
  const cb = typeof arg2 === "string" ? arg3 : arg2;
1970
+ const listenersKey = `${hook}Listeners`;
1971
+ if (atom[listenersKey]) {
1972
+ atom[listenersKey].add(cb);
1973
+ }
1974
+ else {
1975
+ atom[listenersKey] = new Set([cb]);
1976
+ }
1912
1977
  const orig = atom[hook];
1913
1978
  if (typeof orig !== "function")
1914
1979
  return fail$$1(process.env.NODE_ENV !== "production" && "Not an atom that can be (un)observed");
1915
- atom[hook] = function () {
1916
- orig.call(this);
1917
- cb.call(this);
1918
- };
1919
1980
  return function () {
1920
- atom[hook] = orig;
1981
+ const hookListeners = atom[listenersKey];
1982
+ if (hookListeners) {
1983
+ hookListeners.delete(cb);
1984
+ if (hookListeners.size === 0) {
1985
+ delete atom[listenersKey];
1986
+ }
1987
+ }
1921
1988
  };
1922
1989
  }
1923
1990
 
1924
1991
  function configure$$1(options) {
1925
1992
  const { enforceActions, computedRequiresReaction, disableErrorBoundaries, reactionScheduler } = options;
1993
+ if (options.isolateGlobalState === true) {
1994
+ isolateGlobalState$$1();
1995
+ }
1926
1996
  if (enforceActions !== undefined) {
1927
1997
  if (typeof enforceActions === "boolean" || enforceActions === "strict")
1928
1998
  deprecated$$1(`Deprecated value for 'enforceActions', use 'false' => '"never"', 'true' => '"observed"', '"strict"' => "'always'" instead`);
@@ -1949,9 +2019,6 @@ function configure$$1(options) {
1949
2019
  if (computedRequiresReaction !== undefined) {
1950
2020
  globalState$$1.computedRequiresReaction = !!computedRequiresReaction;
1951
2021
  }
1952
- if (options.isolateGlobalState === true) {
1953
- isolateGlobalState$$1();
1954
- }
1955
2022
  if (disableErrorBoundaries !== undefined) {
1956
2023
  if (disableErrorBoundaries === true)
1957
2024
  console.warn("WARNING: Debug feature only. MobX will NOT recover from errors when `disableErrorBoundaries` is enabled.");
@@ -2070,7 +2137,7 @@ function flow$$1(generator) {
2070
2137
  const gen = action$$1(`${name} - runid: ${runId} - init`, generator).apply(ctx, args);
2071
2138
  let rejector;
2072
2139
  let pendingPromise = undefined;
2073
- const res = new Promise(function (resolve, reject) {
2140
+ const promise = new Promise(function (resolve, reject) {
2074
2141
  let stepId = 0;
2075
2142
  rejector = reject;
2076
2143
  function onFulfilled(res) {
@@ -2108,7 +2175,7 @@ function flow$$1(generator) {
2108
2175
  }
2109
2176
  onFulfilled(undefined); // kick off the process
2110
2177
  });
2111
- res.cancel = action$$1(`${name} - runid: ${runId} - cancel`, function () {
2178
+ promise.cancel = action$$1(`${name} - runid: ${runId} - cancel`, function () {
2112
2179
  try {
2113
2180
  if (pendingPromise)
2114
2181
  cancelPromise(pendingPromise);
@@ -2125,7 +2192,7 @@ function flow$$1(generator) {
2125
2192
  rejector(e); // there could be a throwing finally block
2126
2193
  }
2127
2194
  });
2128
- return res;
2195
+ return promise;
2129
2196
  };
2130
2197
  }
2131
2198
  function cancelPromise(promise) {
@@ -2233,11 +2300,14 @@ function keys$$1(obj) {
2233
2300
  if (isObservableMap$$1(obj)) {
2234
2301
  return Array.from(obj.keys());
2235
2302
  }
2303
+ if (isObservableSet$$1(obj)) {
2304
+ return Array.from(obj.keys());
2305
+ }
2236
2306
  if (isObservableArray$$1(obj)) {
2237
2307
  return obj.map((_, index) => index);
2238
2308
  }
2239
2309
  return fail$$1(process.env.NODE_ENV !== "production" &&
2240
- "'keys()' can only be used on observable objects, arrays and maps");
2310
+ "'keys()' can only be used on observable objects, arrays, sets and maps");
2241
2311
  }
2242
2312
  function values$$1(obj) {
2243
2313
  if (isObservableObject$$1(obj)) {
@@ -2246,11 +2316,14 @@ function values$$1(obj) {
2246
2316
  if (isObservableMap$$1(obj)) {
2247
2317
  return keys$$1(obj).map(key => obj.get(key));
2248
2318
  }
2319
+ if (isObservableSet$$1(obj)) {
2320
+ return Array.from(obj.values());
2321
+ }
2249
2322
  if (isObservableArray$$1(obj)) {
2250
2323
  return obj.slice();
2251
2324
  }
2252
2325
  return fail$$1(process.env.NODE_ENV !== "production" &&
2253
- "'values()' can only be used on observable objects, arrays and maps");
2326
+ "'values()' can only be used on observable objects, arrays, sets and maps");
2254
2327
  }
2255
2328
  function entries$$1(obj) {
2256
2329
  if (isObservableObject$$1(obj)) {
@@ -2259,6 +2332,9 @@ function entries$$1(obj) {
2259
2332
  if (isObservableMap$$1(obj)) {
2260
2333
  return keys$$1(obj).map(key => [key, obj.get(key)]);
2261
2334
  }
2335
+ if (isObservableSet$$1(obj)) {
2336
+ return Array.from(obj.entries());
2337
+ }
2262
2338
  if (isObservableArray$$1(obj)) {
2263
2339
  return obj.map((key, index) => [index, key]);
2264
2340
  }
@@ -2314,6 +2390,9 @@ function remove$$1(obj, key) {
2314
2390
  else if (isObservableMap$$1(obj)) {
2315
2391
  obj.delete(key);
2316
2392
  }
2393
+ else if (isObservableSet$$1(obj)) {
2394
+ obj.delete(key);
2395
+ }
2317
2396
  else if (isObservableArray$$1(obj)) {
2318
2397
  if (typeof key !== "number")
2319
2398
  key = parseInt(key, 10);
@@ -2334,6 +2413,9 @@ function has$$1(obj, key) {
2334
2413
  else if (isObservableMap$$1(obj)) {
2335
2414
  return obj.has(key);
2336
2415
  }
2416
+ else if (isObservableSet$$1(obj)) {
2417
+ return obj.has(key);
2418
+ }
2337
2419
  else if (isObservableArray$$1(obj)) {
2338
2420
  return key >= 0 && key < obj.length;
2339
2421
  }
@@ -2411,6 +2493,22 @@ function toJSHelper(source, options, __alreadySeen) {
2411
2493
  res[i] = toAdd[i];
2412
2494
  return res;
2413
2495
  }
2496
+ if (isObservableSet$$1(source) || Object.getPrototypeOf(source) === Set.prototype) {
2497
+ if (options.exportMapsAsObjects === false) {
2498
+ const res = cache(__alreadySeen, source, new Set(), options);
2499
+ source.forEach(value => {
2500
+ res.add(toJSHelper(value, options, __alreadySeen));
2501
+ });
2502
+ return res;
2503
+ }
2504
+ else {
2505
+ const res = cache(__alreadySeen, source, [], options);
2506
+ source.forEach(value => {
2507
+ res.push(toJSHelper(value, options, __alreadySeen));
2508
+ });
2509
+ return res;
2510
+ }
2511
+ }
2414
2512
  if (isObservableMap$$1(source) || Object.getPrototypeOf(source) === Map.prototype) {
2415
2513
  if (options.exportMapsAsObjects === false) {
2416
2514
  const res = cache(__alreadySeen, source, new Map(), options);
@@ -2560,8 +2658,16 @@ const objectProxyTraps = {
2560
2658
  return target[name];
2561
2659
  const adm = getAdm(target);
2562
2660
  const observable$$1 = adm.values.get(name);
2563
- if (observable$$1 instanceof Atom$$1)
2564
- return observable$$1.get();
2661
+ if (observable$$1 instanceof Atom$$1) {
2662
+ const result = observable$$1.get();
2663
+ if (result === undefined) {
2664
+ // This fixes #1796, because deleting a prop that has an
2665
+ // undefined value won't retrigger a observer (no visible effect),
2666
+ // the autorun wouldn't subscribe to future key changes (see also next comment)
2667
+ adm.has(name);
2668
+ }
2669
+ return result;
2670
+ }
2565
2671
  // make sure we start listening to future keys
2566
2672
  // note that we only do this here for optimization
2567
2673
  if (typeof name === "string")
@@ -2716,7 +2822,7 @@ class ObservableArrayAdministration {
2716
2822
  return value;
2717
2823
  }
2718
2824
  dehanceValues(values$$1) {
2719
- if (this.dehancer !== undefined && this.values.length > 0)
2825
+ if (this.dehancer !== undefined && values$$1.length > 0)
2720
2826
  return values$$1.map(this.dehancer);
2721
2827
  return values$$1;
2722
2828
  }
@@ -3125,7 +3231,7 @@ class ObservableMap$$1 {
3125
3231
  _updateValue(key, newValue) {
3126
3232
  const observable$$1 = this._data.get(key);
3127
3233
  newValue = observable$$1.prepareNewValue(newValue);
3128
- if (newValue !== UNCHANGED$$1) {
3234
+ if (newValue !== globalState$$1.UNCHANGED) {
3129
3235
  const notifySpy = isSpyEnabled$$1();
3130
3236
  const notify = hasListeners$$1(this);
3131
3237
  const change = notify || notifySpy
@@ -3233,8 +3339,11 @@ class ObservableMap$$1 {
3233
3339
  Object.keys(other).forEach(key => this.set(key, other[key]));
3234
3340
  else if (Array.isArray(other))
3235
3341
  other.forEach(([key, value]) => this.set(key, value));
3236
- else if (isES6Map$$1(other))
3342
+ else if (isES6Map$$1(other)) {
3343
+ if (other.constructor !== Map)
3344
+ return fail$$1("Cannot initialize from classes that inherit from Map: " + other.constructor.name); // prettier-ignore
3237
3345
  other.forEach((value, key) => this.set(key, value));
3346
+ }
3238
3347
  else if (other !== null && other !== undefined)
3239
3348
  fail$$1("Cannot initialize map from " + other);
3240
3349
  });
@@ -3313,6 +3422,190 @@ class ObservableMap$$1 {
3313
3422
  /* 'var' fixes small-build issue */
3314
3423
  var isObservableMap$$1 = createInstanceofPredicate$$1("ObservableMap", ObservableMap$$1);
3315
3424
 
3425
+ var _a$1;
3426
+ const ObservableSetMarker = {};
3427
+ class ObservableSet$$1 {
3428
+ constructor(initialData, enhancer = deepEnhancer$$1, name = "ObservableSet@" + getNextId$$1()) {
3429
+ this.name = name;
3430
+ this[_a$1] = ObservableSetMarker;
3431
+ this._data = new Set();
3432
+ this._atom = createAtom$$1(this.name);
3433
+ this[Symbol.toStringTag] = "Set";
3434
+ if (typeof Set !== "function") {
3435
+ throw new Error("mobx.set requires Set polyfill for the current browser. Check babel-polyfill or core-js/es6/set.js");
3436
+ }
3437
+ this.enhancer = (newV, oldV) => enhancer(newV, oldV, name);
3438
+ if (initialData) {
3439
+ this.replace(initialData);
3440
+ }
3441
+ }
3442
+ dehanceValue(value) {
3443
+ if (this.dehancer !== undefined) {
3444
+ return this.dehancer(value);
3445
+ }
3446
+ return value;
3447
+ }
3448
+ clear() {
3449
+ transaction$$1(() => {
3450
+ untracked$$1(() => {
3451
+ for (const value of this._data.values())
3452
+ this.delete(value);
3453
+ });
3454
+ });
3455
+ }
3456
+ forEach(callbackFn, thisArg) {
3457
+ for (const value of this) {
3458
+ callbackFn.call(thisArg, value, value, this);
3459
+ }
3460
+ }
3461
+ get size() {
3462
+ this._atom.reportObserved();
3463
+ return this._data.size;
3464
+ }
3465
+ add(value) {
3466
+ checkIfStateModificationsAreAllowed$$1(this._atom);
3467
+ if (hasInterceptors$$1(this)) {
3468
+ const change = interceptChange$$1(this, {
3469
+ type: "add",
3470
+ object: this,
3471
+ newValue: value
3472
+ });
3473
+ if (!change)
3474
+ return this;
3475
+ // TODO: ideally, value = change.value would be done here, so that values can be
3476
+ // changed by interceptor. Same applies for other Set and Map api's.
3477
+ }
3478
+ if (!this.has(value)) {
3479
+ transaction$$1(() => {
3480
+ this._data.add(this.enhancer(value, undefined));
3481
+ this._atom.reportChanged();
3482
+ });
3483
+ const notifySpy = isSpyEnabled$$1();
3484
+ const notify = hasListeners$$1(this);
3485
+ const change = notify || notifySpy
3486
+ ? {
3487
+ type: "add",
3488
+ object: this,
3489
+ newValue: value
3490
+ }
3491
+ : null;
3492
+ if (notifySpy && process.env.NODE_ENV !== "production")
3493
+ spyReportStart$$1(change);
3494
+ if (notify)
3495
+ notifyListeners$$1(this, change);
3496
+ if (notifySpy && process.env.NODE_ENV !== "production")
3497
+ spyReportEnd$$1();
3498
+ }
3499
+ return this;
3500
+ }
3501
+ delete(value) {
3502
+ if (hasInterceptors$$1(this)) {
3503
+ const change = interceptChange$$1(this, {
3504
+ type: "delete",
3505
+ object: this,
3506
+ oldValue: value
3507
+ });
3508
+ if (!change)
3509
+ return false;
3510
+ }
3511
+ if (this.has(value)) {
3512
+ const notifySpy = isSpyEnabled$$1();
3513
+ const notify = hasListeners$$1(this);
3514
+ const change = notify || notifySpy
3515
+ ? {
3516
+ type: "delete",
3517
+ object: this,
3518
+ oldValue: value
3519
+ }
3520
+ : null;
3521
+ if (notifySpy && process.env.NODE_ENV !== "production")
3522
+ spyReportStart$$1(Object.assign({}, change, { name: this.name }));
3523
+ transaction$$1(() => {
3524
+ this._atom.reportChanged();
3525
+ this._data.delete(value);
3526
+ });
3527
+ if (notify)
3528
+ notifyListeners$$1(this, change);
3529
+ if (notifySpy && process.env.NODE_ENV !== "production")
3530
+ spyReportEnd$$1();
3531
+ return true;
3532
+ }
3533
+ return false;
3534
+ }
3535
+ has(value) {
3536
+ this._atom.reportObserved();
3537
+ return this._data.has(this.dehanceValue(value));
3538
+ }
3539
+ entries() {
3540
+ let nextIndex = 0;
3541
+ const keys$$1 = Array.from(this.keys());
3542
+ const values$$1 = Array.from(this.values());
3543
+ return makeIterable({
3544
+ next() {
3545
+ const index = nextIndex;
3546
+ nextIndex += 1;
3547
+ return index < values$$1.length
3548
+ ? { value: [keys$$1[index], values$$1[index]], done: false }
3549
+ : { done: true };
3550
+ }
3551
+ });
3552
+ }
3553
+ keys() {
3554
+ return this.values();
3555
+ }
3556
+ values() {
3557
+ this._atom.reportObserved();
3558
+ const self = this;
3559
+ let nextIndex = 0;
3560
+ const observableValues = Array.from(this._data.values());
3561
+ return makeIterable({
3562
+ next() {
3563
+ return nextIndex < observableValues.length
3564
+ ? { value: self.dehanceValue(observableValues[nextIndex++]), done: false }
3565
+ : { done: true };
3566
+ }
3567
+ });
3568
+ }
3569
+ replace(other) {
3570
+ if (isObservableSet$$1(other)) {
3571
+ other = other.toJS();
3572
+ }
3573
+ transaction$$1(() => {
3574
+ if (Array.isArray(other)) {
3575
+ this.clear();
3576
+ other.forEach(value => this.add(value));
3577
+ }
3578
+ else if (isES6Set$$1(other)) {
3579
+ this.clear();
3580
+ other.forEach(value => this.add(value));
3581
+ }
3582
+ else if (other !== null && other !== undefined) {
3583
+ fail$$1("Cannot initialize set from " + other);
3584
+ }
3585
+ });
3586
+ return this;
3587
+ }
3588
+ observe(listener, fireImmediately) {
3589
+ // TODO 'fireImmediately' can be true?
3590
+ process.env.NODE_ENV !== "production" &&
3591
+ invariant$$1(fireImmediately !== true, "`observe` doesn't support fireImmediately=true in combination with sets.");
3592
+ return registerListener$$1(this, listener);
3593
+ }
3594
+ intercept(handler) {
3595
+ return registerInterceptor$$1(this, handler);
3596
+ }
3597
+ toJS() {
3598
+ return new Set(this);
3599
+ }
3600
+ toString() {
3601
+ return this.name + "[ " + Array.from(this).join(", ") + " ]";
3602
+ }
3603
+ [(_a$1 = $mobx$$1, Symbol.iterator)]() {
3604
+ return this.values();
3605
+ }
3606
+ }
3607
+ const isObservableSet$$1 = createInstanceofPredicate$$1("ObservableSet", ObservableSet$$1);
3608
+
3316
3609
  class ObservableObjectAdministration$$1 {
3317
3610
  constructor(target, values$$1 = new Map(), name, defaultEnhancer) {
3318
3611
  this.target = target;
@@ -3345,7 +3638,7 @@ class ObservableObjectAdministration$$1 {
3345
3638
  }
3346
3639
  newValue = observable$$1.prepareNewValue(newValue);
3347
3640
  // notify spy & observers
3348
- if (newValue !== UNCHANGED$$1) {
3641
+ if (newValue !== globalState$$1.UNCHANGED) {
3349
3642
  const notify = hasListeners$$1(this);
3350
3643
  const notifySpy = isSpyEnabled$$1();
3351
3644
  const change = notify || notifySpy
@@ -3567,7 +3860,7 @@ function getAdministrationForComputedPropOwner(owner) {
3567
3860
  function generateComputedPropConfig$$1(propName) {
3568
3861
  return (computedPropertyConfigs[propName] ||
3569
3862
  (computedPropertyConfigs[propName] = {
3570
- configurable: true,
3863
+ configurable: false,
3571
3864
  enumerable: false,
3572
3865
  get() {
3573
3866
  return getAdministrationForComputedPropOwner(this).read(propName);
@@ -3595,6 +3888,9 @@ function getAtom$$1(thing, property) {
3595
3888
  "It is not possible to get index atoms from arrays");
3596
3889
  return thing[$mobx$$1].atom;
3597
3890
  }
3891
+ if (isObservableSet$$1(thing)) {
3892
+ return thing[$mobx$$1];
3893
+ }
3598
3894
  if (isObservableMap$$1(thing)) {
3599
3895
  const anyThing = thing;
3600
3896
  if (property === undefined)
@@ -3637,7 +3933,7 @@ function getAdministration$$1(thing, property) {
3637
3933
  return getAdministration$$1(getAtom$$1(thing, property));
3638
3934
  if (isAtom$$1(thing) || isComputedValue$$1(thing) || isReaction$$1(thing))
3639
3935
  return thing;
3640
- if (isObservableMap$$1(thing))
3936
+ if (isObservableMap$$1(thing) || isObservableSet$$1(thing))
3641
3937
  return thing;
3642
3938
  // Initializers run lazily when transpiling to babel, so make sure they are run...
3643
3939
  initializeInstance$$1(thing);
@@ -3649,7 +3945,7 @@ function getDebugName$$1(thing, property) {
3649
3945
  let named;
3650
3946
  if (property !== undefined)
3651
3947
  named = getAtom$$1(thing, property);
3652
- else if (isObservableObject$$1(thing) || isObservableMap$$1(thing))
3948
+ else if (isObservableObject$$1(thing) || isObservableMap$$1(thing) || isObservableSet$$1(thing))
3653
3949
  named = getAdministration$$1(thing);
3654
3950
  else
3655
3951
  named = getAtom$$1(thing); // valid for arrays as well
@@ -3780,6 +4076,8 @@ function unwrap(a) {
3780
4076
  return a.slice();
3781
4077
  if (isES6Map$$1(a) || isObservableMap$$1(a))
3782
4078
  return Array.from(a.entries());
4079
+ if (isES6Set$$1(a) || isObservableSet$$1(a))
4080
+ return Array.from(a.entries());
3783
4081
  return a;
3784
4082
  }
3785
4083
  function has$1(a, key) {
@@ -3829,7 +4127,7 @@ try {
3829
4127
  process.env.NODE_ENV;
3830
4128
  }
3831
4129
  catch (e) {
3832
- var g = typeof window !== "undefined" ? window : global;
4130
+ const g = typeof window !== "undefined" ? window : global;
3833
4131
  if (typeof process === "undefined")
3834
4132
  g.process = {};
3835
4133
  g.process.env = {};
@@ -3838,7 +4136,8 @@ catch (e) {
3838
4136
  (() => {
3839
4137
  function testCodeMinification() { }
3840
4138
  if (testCodeMinification.name !== "testCodeMinification" &&
3841
- process.env.NODE_ENV !== "production") {
4139
+ process.env.NODE_ENV !== "production" &&
4140
+ process.env.IGNORE_MOBX_MINIFY_WARNING !== "true") {
3842
4141
  console.warn(
3843
4142
  // Template literal(backtick) is used for fix issue with rollup-plugin-commonjs https://github.com/rollup/rollup-plugin-commonjs/issues/344
3844
4143
  `[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`);
@@ -3856,4 +4155,4 @@ if (typeof __MOBX_DEVTOOLS_GLOBAL_HOOK__ === "object") {
3856
4155
  });
3857
4156
  }
3858
4157
 
3859
- export { Reaction$$1 as Reaction, untracked$$1 as untracked, IDerivationState, createAtom$$1 as createAtom, spy$$1 as spy, comparer$$1 as comparer, isObservableObject$$1 as isObservableObject, isObservableValue$$1 as isBoxedObservable, isObservableArray$$1 as isObservableArray, ObservableMap$$1 as ObservableMap, isObservableMap$$1 as isObservableMap, transaction$$1 as transaction, observable$$1 as observable, computed$$1 as computed, isObservable$$1 as isObservable, isObservableProp$$1 as isObservableProp, isComputed$$1 as isComputed, isComputedProp$$1 as isComputedProp, extendObservable$$1 as extendObservable, observe$$1 as observe, intercept$$1 as intercept, autorun$$1 as autorun, reaction$$1 as reaction, when$$1 as when, action$$1 as action, isAction$$1 as isAction, runInAction$$1 as runInAction, keys$$1 as keys, values$$1 as values, entries$$1 as entries, set$$1 as set, remove$$1 as remove, has$$1 as has, get$$1 as get, decorate$$1 as decorate, configure$$1 as configure, onBecomeObserved$$1 as onBecomeObserved, onBecomeUnobserved$$1 as onBecomeUnobserved, flow$$1 as flow, toJS$$1 as toJS, trace$$1 as trace, getDependencyTree$$1 as getDependencyTree, getObserverTree$$1 as getObserverTree, resetGlobalState$$1 as _resetGlobalState, getGlobalState$$1 as _getGlobalState, getDebugName$$1 as getDebugName, getAtom$$1 as getAtom, getAdministration$$1 as _getAdministration, allowStateChanges$$1 as _allowStateChanges, allowStateChangesInsideComputed$$1 as _allowStateChangesInsideComputed, isArrayLike$$1 as isArrayLike, $mobx$$1 as $mobx, isComputingDerivation$$1 as _isComputingDerivation, onReactionError$$1 as onReactionError, interceptReads$$1 as _interceptReads };
4158
+ export { Reaction$$1 as Reaction, untracked$$1 as untracked, IDerivationState, createAtom$$1 as createAtom, spy$$1 as spy, comparer$$1 as comparer, isObservableObject$$1 as isObservableObject, isObservableValue$$1 as isBoxedObservable, isObservableArray$$1 as isObservableArray, ObservableMap$$1 as ObservableMap, isObservableMap$$1 as isObservableMap, ObservableSet$$1 as ObservableSet, isObservableSet$$1 as isObservableSet, transaction$$1 as transaction, observable$$1 as observable, computed$$1 as computed, isObservable$$1 as isObservable, isObservableProp$$1 as isObservableProp, isComputed$$1 as isComputed, isComputedProp$$1 as isComputedProp, extendObservable$$1 as extendObservable, observe$$1 as observe, intercept$$1 as intercept, autorun$$1 as autorun, reaction$$1 as reaction, when$$1 as when, action$$1 as action, isAction$$1 as isAction, runInAction$$1 as runInAction, keys$$1 as keys, values$$1 as values, entries$$1 as entries, set$$1 as set, remove$$1 as remove, has$$1 as has, get$$1 as get, decorate$$1 as decorate, configure$$1 as configure, onBecomeObserved$$1 as onBecomeObserved, onBecomeUnobserved$$1 as onBecomeUnobserved, flow$$1 as flow, toJS$$1 as toJS, trace$$1 as trace, getDependencyTree$$1 as getDependencyTree, getObserverTree$$1 as getObserverTree, resetGlobalState$$1 as _resetGlobalState, getGlobalState$$1 as _getGlobalState, getDebugName$$1 as getDebugName, getAtom$$1 as getAtom, getAdministration$$1 as _getAdministration, allowStateChanges$$1 as _allowStateChanges, allowStateChangesInsideComputed$$1 as _allowStateChangesInsideComputed, isArrayLike$$1 as isArrayLike, $mobx$$1 as $mobx, isComputingDerivation$$1 as _isComputingDerivation, onReactionError$$1 as onReactionError, interceptReads$$1 as _interceptReads };