mobx 6.13.0 → 6.13.1

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.
@@ -268,6 +268,17 @@
268
268
  });
269
269
  return res;
270
270
  };
271
+ function getFlag(flags, mask) {
272
+ return !!(flags & mask);
273
+ }
274
+ function setFlag(flags, mask, newValue) {
275
+ if (newValue) {
276
+ flags |= mask;
277
+ } else {
278
+ flags &= ~mask;
279
+ }
280
+ return flags;
281
+ }
271
282
 
272
283
  function _arrayLikeToArray(r, a) {
273
284
  (null == a || a > r.length) && (a = r.length);
@@ -420,11 +431,8 @@
420
431
  name_ = "Atom@" + getNextId() ;
421
432
  }
422
433
  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;
434
+ this.flags_ = 0;
426
435
  this.observers_ = new Set();
427
- this.diffValue_ = 0;
428
436
  this.lastAccessedBy_ = 0;
429
437
  this.lowestObserverState_ = IDerivationState_.NOT_TRACKING_;
430
438
  // onBecomeObservedListeners
@@ -433,6 +441,7 @@
433
441
  this.onBUOL = void 0;
434
442
  this.name_ = name_;
435
443
  }
444
+ // for effective unobserving. BaseAtom has true, for extra optimization, so its onBecomeUnobserved never gets called, because it's not needed
436
445
  var _proto = Atom.prototype;
437
446
  _proto.onBO = function onBO() {
438
447
  if (this.onBOL) {
@@ -466,8 +475,35 @@
466
475
  _proto.toString = function toString() {
467
476
  return this.name_;
468
477
  };
469
- return Atom;
478
+ return _createClass(Atom, [{
479
+ key: "isBeingObserved",
480
+ get: function get() {
481
+ return getFlag(this.flags_, Atom.isBeingObservedMask_);
482
+ },
483
+ set: function set(newValue) {
484
+ this.flags_ = setFlag(this.flags_, Atom.isBeingObservedMask_, newValue);
485
+ }
486
+ }, {
487
+ key: "isPendingUnobservation",
488
+ get: function get() {
489
+ return getFlag(this.flags_, Atom.isPendingUnobservationMask_);
490
+ },
491
+ set: function set(newValue) {
492
+ this.flags_ = setFlag(this.flags_, Atom.isPendingUnobservationMask_, newValue);
493
+ }
494
+ }, {
495
+ key: "diffValue",
496
+ get: function get() {
497
+ return getFlag(this.flags_, Atom.diffValueMask_) ? 1 : 0;
498
+ },
499
+ set: function set(newValue) {
500
+ this.flags_ = setFlag(this.flags_, Atom.diffValueMask_, newValue === 1 ? true : false);
501
+ }
502
+ }]);
470
503
  }();
504
+ Atom.isBeingObservedMask_ = 1;
505
+ Atom.isPendingUnobservationMask_ = 2;
506
+ Atom.diffValueMask_ = 4;
471
507
  var isAtom = /*#__PURE__*/createInstanceofPredicate("Atom", Atom);
472
508
  function createAtom(name, onBecomeObservedHandler, onBecomeUnobservedHandler) {
473
509
  if (onBecomeObservedHandler === void 0) {
@@ -1435,17 +1471,6 @@
1435
1471
  }(Atom);
1436
1472
  var isObservableValue = /*#__PURE__*/createInstanceofPredicate("ObservableValue", ObservableValue);
1437
1473
 
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
1474
  /**
1450
1475
  * A node in the state dependency root that observes other nodes, and can be observed itself.
1451
1476
  *
@@ -1485,7 +1510,6 @@
1485
1510
  this.newObserving_ = null;
1486
1511
  // during tracking it's an array with new observed observers
1487
1512
  this.observers_ = new Set();
1488
- this.diffValue_ = 0;
1489
1513
  this.runId_ = 0;
1490
1514
  this.lastAccessedBy_ = 0;
1491
1515
  this.lowestObserverState_ = IDerivationState_.UP_TO_DATE_;
@@ -1712,12 +1736,21 @@
1712
1736
  set: function set(newValue) {
1713
1737
  this.flags_ = setFlag(this.flags_, ComputedValue.isPendingUnobservationMask_, newValue);
1714
1738
  }
1739
+ }, {
1740
+ key: "diffValue",
1741
+ get: function get() {
1742
+ return getFlag(this.flags_, ComputedValue.diffValueMask_) ? 1 : 0;
1743
+ },
1744
+ set: function set(newValue) {
1745
+ this.flags_ = setFlag(this.flags_, ComputedValue.diffValueMask_, newValue === 1 ? true : false);
1746
+ }
1715
1747
  }]);
1716
1748
  }();
1717
1749
  ComputedValue.isComputingMask_ = 1;
1718
1750
  ComputedValue.isRunningSetterMask_ = 2;
1719
1751
  ComputedValue.isBeingObservedMask_ = 4;
1720
1752
  ComputedValue.isPendingUnobservationMask_ = 8;
1753
+ ComputedValue.diffValueMask_ = 16;
1721
1754
  var isComputedValue = /*#__PURE__*/createInstanceofPredicate("ComputedValue", ComputedValue);
1722
1755
 
1723
1756
  var IDerivationState_;
@@ -1886,8 +1919,8 @@
1886
1919
  l = derivation.unboundDepsCount_;
1887
1920
  for (var i = 0; i < l; i++) {
1888
1921
  var dep = observing[i];
1889
- if (dep.diffValue_ === 0) {
1890
- dep.diffValue_ = 1;
1922
+ if (dep.diffValue === 0) {
1923
+ dep.diffValue = 1;
1891
1924
  if (i0 !== i) {
1892
1925
  observing[i0] = dep;
1893
1926
  }
@@ -1907,18 +1940,18 @@
1907
1940
  l = prevObserving.length;
1908
1941
  while (l--) {
1909
1942
  var _dep = prevObserving[l];
1910
- if (_dep.diffValue_ === 0) {
1943
+ if (_dep.diffValue === 0) {
1911
1944
  removeObserver(_dep, derivation);
1912
1945
  }
1913
- _dep.diffValue_ = 0;
1946
+ _dep.diffValue = 0;
1914
1947
  }
1915
1948
  // Go through all new observables and check diffValue: (now it should be unique)
1916
1949
  // 0: it was set to 0 in last loop. don't need to do anything.
1917
1950
  // 1: it wasn't observed, let's observe it. set back to 0
1918
1951
  while (i0--) {
1919
1952
  var _dep2 = observing[i0];
1920
- if (_dep2.diffValue_ === 1) {
1921
- _dep2.diffValue_ = 0;
1953
+ if (_dep2.diffValue === 1) {
1954
+ _dep2.diffValue = 0;
1922
1955
  addObserver(_dep2, derivation);
1923
1956
  }
1924
1957
  }
@@ -2371,13 +2404,9 @@
2371
2404
  // nodes we are looking at. Our value depends on these nodes
2372
2405
  this.newObserving_ = [];
2373
2406
  this.dependenciesState_ = IDerivationState_.NOT_TRACKING_;
2374
- this.diffValue_ = 0;
2375
2407
  this.runId_ = 0;
2376
2408
  this.unboundDepsCount_ = 0;
2377
- this.isDisposed_ = false;
2378
- this.isScheduled_ = false;
2379
- this.isTrackPending_ = false;
2380
- this.isRunning_ = false;
2409
+ this.flags_ = 0;
2381
2410
  this.isTracing_ = TraceMode.NONE;
2382
2411
  this.name_ = name_;
2383
2412
  this.onInvalidate_ = onInvalidate_;
@@ -2389,29 +2418,26 @@
2389
2418
  this.schedule_();
2390
2419
  };
2391
2420
  _proto.schedule_ = function schedule_() {
2392
- if (!this.isScheduled_) {
2393
- this.isScheduled_ = true;
2421
+ if (!this.isScheduled) {
2422
+ this.isScheduled = true;
2394
2423
  globalState.pendingReactions.push(this);
2395
2424
  runReactions();
2396
2425
  }
2397
- };
2398
- _proto.isScheduled = function isScheduled() {
2399
- return this.isScheduled_;
2400
2426
  }
2401
2427
  /**
2402
2428
  * internal, use schedule() if you intend to kick off a reaction
2403
2429
  */;
2404
2430
  _proto.runReaction_ = function runReaction_() {
2405
- if (!this.isDisposed_) {
2431
+ if (!this.isDisposed) {
2406
2432
  startBatch();
2407
- this.isScheduled_ = false;
2433
+ this.isScheduled = false;
2408
2434
  var prev = globalState.trackingContext;
2409
2435
  globalState.trackingContext = this;
2410
2436
  if (shouldCompute(this)) {
2411
- this.isTrackPending_ = true;
2437
+ this.isTrackPending = true;
2412
2438
  try {
2413
2439
  this.onInvalidate_();
2414
- if ("development" !== "production" && this.isTrackPending_ && isSpyEnabled()) {
2440
+ if ("development" !== "production" && this.isTrackPending && isSpyEnabled()) {
2415
2441
  // onInvalidate didn't trigger track right away..
2416
2442
  spyReport({
2417
2443
  name: this.name_,
@@ -2427,7 +2453,7 @@
2427
2453
  }
2428
2454
  };
2429
2455
  _proto.track = function track(fn) {
2430
- if (this.isDisposed_) {
2456
+ if (this.isDisposed) {
2431
2457
  return;
2432
2458
  // console.warn("Reaction already disposed") // Note: Not a warning / error in mobx 4 either
2433
2459
  }
@@ -2441,14 +2467,14 @@
2441
2467
  type: "reaction"
2442
2468
  });
2443
2469
  }
2444
- this.isRunning_ = true;
2470
+ this.isRunning = true;
2445
2471
  var prevReaction = globalState.trackingContext; // reactions could create reactions...
2446
2472
  globalState.trackingContext = this;
2447
2473
  var result = trackDerivedFunction(this, fn, undefined);
2448
2474
  globalState.trackingContext = prevReaction;
2449
- this.isRunning_ = false;
2450
- this.isTrackPending_ = false;
2451
- if (this.isDisposed_) {
2475
+ this.isRunning = false;
2476
+ this.isTrackPending = false;
2477
+ if (this.isDisposed) {
2452
2478
  // disposed during last run. Clean up everything that was bound after the dispose call.
2453
2479
  clearObserving(this);
2454
2480
  }
@@ -2491,9 +2517,9 @@
2491
2517
  });
2492
2518
  };
2493
2519
  _proto.dispose = function dispose() {
2494
- if (!this.isDisposed_) {
2495
- this.isDisposed_ = true;
2496
- if (!this.isRunning_) {
2520
+ if (!this.isDisposed) {
2521
+ this.isDisposed = true;
2522
+ if (!this.isRunning) {
2497
2523
  // if disposed while running, clean up later. Maybe not optimal, but rare case
2498
2524
  startBatch();
2499
2525
  clearObserving(this);
@@ -2520,8 +2546,53 @@
2520
2546
  }
2521
2547
  trace(this, enterBreakPoint);
2522
2548
  };
2523
- return Reaction;
2549
+ return _createClass(Reaction, [{
2550
+ key: "isDisposed",
2551
+ get: function get() {
2552
+ return getFlag(this.flags_, Reaction.isDisposedMask_);
2553
+ },
2554
+ set: function set(newValue) {
2555
+ this.flags_ = setFlag(this.flags_, Reaction.isDisposedMask_, newValue);
2556
+ }
2557
+ }, {
2558
+ key: "isScheduled",
2559
+ get: function get() {
2560
+ return getFlag(this.flags_, Reaction.isScheduledMask_);
2561
+ },
2562
+ set: function set(newValue) {
2563
+ this.flags_ = setFlag(this.flags_, Reaction.isScheduledMask_, newValue);
2564
+ }
2565
+ }, {
2566
+ key: "isTrackPending",
2567
+ get: function get() {
2568
+ return getFlag(this.flags_, Reaction.isTrackPendingMask_);
2569
+ },
2570
+ set: function set(newValue) {
2571
+ this.flags_ = setFlag(this.flags_, Reaction.isTrackPendingMask_, newValue);
2572
+ }
2573
+ }, {
2574
+ key: "isRunning",
2575
+ get: function get() {
2576
+ return getFlag(this.flags_, Reaction.isRunningMask_);
2577
+ },
2578
+ set: function set(newValue) {
2579
+ this.flags_ = setFlag(this.flags_, Reaction.isRunningMask_, newValue);
2580
+ }
2581
+ }, {
2582
+ key: "diffValue",
2583
+ get: function get() {
2584
+ return getFlag(this.flags_, Reaction.diffValueMask_) ? 1 : 0;
2585
+ },
2586
+ set: function set(newValue) {
2587
+ this.flags_ = setFlag(this.flags_, Reaction.diffValueMask_, newValue === 1 ? true : false);
2588
+ }
2589
+ }]);
2524
2590
  }();
2591
+ Reaction.isDisposedMask_ = 1;
2592
+ Reaction.isScheduledMask_ = 2;
2593
+ Reaction.isTrackPendingMask_ = 4;
2594
+ Reaction.isRunningMask_ = 8;
2595
+ Reaction.diffValueMask_ = 16;
2525
2596
  function onReactionError(handler) {
2526
2597
  globalState.globalReactionErrorHandlers.push(handler);
2527
2598
  return function () {
@@ -2715,7 +2786,7 @@
2715
2786
  isScheduled = true;
2716
2787
  scheduler(function () {
2717
2788
  isScheduled = false;
2718
- if (!reaction.isDisposed_) {
2789
+ if (!reaction.isDisposed) {
2719
2790
  reaction.track(reactionRunner);
2720
2791
  }
2721
2792
  });
@@ -2769,7 +2840,7 @@
2769
2840
  }, opts.onError, opts.requiresObservable);
2770
2841
  function reactionRunner() {
2771
2842
  isScheduled = false;
2772
- if (r.isDisposed_) {
2843
+ if (r.isDisposed) {
2773
2844
  return;
2774
2845
  }
2775
2846
  var changed = false;
@@ -3396,7 +3467,7 @@
3396
3467
  if (typeof opts.timeout === "number") {
3397
3468
  var error = new Error("WHEN_TIMEOUT");
3398
3469
  timeoutHandle = setTimeout(function () {
3399
- if (!disposer[$mobx].isDisposed_) {
3470
+ if (!disposer[$mobx].isDisposed) {
3400
3471
  disposer();
3401
3472
  if (opts.onError) {
3402
3473
  opts.onError(error);