mobx 6.13.0 → 6.13.2

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/dist/mobx.esm.js CHANGED
@@ -203,15 +203,24 @@ function createInstanceofPredicate(name, theClass) {
203
203
  return isObject(x) && x[propName] === true;
204
204
  };
205
205
  }
206
+ /**
207
+ * Yields true for both native and observable Map, even across different windows.
208
+ */
206
209
  function isES6Map(thing) {
207
210
  return thing != null && Object.prototype.toString.call(thing) === "[object Map]";
208
211
  }
212
+ /**
213
+ * Makes sure a Map is an instance of non-inherited native or observable Map.
214
+ */
209
215
  function isPlainES6Map(thing) {
210
216
  var mapProto = Object.getPrototypeOf(thing);
211
217
  var objectProto = Object.getPrototypeOf(mapProto);
212
218
  var nullProto = Object.getPrototypeOf(objectProto);
213
219
  return nullProto === null;
214
220
  }
221
+ /**
222
+ * Yields true for both native and observable Set, even across different windows.
223
+ */
215
224
  function isES6Set(thing) {
216
225
  return thing != null && Object.prototype.toString.call(thing) === "[object Set]";
217
226
  }
@@ -263,6 +272,17 @@ var getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors || function get
263
272
  });
264
273
  return res;
265
274
  };
275
+ function getFlag(flags, mask) {
276
+ return !!(flags & mask);
277
+ }
278
+ function setFlag(flags, mask, newValue) {
279
+ if (newValue) {
280
+ flags |= mask;
281
+ } else {
282
+ flags &= ~mask;
283
+ }
284
+ return flags;
285
+ }
266
286
 
267
287
  function _arrayLikeToArray(r, a) {
268
288
  (null == a || a > r.length) && (a = r.length);
@@ -415,11 +435,8 @@ var Atom = /*#__PURE__*/function () {
415
435
  name_ = process.env.NODE_ENV !== "production" ? "Atom@" + getNextId() : "Atom";
416
436
  }
417
437
  this.name_ = void 0;
418
- this.isPendingUnobservation = false;
419
- // for effective unobserving. BaseAtom has true, for extra optimization, so its onBecomeUnobserved never gets called, because it's not needed
420
- this.isBeingObserved = false;
438
+ this.flags_ = 0;
421
439
  this.observers_ = new Set();
422
- this.diffValue_ = 0;
423
440
  this.lastAccessedBy_ = 0;
424
441
  this.lowestObserverState_ = IDerivationState_.NOT_TRACKING_;
425
442
  // onBecomeObservedListeners
@@ -428,6 +445,7 @@ var Atom = /*#__PURE__*/function () {
428
445
  this.onBUOL = void 0;
429
446
  this.name_ = name_;
430
447
  }
448
+ // for effective unobserving. BaseAtom has true, for extra optimization, so its onBecomeUnobserved never gets called, because it's not needed
431
449
  var _proto = Atom.prototype;
432
450
  _proto.onBO = function onBO() {
433
451
  if (this.onBOL) {
@@ -461,8 +479,35 @@ var Atom = /*#__PURE__*/function () {
461
479
  _proto.toString = function toString() {
462
480
  return this.name_;
463
481
  };
464
- return Atom;
482
+ return _createClass(Atom, [{
483
+ key: "isBeingObserved",
484
+ get: function get() {
485
+ return getFlag(this.flags_, Atom.isBeingObservedMask_);
486
+ },
487
+ set: function set(newValue) {
488
+ this.flags_ = setFlag(this.flags_, Atom.isBeingObservedMask_, newValue);
489
+ }
490
+ }, {
491
+ key: "isPendingUnobservation",
492
+ get: function get() {
493
+ return getFlag(this.flags_, Atom.isPendingUnobservationMask_);
494
+ },
495
+ set: function set(newValue) {
496
+ this.flags_ = setFlag(this.flags_, Atom.isPendingUnobservationMask_, newValue);
497
+ }
498
+ }, {
499
+ key: "diffValue",
500
+ get: function get() {
501
+ return getFlag(this.flags_, Atom.diffValueMask_) ? 1 : 0;
502
+ },
503
+ set: function set(newValue) {
504
+ this.flags_ = setFlag(this.flags_, Atom.diffValueMask_, newValue === 1 ? true : false);
505
+ }
506
+ }]);
465
507
  }();
508
+ Atom.isBeingObservedMask_ = 1;
509
+ Atom.isPendingUnobservationMask_ = 2;
510
+ Atom.diffValueMask_ = 4;
466
511
  var isAtom = /*#__PURE__*/createInstanceofPredicate("Atom", Atom);
467
512
  function createAtom(name, onBecomeObservedHandler, onBecomeUnobservedHandler) {
468
513
  if (onBecomeObservedHandler === void 0) {
@@ -1430,17 +1475,6 @@ var ObservableValue = /*#__PURE__*/function (_Atom) {
1430
1475
  }(Atom);
1431
1476
  var isObservableValue = /*#__PURE__*/createInstanceofPredicate("ObservableValue", ObservableValue);
1432
1477
 
1433
- function getFlag(flags, mask) {
1434
- return !!(flags & mask);
1435
- }
1436
- function setFlag(flags, mask, newValue) {
1437
- if (newValue) {
1438
- flags |= mask;
1439
- } else {
1440
- flags &= ~mask;
1441
- }
1442
- return flags;
1443
- }
1444
1478
  /**
1445
1479
  * A node in the state dependency root that observes other nodes, and can be observed itself.
1446
1480
  *
@@ -1480,7 +1514,6 @@ var ComputedValue = /*#__PURE__*/function () {
1480
1514
  this.newObserving_ = null;
1481
1515
  // during tracking it's an array with new observed observers
1482
1516
  this.observers_ = new Set();
1483
- this.diffValue_ = 0;
1484
1517
  this.runId_ = 0;
1485
1518
  this.lastAccessedBy_ = 0;
1486
1519
  this.lowestObserverState_ = IDerivationState_.UP_TO_DATE_;
@@ -1710,12 +1743,21 @@ var ComputedValue = /*#__PURE__*/function () {
1710
1743
  set: function set(newValue) {
1711
1744
  this.flags_ = setFlag(this.flags_, ComputedValue.isPendingUnobservationMask_, newValue);
1712
1745
  }
1746
+ }, {
1747
+ key: "diffValue",
1748
+ get: function get() {
1749
+ return getFlag(this.flags_, ComputedValue.diffValueMask_) ? 1 : 0;
1750
+ },
1751
+ set: function set(newValue) {
1752
+ this.flags_ = setFlag(this.flags_, ComputedValue.diffValueMask_, newValue === 1 ? true : false);
1753
+ }
1713
1754
  }]);
1714
1755
  }();
1715
1756
  ComputedValue.isComputingMask_ = 1;
1716
1757
  ComputedValue.isRunningSetterMask_ = 2;
1717
1758
  ComputedValue.isBeingObservedMask_ = 4;
1718
1759
  ComputedValue.isPendingUnobservationMask_ = 8;
1760
+ ComputedValue.diffValueMask_ = 16;
1719
1761
  var isComputedValue = /*#__PURE__*/createInstanceofPredicate("ComputedValue", ComputedValue);
1720
1762
 
1721
1763
  var IDerivationState_;
@@ -1890,8 +1932,8 @@ function bindDependencies(derivation) {
1890
1932
  l = derivation.unboundDepsCount_;
1891
1933
  for (var i = 0; i < l; i++) {
1892
1934
  var dep = observing[i];
1893
- if (dep.diffValue_ === 0) {
1894
- dep.diffValue_ = 1;
1935
+ if (dep.diffValue === 0) {
1936
+ dep.diffValue = 1;
1895
1937
  if (i0 !== i) {
1896
1938
  observing[i0] = dep;
1897
1939
  }
@@ -1911,18 +1953,18 @@ function bindDependencies(derivation) {
1911
1953
  l = prevObserving.length;
1912
1954
  while (l--) {
1913
1955
  var _dep = prevObserving[l];
1914
- if (_dep.diffValue_ === 0) {
1956
+ if (_dep.diffValue === 0) {
1915
1957
  removeObserver(_dep, derivation);
1916
1958
  }
1917
- _dep.diffValue_ = 0;
1959
+ _dep.diffValue = 0;
1918
1960
  }
1919
1961
  // Go through all new observables and check diffValue: (now it should be unique)
1920
1962
  // 0: it was set to 0 in last loop. don't need to do anything.
1921
1963
  // 1: it wasn't observed, let's observe it. set back to 0
1922
1964
  while (i0--) {
1923
1965
  var _dep2 = observing[i0];
1924
- if (_dep2.diffValue_ === 1) {
1925
- _dep2.diffValue_ = 0;
1966
+ if (_dep2.diffValue === 1) {
1967
+ _dep2.diffValue = 0;
1926
1968
  addObserver(_dep2, derivation);
1927
1969
  }
1928
1970
  }
@@ -2375,13 +2417,9 @@ var Reaction = /*#__PURE__*/function () {
2375
2417
  // nodes we are looking at. Our value depends on these nodes
2376
2418
  this.newObserving_ = [];
2377
2419
  this.dependenciesState_ = IDerivationState_.NOT_TRACKING_;
2378
- this.diffValue_ = 0;
2379
2420
  this.runId_ = 0;
2380
2421
  this.unboundDepsCount_ = 0;
2381
- this.isDisposed_ = false;
2382
- this.isScheduled_ = false;
2383
- this.isTrackPending_ = false;
2384
- this.isRunning_ = false;
2422
+ this.flags_ = 0;
2385
2423
  this.isTracing_ = TraceMode.NONE;
2386
2424
  this.name_ = name_;
2387
2425
  this.onInvalidate_ = onInvalidate_;
@@ -2393,29 +2431,26 @@ var Reaction = /*#__PURE__*/function () {
2393
2431
  this.schedule_();
2394
2432
  };
2395
2433
  _proto.schedule_ = function schedule_() {
2396
- if (!this.isScheduled_) {
2397
- this.isScheduled_ = true;
2434
+ if (!this.isScheduled) {
2435
+ this.isScheduled = true;
2398
2436
  globalState.pendingReactions.push(this);
2399
2437
  runReactions();
2400
2438
  }
2401
- };
2402
- _proto.isScheduled = function isScheduled() {
2403
- return this.isScheduled_;
2404
2439
  }
2405
2440
  /**
2406
2441
  * internal, use schedule() if you intend to kick off a reaction
2407
2442
  */;
2408
2443
  _proto.runReaction_ = function runReaction_() {
2409
- if (!this.isDisposed_) {
2444
+ if (!this.isDisposed) {
2410
2445
  startBatch();
2411
- this.isScheduled_ = false;
2446
+ this.isScheduled = false;
2412
2447
  var prev = globalState.trackingContext;
2413
2448
  globalState.trackingContext = this;
2414
2449
  if (shouldCompute(this)) {
2415
- this.isTrackPending_ = true;
2450
+ this.isTrackPending = true;
2416
2451
  try {
2417
2452
  this.onInvalidate_();
2418
- if (process.env.NODE_ENV !== "production" && this.isTrackPending_ && isSpyEnabled()) {
2453
+ if (process.env.NODE_ENV !== "production" && this.isTrackPending && isSpyEnabled()) {
2419
2454
  // onInvalidate didn't trigger track right away..
2420
2455
  spyReport({
2421
2456
  name: this.name_,
@@ -2431,7 +2466,7 @@ var Reaction = /*#__PURE__*/function () {
2431
2466
  }
2432
2467
  };
2433
2468
  _proto.track = function track(fn) {
2434
- if (this.isDisposed_) {
2469
+ if (this.isDisposed) {
2435
2470
  return;
2436
2471
  // console.warn("Reaction already disposed") // Note: Not a warning / error in mobx 4 either
2437
2472
  }
@@ -2445,14 +2480,14 @@ var Reaction = /*#__PURE__*/function () {
2445
2480
  type: "reaction"
2446
2481
  });
2447
2482
  }
2448
- this.isRunning_ = true;
2483
+ this.isRunning = true;
2449
2484
  var prevReaction = globalState.trackingContext; // reactions could create reactions...
2450
2485
  globalState.trackingContext = this;
2451
2486
  var result = trackDerivedFunction(this, fn, undefined);
2452
2487
  globalState.trackingContext = prevReaction;
2453
- this.isRunning_ = false;
2454
- this.isTrackPending_ = false;
2455
- if (this.isDisposed_) {
2488
+ this.isRunning = false;
2489
+ this.isTrackPending = false;
2490
+ if (this.isDisposed) {
2456
2491
  // disposed during last run. Clean up everything that was bound after the dispose call.
2457
2492
  clearObserving(this);
2458
2493
  }
@@ -2495,9 +2530,9 @@ var Reaction = /*#__PURE__*/function () {
2495
2530
  });
2496
2531
  };
2497
2532
  _proto.dispose = function dispose() {
2498
- if (!this.isDisposed_) {
2499
- this.isDisposed_ = true;
2500
- if (!this.isRunning_) {
2533
+ if (!this.isDisposed) {
2534
+ this.isDisposed = true;
2535
+ if (!this.isRunning) {
2501
2536
  // if disposed while running, clean up later. Maybe not optimal, but rare case
2502
2537
  startBatch();
2503
2538
  clearObserving(this);
@@ -2524,8 +2559,53 @@ var Reaction = /*#__PURE__*/function () {
2524
2559
  }
2525
2560
  trace(this, enterBreakPoint);
2526
2561
  };
2527
- return Reaction;
2562
+ return _createClass(Reaction, [{
2563
+ key: "isDisposed",
2564
+ get: function get() {
2565
+ return getFlag(this.flags_, Reaction.isDisposedMask_);
2566
+ },
2567
+ set: function set(newValue) {
2568
+ this.flags_ = setFlag(this.flags_, Reaction.isDisposedMask_, newValue);
2569
+ }
2570
+ }, {
2571
+ key: "isScheduled",
2572
+ get: function get() {
2573
+ return getFlag(this.flags_, Reaction.isScheduledMask_);
2574
+ },
2575
+ set: function set(newValue) {
2576
+ this.flags_ = setFlag(this.flags_, Reaction.isScheduledMask_, newValue);
2577
+ }
2578
+ }, {
2579
+ key: "isTrackPending",
2580
+ get: function get() {
2581
+ return getFlag(this.flags_, Reaction.isTrackPendingMask_);
2582
+ },
2583
+ set: function set(newValue) {
2584
+ this.flags_ = setFlag(this.flags_, Reaction.isTrackPendingMask_, newValue);
2585
+ }
2586
+ }, {
2587
+ key: "isRunning",
2588
+ get: function get() {
2589
+ return getFlag(this.flags_, Reaction.isRunningMask_);
2590
+ },
2591
+ set: function set(newValue) {
2592
+ this.flags_ = setFlag(this.flags_, Reaction.isRunningMask_, newValue);
2593
+ }
2594
+ }, {
2595
+ key: "diffValue",
2596
+ get: function get() {
2597
+ return getFlag(this.flags_, Reaction.diffValueMask_) ? 1 : 0;
2598
+ },
2599
+ set: function set(newValue) {
2600
+ this.flags_ = setFlag(this.flags_, Reaction.diffValueMask_, newValue === 1 ? true : false);
2601
+ }
2602
+ }]);
2528
2603
  }();
2604
+ Reaction.isDisposedMask_ = 1;
2605
+ Reaction.isScheduledMask_ = 2;
2606
+ Reaction.isTrackPendingMask_ = 4;
2607
+ Reaction.isRunningMask_ = 8;
2608
+ Reaction.diffValueMask_ = 16;
2529
2609
  function onReactionError(handler) {
2530
2610
  globalState.globalReactionErrorHandlers.push(handler);
2531
2611
  return function () {
@@ -2731,7 +2811,7 @@ function autorun(view, opts) {
2731
2811
  isScheduled = true;
2732
2812
  scheduler(function () {
2733
2813
  isScheduled = false;
2734
- if (!reaction.isDisposed_) {
2814
+ if (!reaction.isDisposed) {
2735
2815
  reaction.track(reactionRunner);
2736
2816
  }
2737
2817
  });
@@ -2785,7 +2865,7 @@ function reaction(expression, effect, opts) {
2785
2865
  }, opts.onError, opts.requiresObservable);
2786
2866
  function reactionRunner() {
2787
2867
  isScheduled = false;
2788
- if (r.isDisposed_) {
2868
+ if (r.isDisposed) {
2789
2869
  return;
2790
2870
  }
2791
2871
  var changed = false;
@@ -3415,7 +3495,7 @@ function _when(predicate, effect, opts) {
3415
3495
  if (typeof opts.timeout === "number") {
3416
3496
  var error = new Error("WHEN_TIMEOUT");
3417
3497
  timeoutHandle = setTimeout(function () {
3418
- if (!disposer[$mobx].isDisposed_) {
3498
+ if (!disposer[$mobx].isDisposed) {
3419
3499
  disposer();
3420
3500
  if (opts.onError) {
3421
3501
  opts.onError(error);
@@ -4721,7 +4801,7 @@ var ObservableSet = /*#__PURE__*/function () {
4721
4801
  });
4722
4802
  };
4723
4803
  _proto.intersection = function intersection(otherSet) {
4724
- if (isES6Set(otherSet)) {
4804
+ if (isES6Set(otherSet) && !isObservableSet(otherSet)) {
4725
4805
  return otherSet.intersection(this);
4726
4806
  } else {
4727
4807
  var dehancedSet = new Set(this);
@@ -4729,7 +4809,7 @@ var ObservableSet = /*#__PURE__*/function () {
4729
4809
  }
4730
4810
  };
4731
4811
  _proto.union = function union(otherSet) {
4732
- if (isES6Set(otherSet)) {
4812
+ if (isES6Set(otherSet) && !isObservableSet(otherSet)) {
4733
4813
  return otherSet.union(this);
4734
4814
  } else {
4735
4815
  var dehancedSet = new Set(this);
@@ -4740,7 +4820,7 @@ var ObservableSet = /*#__PURE__*/function () {
4740
4820
  return new Set(this).difference(otherSet);
4741
4821
  };
4742
4822
  _proto.symmetricDifference = function symmetricDifference(otherSet) {
4743
- if (isES6Set(otherSet)) {
4823
+ if (isES6Set(otherSet) && !isObservableSet(otherSet)) {
4744
4824
  return otherSet.symmetricDifference(this);
4745
4825
  } else {
4746
4826
  var dehancedSet = new Set(this);
@@ -4754,7 +4834,7 @@ var ObservableSet = /*#__PURE__*/function () {
4754
4834
  return new Set(this).isSupersetOf(otherSet);
4755
4835
  };
4756
4836
  _proto.isDisjointFrom = function isDisjointFrom(otherSet) {
4757
- if (isES6Set(otherSet)) {
4837
+ if (isES6Set(otherSet) && !isObservableSet(otherSet)) {
4758
4838
  return otherSet.isDisjointFrom(this);
4759
4839
  } else {
4760
4840
  var dehancedSet = new Set(this);