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.
@@ -202,15 +202,24 @@ function createInstanceofPredicate(name, theClass) {
202
202
  return isObject(x) && x[propName] === true;
203
203
  };
204
204
  }
205
+ /**
206
+ * Yields true for both native and observable Map, even across different windows.
207
+ */
205
208
  function isES6Map(thing) {
206
209
  return thing != null && Object.prototype.toString.call(thing) === "[object Map]";
207
210
  }
211
+ /**
212
+ * Makes sure a Map is an instance of non-inherited native or observable Map.
213
+ */
208
214
  function isPlainES6Map(thing) {
209
215
  var mapProto = Object.getPrototypeOf(thing);
210
216
  var objectProto = Object.getPrototypeOf(mapProto);
211
217
  var nullProto = Object.getPrototypeOf(objectProto);
212
218
  return nullProto === null;
213
219
  }
220
+ /**
221
+ * Yields true for both native and observable Set, even across different windows.
222
+ */
214
223
  function isES6Set(thing) {
215
224
  return thing != null && Object.prototype.toString.call(thing) === "[object Set]";
216
225
  }
@@ -262,6 +271,17 @@ var getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors || function get
262
271
  });
263
272
  return res;
264
273
  };
274
+ function getFlag(flags, mask) {
275
+ return !!(flags & mask);
276
+ }
277
+ function setFlag(flags, mask, newValue) {
278
+ if (newValue) {
279
+ flags |= mask;
280
+ } else {
281
+ flags &= ~mask;
282
+ }
283
+ return flags;
284
+ }
265
285
 
266
286
  function _arrayLikeToArray(r, a) {
267
287
  (null == a || a > r.length) && (a = r.length);
@@ -414,11 +434,8 @@ var Atom = /*#__PURE__*/function () {
414
434
  name_ = "Atom@" + getNextId() ;
415
435
  }
416
436
  this.name_ = void 0;
417
- this.isPendingUnobservation = false;
418
- // for effective unobserving. BaseAtom has true, for extra optimization, so its onBecomeUnobserved never gets called, because it's not needed
419
- this.isBeingObserved = false;
437
+ this.flags_ = 0;
420
438
  this.observers_ = new Set();
421
- this.diffValue_ = 0;
422
439
  this.lastAccessedBy_ = 0;
423
440
  this.lowestObserverState_ = IDerivationState_.NOT_TRACKING_;
424
441
  // onBecomeObservedListeners
@@ -427,6 +444,7 @@ var Atom = /*#__PURE__*/function () {
427
444
  this.onBUOL = void 0;
428
445
  this.name_ = name_;
429
446
  }
447
+ // for effective unobserving. BaseAtom has true, for extra optimization, so its onBecomeUnobserved never gets called, because it's not needed
430
448
  var _proto = Atom.prototype;
431
449
  _proto.onBO = function onBO() {
432
450
  if (this.onBOL) {
@@ -460,8 +478,35 @@ var Atom = /*#__PURE__*/function () {
460
478
  _proto.toString = function toString() {
461
479
  return this.name_;
462
480
  };
463
- return Atom;
481
+ return _createClass(Atom, [{
482
+ key: "isBeingObserved",
483
+ get: function get() {
484
+ return getFlag(this.flags_, Atom.isBeingObservedMask_);
485
+ },
486
+ set: function set(newValue) {
487
+ this.flags_ = setFlag(this.flags_, Atom.isBeingObservedMask_, newValue);
488
+ }
489
+ }, {
490
+ key: "isPendingUnobservation",
491
+ get: function get() {
492
+ return getFlag(this.flags_, Atom.isPendingUnobservationMask_);
493
+ },
494
+ set: function set(newValue) {
495
+ this.flags_ = setFlag(this.flags_, Atom.isPendingUnobservationMask_, newValue);
496
+ }
497
+ }, {
498
+ key: "diffValue",
499
+ get: function get() {
500
+ return getFlag(this.flags_, Atom.diffValueMask_) ? 1 : 0;
501
+ },
502
+ set: function set(newValue) {
503
+ this.flags_ = setFlag(this.flags_, Atom.diffValueMask_, newValue === 1 ? true : false);
504
+ }
505
+ }]);
464
506
  }();
507
+ Atom.isBeingObservedMask_ = 1;
508
+ Atom.isPendingUnobservationMask_ = 2;
509
+ Atom.diffValueMask_ = 4;
465
510
  var isAtom = /*#__PURE__*/createInstanceofPredicate("Atom", Atom);
466
511
  function createAtom(name, onBecomeObservedHandler, onBecomeUnobservedHandler) {
467
512
  if (onBecomeObservedHandler === void 0) {
@@ -1429,17 +1474,6 @@ var ObservableValue = /*#__PURE__*/function (_Atom) {
1429
1474
  }(Atom);
1430
1475
  var isObservableValue = /*#__PURE__*/createInstanceofPredicate("ObservableValue", ObservableValue);
1431
1476
 
1432
- function getFlag(flags, mask) {
1433
- return !!(flags & mask);
1434
- }
1435
- function setFlag(flags, mask, newValue) {
1436
- if (newValue) {
1437
- flags |= mask;
1438
- } else {
1439
- flags &= ~mask;
1440
- }
1441
- return flags;
1442
- }
1443
1477
  /**
1444
1478
  * A node in the state dependency root that observes other nodes, and can be observed itself.
1445
1479
  *
@@ -1479,7 +1513,6 @@ var ComputedValue = /*#__PURE__*/function () {
1479
1513
  this.newObserving_ = null;
1480
1514
  // during tracking it's an array with new observed observers
1481
1515
  this.observers_ = new Set();
1482
- this.diffValue_ = 0;
1483
1516
  this.runId_ = 0;
1484
1517
  this.lastAccessedBy_ = 0;
1485
1518
  this.lowestObserverState_ = IDerivationState_.UP_TO_DATE_;
@@ -1706,12 +1739,21 @@ var ComputedValue = /*#__PURE__*/function () {
1706
1739
  set: function set(newValue) {
1707
1740
  this.flags_ = setFlag(this.flags_, ComputedValue.isPendingUnobservationMask_, newValue);
1708
1741
  }
1742
+ }, {
1743
+ key: "diffValue",
1744
+ get: function get() {
1745
+ return getFlag(this.flags_, ComputedValue.diffValueMask_) ? 1 : 0;
1746
+ },
1747
+ set: function set(newValue) {
1748
+ this.flags_ = setFlag(this.flags_, ComputedValue.diffValueMask_, newValue === 1 ? true : false);
1749
+ }
1709
1750
  }]);
1710
1751
  }();
1711
1752
  ComputedValue.isComputingMask_ = 1;
1712
1753
  ComputedValue.isRunningSetterMask_ = 2;
1713
1754
  ComputedValue.isBeingObservedMask_ = 4;
1714
1755
  ComputedValue.isPendingUnobservationMask_ = 8;
1756
+ ComputedValue.diffValueMask_ = 16;
1715
1757
  var isComputedValue = /*#__PURE__*/createInstanceofPredicate("ComputedValue", ComputedValue);
1716
1758
 
1717
1759
  var IDerivationState_;
@@ -1880,8 +1922,8 @@ function bindDependencies(derivation) {
1880
1922
  l = derivation.unboundDepsCount_;
1881
1923
  for (var i = 0; i < l; i++) {
1882
1924
  var dep = observing[i];
1883
- if (dep.diffValue_ === 0) {
1884
- dep.diffValue_ = 1;
1925
+ if (dep.diffValue === 0) {
1926
+ dep.diffValue = 1;
1885
1927
  if (i0 !== i) {
1886
1928
  observing[i0] = dep;
1887
1929
  }
@@ -1901,18 +1943,18 @@ function bindDependencies(derivation) {
1901
1943
  l = prevObserving.length;
1902
1944
  while (l--) {
1903
1945
  var _dep = prevObserving[l];
1904
- if (_dep.diffValue_ === 0) {
1946
+ if (_dep.diffValue === 0) {
1905
1947
  removeObserver(_dep, derivation);
1906
1948
  }
1907
- _dep.diffValue_ = 0;
1949
+ _dep.diffValue = 0;
1908
1950
  }
1909
1951
  // Go through all new observables and check diffValue: (now it should be unique)
1910
1952
  // 0: it was set to 0 in last loop. don't need to do anything.
1911
1953
  // 1: it wasn't observed, let's observe it. set back to 0
1912
1954
  while (i0--) {
1913
1955
  var _dep2 = observing[i0];
1914
- if (_dep2.diffValue_ === 1) {
1915
- _dep2.diffValue_ = 0;
1956
+ if (_dep2.diffValue === 1) {
1957
+ _dep2.diffValue = 0;
1916
1958
  addObserver(_dep2, derivation);
1917
1959
  }
1918
1960
  }
@@ -2365,13 +2407,9 @@ var Reaction = /*#__PURE__*/function () {
2365
2407
  // nodes we are looking at. Our value depends on these nodes
2366
2408
  this.newObserving_ = [];
2367
2409
  this.dependenciesState_ = IDerivationState_.NOT_TRACKING_;
2368
- this.diffValue_ = 0;
2369
2410
  this.runId_ = 0;
2370
2411
  this.unboundDepsCount_ = 0;
2371
- this.isDisposed_ = false;
2372
- this.isScheduled_ = false;
2373
- this.isTrackPending_ = false;
2374
- this.isRunning_ = false;
2412
+ this.flags_ = 0;
2375
2413
  this.isTracing_ = TraceMode.NONE;
2376
2414
  this.name_ = name_;
2377
2415
  this.onInvalidate_ = onInvalidate_;
@@ -2383,29 +2421,26 @@ var Reaction = /*#__PURE__*/function () {
2383
2421
  this.schedule_();
2384
2422
  };
2385
2423
  _proto.schedule_ = function schedule_() {
2386
- if (!this.isScheduled_) {
2387
- this.isScheduled_ = true;
2424
+ if (!this.isScheduled) {
2425
+ this.isScheduled = true;
2388
2426
  globalState.pendingReactions.push(this);
2389
2427
  runReactions();
2390
2428
  }
2391
- };
2392
- _proto.isScheduled = function isScheduled() {
2393
- return this.isScheduled_;
2394
2429
  }
2395
2430
  /**
2396
2431
  * internal, use schedule() if you intend to kick off a reaction
2397
2432
  */;
2398
2433
  _proto.runReaction_ = function runReaction_() {
2399
- if (!this.isDisposed_) {
2434
+ if (!this.isDisposed) {
2400
2435
  startBatch();
2401
- this.isScheduled_ = false;
2436
+ this.isScheduled = false;
2402
2437
  var prev = globalState.trackingContext;
2403
2438
  globalState.trackingContext = this;
2404
2439
  if (shouldCompute(this)) {
2405
- this.isTrackPending_ = true;
2440
+ this.isTrackPending = true;
2406
2441
  try {
2407
2442
  this.onInvalidate_();
2408
- if ("development" !== "production" && this.isTrackPending_ && isSpyEnabled()) {
2443
+ if ("development" !== "production" && this.isTrackPending && isSpyEnabled()) {
2409
2444
  // onInvalidate didn't trigger track right away..
2410
2445
  spyReport({
2411
2446
  name: this.name_,
@@ -2421,7 +2456,7 @@ var Reaction = /*#__PURE__*/function () {
2421
2456
  }
2422
2457
  };
2423
2458
  _proto.track = function track(fn) {
2424
- if (this.isDisposed_) {
2459
+ if (this.isDisposed) {
2425
2460
  return;
2426
2461
  // console.warn("Reaction already disposed") // Note: Not a warning / error in mobx 4 either
2427
2462
  }
@@ -2435,14 +2470,14 @@ var Reaction = /*#__PURE__*/function () {
2435
2470
  type: "reaction"
2436
2471
  });
2437
2472
  }
2438
- this.isRunning_ = true;
2473
+ this.isRunning = true;
2439
2474
  var prevReaction = globalState.trackingContext; // reactions could create reactions...
2440
2475
  globalState.trackingContext = this;
2441
2476
  var result = trackDerivedFunction(this, fn, undefined);
2442
2477
  globalState.trackingContext = prevReaction;
2443
- this.isRunning_ = false;
2444
- this.isTrackPending_ = false;
2445
- if (this.isDisposed_) {
2478
+ this.isRunning = false;
2479
+ this.isTrackPending = false;
2480
+ if (this.isDisposed) {
2446
2481
  // disposed during last run. Clean up everything that was bound after the dispose call.
2447
2482
  clearObserving(this);
2448
2483
  }
@@ -2485,9 +2520,9 @@ var Reaction = /*#__PURE__*/function () {
2485
2520
  });
2486
2521
  };
2487
2522
  _proto.dispose = function dispose() {
2488
- if (!this.isDisposed_) {
2489
- this.isDisposed_ = true;
2490
- if (!this.isRunning_) {
2523
+ if (!this.isDisposed) {
2524
+ this.isDisposed = true;
2525
+ if (!this.isRunning) {
2491
2526
  // if disposed while running, clean up later. Maybe not optimal, but rare case
2492
2527
  startBatch();
2493
2528
  clearObserving(this);
@@ -2514,8 +2549,53 @@ var Reaction = /*#__PURE__*/function () {
2514
2549
  }
2515
2550
  trace(this, enterBreakPoint);
2516
2551
  };
2517
- return Reaction;
2552
+ return _createClass(Reaction, [{
2553
+ key: "isDisposed",
2554
+ get: function get() {
2555
+ return getFlag(this.flags_, Reaction.isDisposedMask_);
2556
+ },
2557
+ set: function set(newValue) {
2558
+ this.flags_ = setFlag(this.flags_, Reaction.isDisposedMask_, newValue);
2559
+ }
2560
+ }, {
2561
+ key: "isScheduled",
2562
+ get: function get() {
2563
+ return getFlag(this.flags_, Reaction.isScheduledMask_);
2564
+ },
2565
+ set: function set(newValue) {
2566
+ this.flags_ = setFlag(this.flags_, Reaction.isScheduledMask_, newValue);
2567
+ }
2568
+ }, {
2569
+ key: "isTrackPending",
2570
+ get: function get() {
2571
+ return getFlag(this.flags_, Reaction.isTrackPendingMask_);
2572
+ },
2573
+ set: function set(newValue) {
2574
+ this.flags_ = setFlag(this.flags_, Reaction.isTrackPendingMask_, newValue);
2575
+ }
2576
+ }, {
2577
+ key: "isRunning",
2578
+ get: function get() {
2579
+ return getFlag(this.flags_, Reaction.isRunningMask_);
2580
+ },
2581
+ set: function set(newValue) {
2582
+ this.flags_ = setFlag(this.flags_, Reaction.isRunningMask_, newValue);
2583
+ }
2584
+ }, {
2585
+ key: "diffValue",
2586
+ get: function get() {
2587
+ return getFlag(this.flags_, Reaction.diffValueMask_) ? 1 : 0;
2588
+ },
2589
+ set: function set(newValue) {
2590
+ this.flags_ = setFlag(this.flags_, Reaction.diffValueMask_, newValue === 1 ? true : false);
2591
+ }
2592
+ }]);
2518
2593
  }();
2594
+ Reaction.isDisposedMask_ = 1;
2595
+ Reaction.isScheduledMask_ = 2;
2596
+ Reaction.isTrackPendingMask_ = 4;
2597
+ Reaction.isRunningMask_ = 8;
2598
+ Reaction.diffValueMask_ = 16;
2519
2599
  function onReactionError(handler) {
2520
2600
  globalState.globalReactionErrorHandlers.push(handler);
2521
2601
  return function () {
@@ -2709,7 +2789,7 @@ function autorun(view, opts) {
2709
2789
  isScheduled = true;
2710
2790
  scheduler(function () {
2711
2791
  isScheduled = false;
2712
- if (!reaction.isDisposed_) {
2792
+ if (!reaction.isDisposed) {
2713
2793
  reaction.track(reactionRunner);
2714
2794
  }
2715
2795
  });
@@ -2763,7 +2843,7 @@ function reaction(expression, effect, opts) {
2763
2843
  }, opts.onError, opts.requiresObservable);
2764
2844
  function reactionRunner() {
2765
2845
  isScheduled = false;
2766
- if (r.isDisposed_) {
2846
+ if (r.isDisposed) {
2767
2847
  return;
2768
2848
  }
2769
2849
  var changed = false;
@@ -3390,7 +3470,7 @@ function _when(predicate, effect, opts) {
3390
3470
  if (typeof opts.timeout === "number") {
3391
3471
  var error = new Error("WHEN_TIMEOUT");
3392
3472
  timeoutHandle = setTimeout(function () {
3393
- if (!disposer[$mobx].isDisposed_) {
3473
+ if (!disposer[$mobx].isDisposed) {
3394
3474
  disposer();
3395
3475
  if (opts.onError) {
3396
3476
  opts.onError(error);
@@ -4696,7 +4776,7 @@ var ObservableSet = /*#__PURE__*/function () {
4696
4776
  });
4697
4777
  };
4698
4778
  _proto.intersection = function intersection(otherSet) {
4699
- if (isES6Set(otherSet)) {
4779
+ if (isES6Set(otherSet) && !isObservableSet(otherSet)) {
4700
4780
  return otherSet.intersection(this);
4701
4781
  } else {
4702
4782
  var dehancedSet = new Set(this);
@@ -4704,7 +4784,7 @@ var ObservableSet = /*#__PURE__*/function () {
4704
4784
  }
4705
4785
  };
4706
4786
  _proto.union = function union(otherSet) {
4707
- if (isES6Set(otherSet)) {
4787
+ if (isES6Set(otherSet) && !isObservableSet(otherSet)) {
4708
4788
  return otherSet.union(this);
4709
4789
  } else {
4710
4790
  var dehancedSet = new Set(this);
@@ -4715,7 +4795,7 @@ var ObservableSet = /*#__PURE__*/function () {
4715
4795
  return new Set(this).difference(otherSet);
4716
4796
  };
4717
4797
  _proto.symmetricDifference = function symmetricDifference(otherSet) {
4718
- if (isES6Set(otherSet)) {
4798
+ if (isES6Set(otherSet) && !isObservableSet(otherSet)) {
4719
4799
  return otherSet.symmetricDifference(this);
4720
4800
  } else {
4721
4801
  var dehancedSet = new Set(this);
@@ -4729,7 +4809,7 @@ var ObservableSet = /*#__PURE__*/function () {
4729
4809
  return new Set(this).isSupersetOf(otherSet);
4730
4810
  };
4731
4811
  _proto.isDisjointFrom = function isDisjointFrom(otherSet) {
4732
- if (isES6Set(otherSet)) {
4812
+ if (isES6Set(otherSet) && !isObservableSet(otherSet)) {
4733
4813
  return otherSet.isDisjointFrom(this);
4734
4814
  } else {
4735
4815
  var dehancedSet = new Set(this);