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.
@@ -208,15 +208,24 @@
208
208
  return isObject(x) && x[propName] === true;
209
209
  };
210
210
  }
211
+ /**
212
+ * Yields true for both native and observable Map, even across different windows.
213
+ */
211
214
  function isES6Map(thing) {
212
215
  return thing != null && Object.prototype.toString.call(thing) === "[object Map]";
213
216
  }
217
+ /**
218
+ * Makes sure a Map is an instance of non-inherited native or observable Map.
219
+ */
214
220
  function isPlainES6Map(thing) {
215
221
  var mapProto = Object.getPrototypeOf(thing);
216
222
  var objectProto = Object.getPrototypeOf(mapProto);
217
223
  var nullProto = Object.getPrototypeOf(objectProto);
218
224
  return nullProto === null;
219
225
  }
226
+ /**
227
+ * Yields true for both native and observable Set, even across different windows.
228
+ */
220
229
  function isES6Set(thing) {
221
230
  return thing != null && Object.prototype.toString.call(thing) === "[object Set]";
222
231
  }
@@ -268,6 +277,17 @@
268
277
  });
269
278
  return res;
270
279
  };
280
+ function getFlag(flags, mask) {
281
+ return !!(flags & mask);
282
+ }
283
+ function setFlag(flags, mask, newValue) {
284
+ if (newValue) {
285
+ flags |= mask;
286
+ } else {
287
+ flags &= ~mask;
288
+ }
289
+ return flags;
290
+ }
271
291
 
272
292
  function _arrayLikeToArray(r, a) {
273
293
  (null == a || a > r.length) && (a = r.length);
@@ -420,11 +440,8 @@
420
440
  name_ = "Atom@" + getNextId() ;
421
441
  }
422
442
  this.name_ = void 0;
423
- this.isPendingUnobservation = false;
424
- // for effective unobserving. BaseAtom has true, for extra optimization, so its onBecomeUnobserved never gets called, because it's not needed
425
- this.isBeingObserved = false;
443
+ this.flags_ = 0;
426
444
  this.observers_ = new Set();
427
- this.diffValue_ = 0;
428
445
  this.lastAccessedBy_ = 0;
429
446
  this.lowestObserverState_ = IDerivationState_.NOT_TRACKING_;
430
447
  // onBecomeObservedListeners
@@ -433,6 +450,7 @@
433
450
  this.onBUOL = void 0;
434
451
  this.name_ = name_;
435
452
  }
453
+ // for effective unobserving. BaseAtom has true, for extra optimization, so its onBecomeUnobserved never gets called, because it's not needed
436
454
  var _proto = Atom.prototype;
437
455
  _proto.onBO = function onBO() {
438
456
  if (this.onBOL) {
@@ -466,8 +484,35 @@
466
484
  _proto.toString = function toString() {
467
485
  return this.name_;
468
486
  };
469
- return Atom;
487
+ return _createClass(Atom, [{
488
+ key: "isBeingObserved",
489
+ get: function get() {
490
+ return getFlag(this.flags_, Atom.isBeingObservedMask_);
491
+ },
492
+ set: function set(newValue) {
493
+ this.flags_ = setFlag(this.flags_, Atom.isBeingObservedMask_, newValue);
494
+ }
495
+ }, {
496
+ key: "isPendingUnobservation",
497
+ get: function get() {
498
+ return getFlag(this.flags_, Atom.isPendingUnobservationMask_);
499
+ },
500
+ set: function set(newValue) {
501
+ this.flags_ = setFlag(this.flags_, Atom.isPendingUnobservationMask_, newValue);
502
+ }
503
+ }, {
504
+ key: "diffValue",
505
+ get: function get() {
506
+ return getFlag(this.flags_, Atom.diffValueMask_) ? 1 : 0;
507
+ },
508
+ set: function set(newValue) {
509
+ this.flags_ = setFlag(this.flags_, Atom.diffValueMask_, newValue === 1 ? true : false);
510
+ }
511
+ }]);
470
512
  }();
513
+ Atom.isBeingObservedMask_ = 1;
514
+ Atom.isPendingUnobservationMask_ = 2;
515
+ Atom.diffValueMask_ = 4;
471
516
  var isAtom = /*#__PURE__*/createInstanceofPredicate("Atom", Atom);
472
517
  function createAtom(name, onBecomeObservedHandler, onBecomeUnobservedHandler) {
473
518
  if (onBecomeObservedHandler === void 0) {
@@ -1435,17 +1480,6 @@
1435
1480
  }(Atom);
1436
1481
  var isObservableValue = /*#__PURE__*/createInstanceofPredicate("ObservableValue", ObservableValue);
1437
1482
 
1438
- function getFlag(flags, mask) {
1439
- return !!(flags & mask);
1440
- }
1441
- function setFlag(flags, mask, newValue) {
1442
- if (newValue) {
1443
- flags |= mask;
1444
- } else {
1445
- flags &= ~mask;
1446
- }
1447
- return flags;
1448
- }
1449
1483
  /**
1450
1484
  * A node in the state dependency root that observes other nodes, and can be observed itself.
1451
1485
  *
@@ -1485,7 +1519,6 @@
1485
1519
  this.newObserving_ = null;
1486
1520
  // during tracking it's an array with new observed observers
1487
1521
  this.observers_ = new Set();
1488
- this.diffValue_ = 0;
1489
1522
  this.runId_ = 0;
1490
1523
  this.lastAccessedBy_ = 0;
1491
1524
  this.lowestObserverState_ = IDerivationState_.UP_TO_DATE_;
@@ -1712,12 +1745,21 @@
1712
1745
  set: function set(newValue) {
1713
1746
  this.flags_ = setFlag(this.flags_, ComputedValue.isPendingUnobservationMask_, newValue);
1714
1747
  }
1748
+ }, {
1749
+ key: "diffValue",
1750
+ get: function get() {
1751
+ return getFlag(this.flags_, ComputedValue.diffValueMask_) ? 1 : 0;
1752
+ },
1753
+ set: function set(newValue) {
1754
+ this.flags_ = setFlag(this.flags_, ComputedValue.diffValueMask_, newValue === 1 ? true : false);
1755
+ }
1715
1756
  }]);
1716
1757
  }();
1717
1758
  ComputedValue.isComputingMask_ = 1;
1718
1759
  ComputedValue.isRunningSetterMask_ = 2;
1719
1760
  ComputedValue.isBeingObservedMask_ = 4;
1720
1761
  ComputedValue.isPendingUnobservationMask_ = 8;
1762
+ ComputedValue.diffValueMask_ = 16;
1721
1763
  var isComputedValue = /*#__PURE__*/createInstanceofPredicate("ComputedValue", ComputedValue);
1722
1764
 
1723
1765
  var IDerivationState_;
@@ -1886,8 +1928,8 @@
1886
1928
  l = derivation.unboundDepsCount_;
1887
1929
  for (var i = 0; i < l; i++) {
1888
1930
  var dep = observing[i];
1889
- if (dep.diffValue_ === 0) {
1890
- dep.diffValue_ = 1;
1931
+ if (dep.diffValue === 0) {
1932
+ dep.diffValue = 1;
1891
1933
  if (i0 !== i) {
1892
1934
  observing[i0] = dep;
1893
1935
  }
@@ -1907,18 +1949,18 @@
1907
1949
  l = prevObserving.length;
1908
1950
  while (l--) {
1909
1951
  var _dep = prevObserving[l];
1910
- if (_dep.diffValue_ === 0) {
1952
+ if (_dep.diffValue === 0) {
1911
1953
  removeObserver(_dep, derivation);
1912
1954
  }
1913
- _dep.diffValue_ = 0;
1955
+ _dep.diffValue = 0;
1914
1956
  }
1915
1957
  // Go through all new observables and check diffValue: (now it should be unique)
1916
1958
  // 0: it was set to 0 in last loop. don't need to do anything.
1917
1959
  // 1: it wasn't observed, let's observe it. set back to 0
1918
1960
  while (i0--) {
1919
1961
  var _dep2 = observing[i0];
1920
- if (_dep2.diffValue_ === 1) {
1921
- _dep2.diffValue_ = 0;
1962
+ if (_dep2.diffValue === 1) {
1963
+ _dep2.diffValue = 0;
1922
1964
  addObserver(_dep2, derivation);
1923
1965
  }
1924
1966
  }
@@ -2371,13 +2413,9 @@
2371
2413
  // nodes we are looking at. Our value depends on these nodes
2372
2414
  this.newObserving_ = [];
2373
2415
  this.dependenciesState_ = IDerivationState_.NOT_TRACKING_;
2374
- this.diffValue_ = 0;
2375
2416
  this.runId_ = 0;
2376
2417
  this.unboundDepsCount_ = 0;
2377
- this.isDisposed_ = false;
2378
- this.isScheduled_ = false;
2379
- this.isTrackPending_ = false;
2380
- this.isRunning_ = false;
2418
+ this.flags_ = 0;
2381
2419
  this.isTracing_ = TraceMode.NONE;
2382
2420
  this.name_ = name_;
2383
2421
  this.onInvalidate_ = onInvalidate_;
@@ -2389,29 +2427,26 @@
2389
2427
  this.schedule_();
2390
2428
  };
2391
2429
  _proto.schedule_ = function schedule_() {
2392
- if (!this.isScheduled_) {
2393
- this.isScheduled_ = true;
2430
+ if (!this.isScheduled) {
2431
+ this.isScheduled = true;
2394
2432
  globalState.pendingReactions.push(this);
2395
2433
  runReactions();
2396
2434
  }
2397
- };
2398
- _proto.isScheduled = function isScheduled() {
2399
- return this.isScheduled_;
2400
2435
  }
2401
2436
  /**
2402
2437
  * internal, use schedule() if you intend to kick off a reaction
2403
2438
  */;
2404
2439
  _proto.runReaction_ = function runReaction_() {
2405
- if (!this.isDisposed_) {
2440
+ if (!this.isDisposed) {
2406
2441
  startBatch();
2407
- this.isScheduled_ = false;
2442
+ this.isScheduled = false;
2408
2443
  var prev = globalState.trackingContext;
2409
2444
  globalState.trackingContext = this;
2410
2445
  if (shouldCompute(this)) {
2411
- this.isTrackPending_ = true;
2446
+ this.isTrackPending = true;
2412
2447
  try {
2413
2448
  this.onInvalidate_();
2414
- if ("development" !== "production" && this.isTrackPending_ && isSpyEnabled()) {
2449
+ if ("development" !== "production" && this.isTrackPending && isSpyEnabled()) {
2415
2450
  // onInvalidate didn't trigger track right away..
2416
2451
  spyReport({
2417
2452
  name: this.name_,
@@ -2427,7 +2462,7 @@
2427
2462
  }
2428
2463
  };
2429
2464
  _proto.track = function track(fn) {
2430
- if (this.isDisposed_) {
2465
+ if (this.isDisposed) {
2431
2466
  return;
2432
2467
  // console.warn("Reaction already disposed") // Note: Not a warning / error in mobx 4 either
2433
2468
  }
@@ -2441,14 +2476,14 @@
2441
2476
  type: "reaction"
2442
2477
  });
2443
2478
  }
2444
- this.isRunning_ = true;
2479
+ this.isRunning = true;
2445
2480
  var prevReaction = globalState.trackingContext; // reactions could create reactions...
2446
2481
  globalState.trackingContext = this;
2447
2482
  var result = trackDerivedFunction(this, fn, undefined);
2448
2483
  globalState.trackingContext = prevReaction;
2449
- this.isRunning_ = false;
2450
- this.isTrackPending_ = false;
2451
- if (this.isDisposed_) {
2484
+ this.isRunning = false;
2485
+ this.isTrackPending = false;
2486
+ if (this.isDisposed) {
2452
2487
  // disposed during last run. Clean up everything that was bound after the dispose call.
2453
2488
  clearObserving(this);
2454
2489
  }
@@ -2491,9 +2526,9 @@
2491
2526
  });
2492
2527
  };
2493
2528
  _proto.dispose = function dispose() {
2494
- if (!this.isDisposed_) {
2495
- this.isDisposed_ = true;
2496
- if (!this.isRunning_) {
2529
+ if (!this.isDisposed) {
2530
+ this.isDisposed = true;
2531
+ if (!this.isRunning) {
2497
2532
  // if disposed while running, clean up later. Maybe not optimal, but rare case
2498
2533
  startBatch();
2499
2534
  clearObserving(this);
@@ -2520,8 +2555,53 @@
2520
2555
  }
2521
2556
  trace(this, enterBreakPoint);
2522
2557
  };
2523
- return Reaction;
2558
+ return _createClass(Reaction, [{
2559
+ key: "isDisposed",
2560
+ get: function get() {
2561
+ return getFlag(this.flags_, Reaction.isDisposedMask_);
2562
+ },
2563
+ set: function set(newValue) {
2564
+ this.flags_ = setFlag(this.flags_, Reaction.isDisposedMask_, newValue);
2565
+ }
2566
+ }, {
2567
+ key: "isScheduled",
2568
+ get: function get() {
2569
+ return getFlag(this.flags_, Reaction.isScheduledMask_);
2570
+ },
2571
+ set: function set(newValue) {
2572
+ this.flags_ = setFlag(this.flags_, Reaction.isScheduledMask_, newValue);
2573
+ }
2574
+ }, {
2575
+ key: "isTrackPending",
2576
+ get: function get() {
2577
+ return getFlag(this.flags_, Reaction.isTrackPendingMask_);
2578
+ },
2579
+ set: function set(newValue) {
2580
+ this.flags_ = setFlag(this.flags_, Reaction.isTrackPendingMask_, newValue);
2581
+ }
2582
+ }, {
2583
+ key: "isRunning",
2584
+ get: function get() {
2585
+ return getFlag(this.flags_, Reaction.isRunningMask_);
2586
+ },
2587
+ set: function set(newValue) {
2588
+ this.flags_ = setFlag(this.flags_, Reaction.isRunningMask_, newValue);
2589
+ }
2590
+ }, {
2591
+ key: "diffValue",
2592
+ get: function get() {
2593
+ return getFlag(this.flags_, Reaction.diffValueMask_) ? 1 : 0;
2594
+ },
2595
+ set: function set(newValue) {
2596
+ this.flags_ = setFlag(this.flags_, Reaction.diffValueMask_, newValue === 1 ? true : false);
2597
+ }
2598
+ }]);
2524
2599
  }();
2600
+ Reaction.isDisposedMask_ = 1;
2601
+ Reaction.isScheduledMask_ = 2;
2602
+ Reaction.isTrackPendingMask_ = 4;
2603
+ Reaction.isRunningMask_ = 8;
2604
+ Reaction.diffValueMask_ = 16;
2525
2605
  function onReactionError(handler) {
2526
2606
  globalState.globalReactionErrorHandlers.push(handler);
2527
2607
  return function () {
@@ -2715,7 +2795,7 @@
2715
2795
  isScheduled = true;
2716
2796
  scheduler(function () {
2717
2797
  isScheduled = false;
2718
- if (!reaction.isDisposed_) {
2798
+ if (!reaction.isDisposed) {
2719
2799
  reaction.track(reactionRunner);
2720
2800
  }
2721
2801
  });
@@ -2769,7 +2849,7 @@
2769
2849
  }, opts.onError, opts.requiresObservable);
2770
2850
  function reactionRunner() {
2771
2851
  isScheduled = false;
2772
- if (r.isDisposed_) {
2852
+ if (r.isDisposed) {
2773
2853
  return;
2774
2854
  }
2775
2855
  var changed = false;
@@ -3396,7 +3476,7 @@
3396
3476
  if (typeof opts.timeout === "number") {
3397
3477
  var error = new Error("WHEN_TIMEOUT");
3398
3478
  timeoutHandle = setTimeout(function () {
3399
- if (!disposer[$mobx].isDisposed_) {
3479
+ if (!disposer[$mobx].isDisposed) {
3400
3480
  disposer();
3401
3481
  if (opts.onError) {
3402
3482
  opts.onError(error);
@@ -4702,7 +4782,7 @@
4702
4782
  });
4703
4783
  };
4704
4784
  _proto.intersection = function intersection(otherSet) {
4705
- if (isES6Set(otherSet)) {
4785
+ if (isES6Set(otherSet) && !isObservableSet(otherSet)) {
4706
4786
  return otherSet.intersection(this);
4707
4787
  } else {
4708
4788
  var dehancedSet = new Set(this);
@@ -4710,7 +4790,7 @@
4710
4790
  }
4711
4791
  };
4712
4792
  _proto.union = function union(otherSet) {
4713
- if (isES6Set(otherSet)) {
4793
+ if (isES6Set(otherSet) && !isObservableSet(otherSet)) {
4714
4794
  return otherSet.union(this);
4715
4795
  } else {
4716
4796
  var dehancedSet = new Set(this);
@@ -4721,7 +4801,7 @@
4721
4801
  return new Set(this).difference(otherSet);
4722
4802
  };
4723
4803
  _proto.symmetricDifference = function symmetricDifference(otherSet) {
4724
- if (isES6Set(otherSet)) {
4804
+ if (isES6Set(otherSet) && !isObservableSet(otherSet)) {
4725
4805
  return otherSet.symmetricDifference(this);
4726
4806
  } else {
4727
4807
  var dehancedSet = new Set(this);
@@ -4735,7 +4815,7 @@
4735
4815
  return new Set(this).isSupersetOf(otherSet);
4736
4816
  };
4737
4817
  _proto.isDisjointFrom = function isDisjointFrom(otherSet) {
4738
- if (isES6Set(otherSet)) {
4818
+ if (isES6Set(otherSet) && !isObservableSet(otherSet)) {
4739
4819
  return otherSet.isDisjointFrom(this);
4740
4820
  } else {
4741
4821
  var dehancedSet = new Set(this);