mobx 6.9.1 → 6.10.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.
Files changed (42) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/api/autorun.d.ts +2 -1
  3. package/dist/api/makeObservable.d.ts +3 -2
  4. package/dist/api/when.d.ts +1 -8
  5. package/dist/core/atom.d.ts +2 -1
  6. package/dist/core/globalstate.d.ts +5 -0
  7. package/dist/core/reaction.d.ts +2 -2
  8. package/dist/internal.d.ts +1 -0
  9. package/dist/mobx.cjs.development.js +137 -85
  10. package/dist/mobx.cjs.development.js.map +1 -1
  11. package/dist/mobx.cjs.production.min.js +1 -1
  12. package/dist/mobx.cjs.production.min.js.map +1 -1
  13. package/dist/mobx.esm.development.js +137 -85
  14. package/dist/mobx.esm.development.js.map +1 -1
  15. package/dist/mobx.esm.js +137 -85
  16. package/dist/mobx.esm.js.map +1 -1
  17. package/dist/mobx.esm.production.min.js +1 -1
  18. package/dist/mobx.esm.production.min.js.map +1 -1
  19. package/dist/mobx.umd.development.js +137 -85
  20. package/dist/mobx.umd.development.js.map +1 -1
  21. package/dist/mobx.umd.production.min.js +1 -1
  22. package/dist/mobx.umd.production.min.js.map +1 -1
  23. package/dist/types/generic-abort-signal.d.ts +6 -0
  24. package/dist/types/type-utils.d.ts +7 -0
  25. package/package.json +1 -1
  26. package/src/api/autorun.ts +11 -5
  27. package/src/api/extendobservable.ts +6 -9
  28. package/src/api/makeObservable.ts +22 -26
  29. package/src/api/observable.ts +10 -7
  30. package/src/api/when.ts +2 -9
  31. package/src/core/atom.ts +12 -2
  32. package/src/core/globalstate.ts +6 -0
  33. package/src/core/observable.ts +6 -0
  34. package/src/core/reaction.ts +10 -5
  35. package/src/internal.ts +1 -0
  36. package/src/types/generic-abort-signal.ts +7 -0
  37. package/src/types/legacyobservablearray.ts +17 -19
  38. package/src/types/observablearray.ts +12 -13
  39. package/src/types/observablemap.ts +13 -10
  40. package/src/types/observableobject.ts +6 -1
  41. package/src/types/observableset.ts +9 -6
  42. package/src/types/type-utils.ts +26 -1
@@ -422,12 +422,14 @@ var Atom = /*#__PURE__*/function () {
422
422
  this.isPendingUnobservation_ = false;
423
423
  this.isBeingObserved_ = false;
424
424
  this.observers_ = new Set();
425
+ this.batchId_ = void 0;
425
426
  this.diffValue_ = 0;
426
427
  this.lastAccessedBy_ = 0;
427
428
  this.lowestObserverState_ = IDerivationState_.NOT_TRACKING_;
428
429
  this.onBOL = void 0;
429
430
  this.onBUOL = void 0;
430
431
  this.name_ = name_;
432
+ this.batchId_ = globalState.inBatch ? globalState.batchId : NaN;
431
433
  }
432
434
  // onBecomeObservedListeners
433
435
  var _proto = Atom.prototype;
@@ -456,6 +458,12 @@ var Atom = /*#__PURE__*/function () {
456
458
  * Invoke this method _after_ this method has changed to signal mobx that all its observers should invalidate.
457
459
  */;
458
460
  _proto.reportChanged = function reportChanged() {
461
+ if (globalState.inBatch && this.batchId_ === globalState.batchId) {
462
+ // Called from the same batch this atom was created in.
463
+ return;
464
+ }
465
+ // Avoids the possibility of hitting the same globalState.batchId when it cycled through all integers (necessary?)
466
+ this.batchId_ = NaN;
459
467
  startBatch();
460
468
  propagateChanged(this);
461
469
  // We could update state version only at the end of batch,
@@ -989,7 +997,9 @@ var observableFactories = {
989
997
  return new ObservableSet(initialValues, getEnhancerFromOptions(o), o.name);
990
998
  },
991
999
  object: function object(props, decorators, options) {
992
- return extendObservable(globalState.useProxies === false || (options == null ? void 0 : options.proxy) === false ? asObservableObject({}, options) : asDynamicObservableObject({}, options), props, decorators);
1000
+ return initObservable(function () {
1001
+ return extendObservable(globalState.useProxies === false || (options == null ? void 0 : options.proxy) === false ? asObservableObject({}, options) : asDynamicObservableObject({}, options), props, decorators);
1002
+ });
993
1003
  },
994
1004
  ref: /*#__PURE__*/createDecoratorAnnotation(observableRefAnnotation),
995
1005
  shallow: /*#__PURE__*/createDecoratorAnnotation(observableShallowAnnotation),
@@ -1811,6 +1821,7 @@ var MobXGlobals = function MobXGlobals() {
1811
1821
  this.runId = 0;
1812
1822
  this.mobxGuid = 0;
1813
1823
  this.inBatch = 0;
1824
+ this.batchId = Number.MIN_SAFE_INTEGER;
1814
1825
  this.pendingUnobservations = [];
1815
1826
  this.pendingReactions = [];
1816
1827
  this.isRunningReactions = false;
@@ -1950,6 +1961,9 @@ function queueForUnobservation(observable) {
1950
1961
  * Avoids unnecessary recalculations.
1951
1962
  */
1952
1963
  function startBatch() {
1964
+ if (globalState.inBatch === 0) {
1965
+ globalState.batchId = globalState.batchId < Number.MAX_SAFE_INTEGER ? globalState.batchId + 1 : Number.MIN_SAFE_INTEGER;
1966
+ }
1953
1967
  globalState.inBatch++;
1954
1968
  }
1955
1969
  function endBatch() {
@@ -2242,10 +2256,15 @@ var Reaction = /*#__PURE__*/function () {
2242
2256
  }
2243
2257
  }
2244
2258
  };
2245
- _proto.getDisposer_ = function getDisposer_() {
2246
- var r = this.dispose.bind(this);
2247
- r[$mobx] = this;
2248
- return r;
2259
+ _proto.getDisposer_ = function getDisposer_(abortSignal) {
2260
+ var _this2 = this;
2261
+ var dispose = function dispose() {
2262
+ _this2.dispose();
2263
+ abortSignal == null ? void 0 : abortSignal.removeEventListener == null ? void 0 : abortSignal.removeEventListener("abort", dispose);
2264
+ };
2265
+ abortSignal == null ? void 0 : abortSignal.addEventListener == null ? void 0 : abortSignal.addEventListener("abort", dispose);
2266
+ dispose[$mobx] = this;
2267
+ return dispose;
2249
2268
  };
2250
2269
  _proto.toString = function toString() {
2251
2270
  return "Reaction[" + this.name_ + "]";
@@ -2419,7 +2438,7 @@ function isAction(thing) {
2419
2438
  * @returns disposer function, which can be used to stop the view from being updated in the future.
2420
2439
  */
2421
2440
  function autorun(view, opts) {
2422
- var _opts$name, _opts;
2441
+ var _opts$name, _opts, _opts2, _opts2$signal, _opts3;
2423
2442
  if (opts === void 0) {
2424
2443
  opts = EMPTY_OBJECT;
2425
2444
  }
@@ -2458,8 +2477,10 @@ function autorun(view, opts) {
2458
2477
  function reactionRunner() {
2459
2478
  view(reaction);
2460
2479
  }
2461
- reaction.schedule_();
2462
- return reaction.getDisposer_();
2480
+ if (!((_opts2 = opts) != null && (_opts2$signal = _opts2.signal) != null && _opts2$signal.aborted)) {
2481
+ reaction.schedule_();
2482
+ }
2483
+ return reaction.getDisposer_((_opts3 = opts) == null ? void 0 : _opts3.signal);
2463
2484
  }
2464
2485
  var run = function run(f) {
2465
2486
  return f();
@@ -2470,7 +2491,7 @@ function createSchedulerFromOptions(opts) {
2470
2491
  } : run;
2471
2492
  }
2472
2493
  function reaction(expression, effect, opts) {
2473
- var _opts$name2;
2494
+ var _opts$name2, _opts4, _opts4$signal, _opts5;
2474
2495
  if (opts === void 0) {
2475
2496
  opts = EMPTY_OBJECT;
2476
2497
  }
@@ -2520,8 +2541,10 @@ function reaction(expression, effect, opts) {
2520
2541
  }
2521
2542
  firstTime = false;
2522
2543
  }
2523
- r.schedule_();
2524
- return r.getDisposer_();
2544
+ if (!((_opts4 = opts) != null && (_opts4$signal = _opts4.signal) != null && _opts4$signal.aborted)) {
2545
+ r.schedule_();
2546
+ }
2547
+ return r.getDisposer_((_opts5 = opts) == null ? void 0 : _opts5.signal);
2525
2548
  }
2526
2549
  function wrapErrorHandler(errorHandler, baseFn) {
2527
2550
  return function () {
@@ -2616,17 +2639,14 @@ function extendObservable(target, properties, annotations, options) {
2616
2639
  }
2617
2640
  // Pull descriptors first, so we don't have to deal with props added by administration ($mobx)
2618
2641
  var descriptors = getOwnPropertyDescriptors(properties);
2619
- var adm = asObservableObject(target, options)[$mobx];
2620
- startBatch();
2621
- try {
2642
+ initObservable(function () {
2643
+ var adm = asObservableObject(target, options)[$mobx];
2622
2644
  ownKeys(descriptors).forEach(function (key) {
2623
2645
  adm.extend_(key, descriptors[key],
2624
2646
  // must pass "undefined" for { key: undefined }
2625
2647
  !annotations ? true : key in annotations ? annotations[key] : true);
2626
2648
  });
2627
- } finally {
2628
- endBatch();
2629
- }
2649
+ });
2630
2650
  return target;
2631
2651
  }
2632
2652
 
@@ -3312,10 +3332,9 @@ function notifyListeners(listenable, change) {
3312
3332
  }
3313
3333
 
3314
3334
  function makeObservable(target, annotations, options) {
3315
- var adm = asObservableObject(target, options)[$mobx];
3316
- startBatch();
3317
- try {
3335
+ initObservable(function () {
3318
3336
  var _annotations;
3337
+ var adm = asObservableObject(target, options)[$mobx];
3319
3338
  if ("development" !== "production" && annotations && target[storedAnnotationsSymbol]) {
3320
3339
  die("makeObservable second arg must be nullish when using decorators. Mixing @decorator syntax with annotations is not supported.");
3321
3340
  }
@@ -3325,9 +3344,7 @@ function makeObservable(target, annotations, options) {
3325
3344
  ownKeys(annotations).forEach(function (key) {
3326
3345
  return adm.make_(key, annotations[key]);
3327
3346
  });
3328
- } finally {
3329
- endBatch();
3330
- }
3347
+ });
3331
3348
  return target;
3332
3349
  }
3333
3350
  // proto[keysSymbol] = new Set<PropertyKey>()
@@ -3346,26 +3363,23 @@ function makeAutoObservable(target, overrides, options) {
3346
3363
  if (isPlainObject(target)) {
3347
3364
  return extendObservable(target, target, overrides, options);
3348
3365
  }
3349
- var adm = asObservableObject(target, options)[$mobx];
3350
- // Optimization: cache keys on proto
3351
- // Assumes makeAutoObservable can be called only once per object and can't be used in subclass
3352
- if (!target[keysSymbol]) {
3353
- var proto = Object.getPrototypeOf(target);
3354
- var keys = new Set([].concat(ownKeys(target), ownKeys(proto)));
3355
- keys["delete"]("constructor");
3356
- keys["delete"]($mobx);
3357
- addHiddenProp(proto, keysSymbol, keys);
3358
- }
3359
- startBatch();
3360
- try {
3366
+ initObservable(function () {
3367
+ var adm = asObservableObject(target, options)[$mobx];
3368
+ // Optimization: cache keys on proto
3369
+ // Assumes makeAutoObservable can be called only once per object and can't be used in subclass
3370
+ if (!target[keysSymbol]) {
3371
+ var proto = Object.getPrototypeOf(target);
3372
+ var keys = new Set([].concat(ownKeys(target), ownKeys(proto)));
3373
+ keys["delete"]("constructor");
3374
+ keys["delete"]($mobx);
3375
+ addHiddenProp(proto, keysSymbol, keys);
3376
+ }
3361
3377
  target[keysSymbol].forEach(function (key) {
3362
3378
  return adm.make_(key,
3363
3379
  // must pass "undefined" for { key: undefined }
3364
3380
  !overrides ? true : key in overrides ? overrides[key] : true);
3365
3381
  });
3366
- } finally {
3367
- endBatch();
3368
- }
3382
+ });
3369
3383
  return target;
3370
3384
  }
3371
3385
 
@@ -3673,16 +3687,16 @@ function createObservableArray(initialValues, enhancer, name, owned) {
3673
3687
  owned = false;
3674
3688
  }
3675
3689
  assertProxies();
3676
- var adm = new ObservableArrayAdministration(name, enhancer, owned, false);
3677
- addHiddenFinalProp(adm.values_, $mobx, adm);
3678
- var proxy = new Proxy(adm.values_, arrayTraps);
3679
- adm.proxy_ = proxy;
3680
- if (initialValues && initialValues.length) {
3681
- var prev = allowStateChangesStart(true);
3682
- adm.spliceWithArray_(0, 0, initialValues);
3683
- allowStateChangesEnd(prev);
3684
- }
3685
- return proxy;
3690
+ return initObservable(function () {
3691
+ var adm = new ObservableArrayAdministration(name, enhancer, owned, false);
3692
+ addHiddenFinalProp(adm.values_, $mobx, adm);
3693
+ var proxy = new Proxy(adm.values_, arrayTraps);
3694
+ adm.proxy_ = proxy;
3695
+ if (initialValues && initialValues.length) {
3696
+ adm.spliceWithArray_(0, 0, initialValues);
3697
+ }
3698
+ return proxy;
3699
+ });
3686
3700
  }
3687
3701
  // eslint-disable-next-line
3688
3702
  var arrayExtensions = {
@@ -3878,11 +3892,13 @@ var ObservableMap = /*#__PURE__*/function () {
3878
3892
  if (!isFunction(Map)) {
3879
3893
  die(18);
3880
3894
  }
3881
- this.keysAtom_ = createAtom( this.name_ + ".keys()" );
3882
- this.data_ = new Map();
3883
- this.hasMap_ = new Map();
3884
- allowStateChanges(true, function () {
3885
- _this.merge(initialData);
3895
+ initObservable(function () {
3896
+ _this.keysAtom_ = createAtom("development" !== "production" ? _this.name_ + ".keys()" : "ObservableMap.keys()");
3897
+ _this.data_ = new Map();
3898
+ _this.hasMap_ = new Map();
3899
+ if (initialData) {
3900
+ _this.merge(initialData);
3901
+ }
3886
3902
  });
3887
3903
  }
3888
3904
  var _proto = ObservableMap.prototype;
@@ -4266,6 +4282,7 @@ _Symbol$iterator$1 = Symbol.iterator;
4266
4282
  _Symbol$toStringTag$1 = Symbol.toStringTag;
4267
4283
  var ObservableSet = /*#__PURE__*/function () {
4268
4284
  function ObservableSet(initialData, enhancer, name_) {
4285
+ var _this = this;
4269
4286
  if (enhancer === void 0) {
4270
4287
  enhancer = deepEnhancer;
4271
4288
  }
@@ -4284,13 +4301,15 @@ var ObservableSet = /*#__PURE__*/function () {
4284
4301
  if (!isFunction(Set)) {
4285
4302
  die(22);
4286
4303
  }
4287
- this.atom_ = createAtom(this.name_);
4288
4304
  this.enhancer_ = function (newV, oldV) {
4289
4305
  return enhancer(newV, oldV, name_);
4290
4306
  };
4291
- if (initialData) {
4292
- this.replace(initialData);
4293
- }
4307
+ initObservable(function () {
4308
+ _this.atom_ = createAtom(_this.name_);
4309
+ if (initialData) {
4310
+ _this.replace(initialData);
4311
+ }
4312
+ });
4294
4313
  }
4295
4314
  var _proto = ObservableSet.prototype;
4296
4315
  _proto.dehanceValue_ = function dehanceValue_(value) {
@@ -4300,12 +4319,12 @@ var ObservableSet = /*#__PURE__*/function () {
4300
4319
  return value;
4301
4320
  };
4302
4321
  _proto.clear = function clear() {
4303
- var _this = this;
4322
+ var _this2 = this;
4304
4323
  transaction(function () {
4305
4324
  untracked(function () {
4306
- for (var _iterator = _createForOfIteratorHelperLoose(_this.data_.values()), _step; !(_step = _iterator()).done;) {
4325
+ for (var _iterator = _createForOfIteratorHelperLoose(_this2.data_.values()), _step; !(_step = _iterator()).done;) {
4307
4326
  var value = _step.value;
4308
- _this["delete"](value);
4327
+ _this2["delete"](value);
4309
4328
  }
4310
4329
  });
4311
4330
  });
@@ -4317,7 +4336,7 @@ var ObservableSet = /*#__PURE__*/function () {
4317
4336
  }
4318
4337
  };
4319
4338
  _proto.add = function add(value) {
4320
- var _this2 = this;
4339
+ var _this3 = this;
4321
4340
  checkIfStateModificationsAreAllowed(this.atom_);
4322
4341
  if (hasInterceptors(this)) {
4323
4342
  var change = interceptChange(this, {
@@ -4334,8 +4353,8 @@ var ObservableSet = /*#__PURE__*/function () {
4334
4353
 
4335
4354
  if (!this.has(value)) {
4336
4355
  transaction(function () {
4337
- _this2.data_.add(_this2.enhancer_(value, undefined));
4338
- _this2.atom_.reportChanged();
4356
+ _this3.data_.add(_this3.enhancer_(value, undefined));
4357
+ _this3.atom_.reportChanged();
4339
4358
  });
4340
4359
  var notifySpy = isSpyEnabled();
4341
4360
  var notify = hasListeners(this);
@@ -4359,7 +4378,7 @@ var ObservableSet = /*#__PURE__*/function () {
4359
4378
  return this;
4360
4379
  };
4361
4380
  _proto["delete"] = function _delete(value) {
4362
- var _this3 = this;
4381
+ var _this4 = this;
4363
4382
  if (hasInterceptors(this)) {
4364
4383
  var change = interceptChange(this, {
4365
4384
  type: DELETE,
@@ -4384,8 +4403,8 @@ var ObservableSet = /*#__PURE__*/function () {
4384
4403
  spyReportStart(_change2);
4385
4404
  }
4386
4405
  transaction(function () {
4387
- _this3.atom_.reportChanged();
4388
- _this3.data_["delete"](value);
4406
+ _this4.atom_.reportChanged();
4407
+ _this4.data_["delete"](value);
4389
4408
  });
4390
4409
  if (notify) {
4391
4410
  notifyListeners(this, _change2);
@@ -4438,20 +4457,20 @@ var ObservableSet = /*#__PURE__*/function () {
4438
4457
  });
4439
4458
  };
4440
4459
  _proto.replace = function replace(other) {
4441
- var _this4 = this;
4460
+ var _this5 = this;
4442
4461
  if (isObservableSet(other)) {
4443
4462
  other = new Set(other);
4444
4463
  }
4445
4464
  transaction(function () {
4446
4465
  if (Array.isArray(other)) {
4447
- _this4.clear();
4466
+ _this5.clear();
4448
4467
  other.forEach(function (value) {
4449
- return _this4.add(value);
4468
+ return _this5.add(value);
4450
4469
  });
4451
4470
  } else if (isES6Set(other)) {
4452
- _this4.clear();
4471
+ _this5.clear();
4453
4472
  other.forEach(function (value) {
4454
- return _this4.add(value);
4473
+ return _this5.add(value);
4455
4474
  });
4456
4475
  } else if (other !== null && other !== undefined) {
4457
4476
  die("Cannot initialize set from " + other);
@@ -4715,6 +4734,7 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
4715
4734
  if (proxyTrap === void 0) {
4716
4735
  proxyTrap = false;
4717
4736
  }
4737
+ checkIfStateModificationsAreAllowed(this.keysAtom_);
4718
4738
  try {
4719
4739
  startBatch();
4720
4740
  // Delete
@@ -4762,6 +4782,7 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
4762
4782
  if (proxyTrap === void 0) {
4763
4783
  proxyTrap = false;
4764
4784
  }
4785
+ checkIfStateModificationsAreAllowed(this.keysAtom_);
4765
4786
  try {
4766
4787
  startBatch();
4767
4788
  // Delete
@@ -4813,6 +4834,7 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
4813
4834
  if (proxyTrap === void 0) {
4814
4835
  proxyTrap = false;
4815
4836
  }
4837
+ checkIfStateModificationsAreAllowed(this.keysAtom_);
4816
4838
  try {
4817
4839
  startBatch();
4818
4840
  // Delete
@@ -4868,6 +4890,7 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
4868
4890
  if (proxyTrap === void 0) {
4869
4891
  proxyTrap = false;
4870
4892
  }
4893
+ checkIfStateModificationsAreAllowed(this.keysAtom_);
4871
4894
  // No such prop
4872
4895
  if (!hasProp(this.target_, key)) {
4873
4896
  return true;
@@ -5097,6 +5120,17 @@ function assertAnnotable(adm, annotation, key) {
5097
5120
 
5098
5121
  // Bug in safari 9.* (or iOS 9 safari mobile). See #364
5099
5122
  var ENTRY_0 = /*#__PURE__*/createArrayEntryDescriptor(0);
5123
+ var safariPrototypeSetterInheritanceBug = /*#__PURE__*/function () {
5124
+ var v = false;
5125
+ var p = {};
5126
+ Object.defineProperty(p, "0", {
5127
+ set: function set() {
5128
+ v = true;
5129
+ }
5130
+ });
5131
+ /*#__PURE__*/Object.create(p)["0"] = 1;
5132
+ return v === false;
5133
+ }();
5100
5134
  /**
5101
5135
  * This array buffer contains two lists of properties, so that all arrays
5102
5136
  * can recycle their property definitions, which significantly improves performance of creating
@@ -5129,20 +5163,20 @@ var LegacyObservableArray = /*#__PURE__*/function (_StubArray, _Symbol$toStringT
5129
5163
  owned = false;
5130
5164
  }
5131
5165
  _this = _StubArray.call(this) || this;
5132
- var adm = new ObservableArrayAdministration(name, enhancer, owned, true);
5133
- adm.proxy_ = _assertThisInitialized(_this);
5134
- addHiddenFinalProp(_assertThisInitialized(_this), $mobx, adm);
5135
- if (initialValues && initialValues.length) {
5136
- var prev = allowStateChangesStart(true);
5137
- // @ts-ignore
5138
- _this.spliceWithArray(0, 0, initialValues);
5139
- allowStateChangesEnd(prev);
5140
- }
5141
- {
5142
- // Seems that Safari won't use numeric prototype setter untill any * numeric property is
5143
- // defined on the instance. After that it works fine, even if this property is deleted.
5144
- Object.defineProperty(_assertThisInitialized(_this), "0", ENTRY_0);
5145
- }
5166
+ initObservable(function () {
5167
+ var adm = new ObservableArrayAdministration(name, enhancer, owned, true);
5168
+ adm.proxy_ = _assertThisInitialized(_this);
5169
+ addHiddenFinalProp(_assertThisInitialized(_this), $mobx, adm);
5170
+ if (initialValues && initialValues.length) {
5171
+ // @ts-ignore
5172
+ _this.spliceWithArray(0, 0, initialValues);
5173
+ }
5174
+ if (safariPrototypeSetterInheritanceBug) {
5175
+ // Seems that Safari won't use numeric prototype setter untill any * numeric property is
5176
+ // defined on the instance. After that it works fine, even if this property is deleted.
5177
+ Object.defineProperty(_assertThisInitialized(_this), "0", ENTRY_0);
5178
+ }
5179
+ });
5146
5180
  return _this;
5147
5181
  }
5148
5182
  var _proto = LegacyObservableArray.prototype;
@@ -5297,6 +5331,24 @@ function getDebugName(thing, property) {
5297
5331
  }
5298
5332
  return named.name_;
5299
5333
  }
5334
+ /**
5335
+ * Helper function for initializing observable structures, it applies:
5336
+ * 1. allowStateChanges so we don't violate enforceActions.
5337
+ * 2. untracked so we don't accidentaly subscribe to anything observable accessed during init in case the observable is created inside derivation.
5338
+ * 3. batch to avoid state version updates
5339
+ */
5340
+ function initObservable(cb) {
5341
+ var derivation = untrackedStart();
5342
+ var allowStateChanges = allowStateChangesStart(true);
5343
+ startBatch();
5344
+ try {
5345
+ return cb();
5346
+ } finally {
5347
+ endBatch();
5348
+ allowStateChangesEnd(allowStateChanges);
5349
+ untrackedEnd(derivation);
5350
+ }
5351
+ }
5300
5352
 
5301
5353
  var toString = objectPrototype.toString;
5302
5354
  function deepEqual(a, b, depth) {