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
package/dist/mobx.esm.js CHANGED
@@ -423,12 +423,14 @@ var Atom = /*#__PURE__*/function () {
423
423
  this.isPendingUnobservation_ = false;
424
424
  this.isBeingObserved_ = false;
425
425
  this.observers_ = new Set();
426
+ this.batchId_ = void 0;
426
427
  this.diffValue_ = 0;
427
428
  this.lastAccessedBy_ = 0;
428
429
  this.lowestObserverState_ = IDerivationState_.NOT_TRACKING_;
429
430
  this.onBOL = void 0;
430
431
  this.onBUOL = void 0;
431
432
  this.name_ = name_;
433
+ this.batchId_ = globalState.inBatch ? globalState.batchId : NaN;
432
434
  }
433
435
  // onBecomeObservedListeners
434
436
  var _proto = Atom.prototype;
@@ -457,6 +459,12 @@ var Atom = /*#__PURE__*/function () {
457
459
  * Invoke this method _after_ this method has changed to signal mobx that all its observers should invalidate.
458
460
  */;
459
461
  _proto.reportChanged = function reportChanged() {
462
+ if (globalState.inBatch && this.batchId_ === globalState.batchId) {
463
+ // Called from the same batch this atom was created in.
464
+ return;
465
+ }
466
+ // Avoids the possibility of hitting the same globalState.batchId when it cycled through all integers (necessary?)
467
+ this.batchId_ = NaN;
460
468
  startBatch();
461
469
  propagateChanged(this);
462
470
  // We could update state version only at the end of batch,
@@ -990,7 +998,9 @@ var observableFactories = {
990
998
  return new ObservableSet(initialValues, getEnhancerFromOptions(o), o.name);
991
999
  },
992
1000
  object: function object(props, decorators, options) {
993
- return extendObservable(globalState.useProxies === false || (options == null ? void 0 : options.proxy) === false ? asObservableObject({}, options) : asDynamicObservableObject({}, options), props, decorators);
1001
+ return initObservable(function () {
1002
+ return extendObservable(globalState.useProxies === false || (options == null ? void 0 : options.proxy) === false ? asObservableObject({}, options) : asDynamicObservableObject({}, options), props, decorators);
1003
+ });
994
1004
  },
995
1005
  ref: /*#__PURE__*/createDecoratorAnnotation(observableRefAnnotation),
996
1006
  shallow: /*#__PURE__*/createDecoratorAnnotation(observableShallowAnnotation),
@@ -1821,6 +1831,7 @@ var MobXGlobals = function MobXGlobals() {
1821
1831
  this.runId = 0;
1822
1832
  this.mobxGuid = 0;
1823
1833
  this.inBatch = 0;
1834
+ this.batchId = Number.MIN_SAFE_INTEGER;
1824
1835
  this.pendingUnobservations = [];
1825
1836
  this.pendingReactions = [];
1826
1837
  this.isRunningReactions = false;
@@ -1960,6 +1971,9 @@ function queueForUnobservation(observable) {
1960
1971
  * Avoids unnecessary recalculations.
1961
1972
  */
1962
1973
  function startBatch() {
1974
+ if (globalState.inBatch === 0) {
1975
+ globalState.batchId = globalState.batchId < Number.MAX_SAFE_INTEGER ? globalState.batchId + 1 : Number.MIN_SAFE_INTEGER;
1976
+ }
1963
1977
  globalState.inBatch++;
1964
1978
  }
1965
1979
  function endBatch() {
@@ -2252,10 +2266,15 @@ var Reaction = /*#__PURE__*/function () {
2252
2266
  }
2253
2267
  }
2254
2268
  };
2255
- _proto.getDisposer_ = function getDisposer_() {
2256
- var r = this.dispose.bind(this);
2257
- r[$mobx] = this;
2258
- return r;
2269
+ _proto.getDisposer_ = function getDisposer_(abortSignal) {
2270
+ var _this2 = this;
2271
+ var dispose = function dispose() {
2272
+ _this2.dispose();
2273
+ abortSignal == null ? void 0 : abortSignal.removeEventListener == null ? void 0 : abortSignal.removeEventListener("abort", dispose);
2274
+ };
2275
+ abortSignal == null ? void 0 : abortSignal.addEventListener == null ? void 0 : abortSignal.addEventListener("abort", dispose);
2276
+ dispose[$mobx] = this;
2277
+ return dispose;
2259
2278
  };
2260
2279
  _proto.toString = function toString() {
2261
2280
  return "Reaction[" + this.name_ + "]";
@@ -2441,7 +2460,7 @@ function isAction(thing) {
2441
2460
  * @returns disposer function, which can be used to stop the view from being updated in the future.
2442
2461
  */
2443
2462
  function autorun(view, opts) {
2444
- var _opts$name, _opts;
2463
+ var _opts$name, _opts, _opts2, _opts2$signal, _opts3;
2445
2464
  if (opts === void 0) {
2446
2465
  opts = EMPTY_OBJECT;
2447
2466
  }
@@ -2480,8 +2499,10 @@ function autorun(view, opts) {
2480
2499
  function reactionRunner() {
2481
2500
  view(reaction);
2482
2501
  }
2483
- reaction.schedule_();
2484
- return reaction.getDisposer_();
2502
+ if (!((_opts2 = opts) != null && (_opts2$signal = _opts2.signal) != null && _opts2$signal.aborted)) {
2503
+ reaction.schedule_();
2504
+ }
2505
+ return reaction.getDisposer_((_opts3 = opts) == null ? void 0 : _opts3.signal);
2485
2506
  }
2486
2507
  var run = function run(f) {
2487
2508
  return f();
@@ -2492,7 +2513,7 @@ function createSchedulerFromOptions(opts) {
2492
2513
  } : run;
2493
2514
  }
2494
2515
  function reaction(expression, effect, opts) {
2495
- var _opts$name2;
2516
+ var _opts$name2, _opts4, _opts4$signal, _opts5;
2496
2517
  if (opts === void 0) {
2497
2518
  opts = EMPTY_OBJECT;
2498
2519
  }
@@ -2542,8 +2563,10 @@ function reaction(expression, effect, opts) {
2542
2563
  }
2543
2564
  firstTime = false;
2544
2565
  }
2545
- r.schedule_();
2546
- return r.getDisposer_();
2566
+ if (!((_opts4 = opts) != null && (_opts4$signal = _opts4.signal) != null && _opts4$signal.aborted)) {
2567
+ r.schedule_();
2568
+ }
2569
+ return r.getDisposer_((_opts5 = opts) == null ? void 0 : _opts5.signal);
2547
2570
  }
2548
2571
  function wrapErrorHandler(errorHandler, baseFn) {
2549
2572
  return function () {
@@ -2638,17 +2661,14 @@ function extendObservable(target, properties, annotations, options) {
2638
2661
  }
2639
2662
  // Pull descriptors first, so we don't have to deal with props added by administration ($mobx)
2640
2663
  var descriptors = getOwnPropertyDescriptors(properties);
2641
- var adm = asObservableObject(target, options)[$mobx];
2642
- startBatch();
2643
- try {
2664
+ initObservable(function () {
2665
+ var adm = asObservableObject(target, options)[$mobx];
2644
2666
  ownKeys(descriptors).forEach(function (key) {
2645
2667
  adm.extend_(key, descriptors[key],
2646
2668
  // must pass "undefined" for { key: undefined }
2647
2669
  !annotations ? true : key in annotations ? annotations[key] : true);
2648
2670
  });
2649
- } finally {
2650
- endBatch();
2651
- }
2671
+ });
2652
2672
  return target;
2653
2673
  }
2654
2674
 
@@ -3337,10 +3357,9 @@ function notifyListeners(listenable, change) {
3337
3357
  }
3338
3358
 
3339
3359
  function makeObservable(target, annotations, options) {
3340
- var adm = asObservableObject(target, options)[$mobx];
3341
- startBatch();
3342
- try {
3360
+ initObservable(function () {
3343
3361
  var _annotations;
3362
+ var adm = asObservableObject(target, options)[$mobx];
3344
3363
  if (process.env.NODE_ENV !== "production" && annotations && target[storedAnnotationsSymbol]) {
3345
3364
  die("makeObservable second arg must be nullish when using decorators. Mixing @decorator syntax with annotations is not supported.");
3346
3365
  }
@@ -3350,9 +3369,7 @@ function makeObservable(target, annotations, options) {
3350
3369
  ownKeys(annotations).forEach(function (key) {
3351
3370
  return adm.make_(key, annotations[key]);
3352
3371
  });
3353
- } finally {
3354
- endBatch();
3355
- }
3372
+ });
3356
3373
  return target;
3357
3374
  }
3358
3375
  // proto[keysSymbol] = new Set<PropertyKey>()
@@ -3371,26 +3388,23 @@ function makeAutoObservable(target, overrides, options) {
3371
3388
  if (isPlainObject(target)) {
3372
3389
  return extendObservable(target, target, overrides, options);
3373
3390
  }
3374
- var adm = asObservableObject(target, options)[$mobx];
3375
- // Optimization: cache keys on proto
3376
- // Assumes makeAutoObservable can be called only once per object and can't be used in subclass
3377
- if (!target[keysSymbol]) {
3378
- var proto = Object.getPrototypeOf(target);
3379
- var keys = new Set([].concat(ownKeys(target), ownKeys(proto)));
3380
- keys["delete"]("constructor");
3381
- keys["delete"]($mobx);
3382
- addHiddenProp(proto, keysSymbol, keys);
3383
- }
3384
- startBatch();
3385
- try {
3391
+ initObservable(function () {
3392
+ var adm = asObservableObject(target, options)[$mobx];
3393
+ // Optimization: cache keys on proto
3394
+ // Assumes makeAutoObservable can be called only once per object and can't be used in subclass
3395
+ if (!target[keysSymbol]) {
3396
+ var proto = Object.getPrototypeOf(target);
3397
+ var keys = new Set([].concat(ownKeys(target), ownKeys(proto)));
3398
+ keys["delete"]("constructor");
3399
+ keys["delete"]($mobx);
3400
+ addHiddenProp(proto, keysSymbol, keys);
3401
+ }
3386
3402
  target[keysSymbol].forEach(function (key) {
3387
3403
  return adm.make_(key,
3388
3404
  // must pass "undefined" for { key: undefined }
3389
3405
  !overrides ? true : key in overrides ? overrides[key] : true);
3390
3406
  });
3391
- } finally {
3392
- endBatch();
3393
- }
3407
+ });
3394
3408
  return target;
3395
3409
  }
3396
3410
 
@@ -3698,16 +3712,16 @@ function createObservableArray(initialValues, enhancer, name, owned) {
3698
3712
  owned = false;
3699
3713
  }
3700
3714
  assertProxies();
3701
- var adm = new ObservableArrayAdministration(name, enhancer, owned, false);
3702
- addHiddenFinalProp(adm.values_, $mobx, adm);
3703
- var proxy = new Proxy(adm.values_, arrayTraps);
3704
- adm.proxy_ = proxy;
3705
- if (initialValues && initialValues.length) {
3706
- var prev = allowStateChangesStart(true);
3707
- adm.spliceWithArray_(0, 0, initialValues);
3708
- allowStateChangesEnd(prev);
3709
- }
3710
- return proxy;
3715
+ return initObservable(function () {
3716
+ var adm = new ObservableArrayAdministration(name, enhancer, owned, false);
3717
+ addHiddenFinalProp(adm.values_, $mobx, adm);
3718
+ var proxy = new Proxy(adm.values_, arrayTraps);
3719
+ adm.proxy_ = proxy;
3720
+ if (initialValues && initialValues.length) {
3721
+ adm.spliceWithArray_(0, 0, initialValues);
3722
+ }
3723
+ return proxy;
3724
+ });
3711
3725
  }
3712
3726
  // eslint-disable-next-line
3713
3727
  var arrayExtensions = {
@@ -3903,11 +3917,13 @@ var ObservableMap = /*#__PURE__*/function () {
3903
3917
  if (!isFunction(Map)) {
3904
3918
  die(18);
3905
3919
  }
3906
- this.keysAtom_ = createAtom(process.env.NODE_ENV !== "production" ? this.name_ + ".keys()" : "ObservableMap.keys()");
3907
- this.data_ = new Map();
3908
- this.hasMap_ = new Map();
3909
- allowStateChanges(true, function () {
3910
- _this.merge(initialData);
3920
+ initObservable(function () {
3921
+ _this.keysAtom_ = createAtom(process.env.NODE_ENV !== "production" ? _this.name_ + ".keys()" : "ObservableMap.keys()");
3922
+ _this.data_ = new Map();
3923
+ _this.hasMap_ = new Map();
3924
+ if (initialData) {
3925
+ _this.merge(initialData);
3926
+ }
3911
3927
  });
3912
3928
  }
3913
3929
  var _proto = ObservableMap.prototype;
@@ -4291,6 +4307,7 @@ _Symbol$iterator$1 = Symbol.iterator;
4291
4307
  _Symbol$toStringTag$1 = Symbol.toStringTag;
4292
4308
  var ObservableSet = /*#__PURE__*/function () {
4293
4309
  function ObservableSet(initialData, enhancer, name_) {
4310
+ var _this = this;
4294
4311
  if (enhancer === void 0) {
4295
4312
  enhancer = deepEnhancer;
4296
4313
  }
@@ -4309,13 +4326,15 @@ var ObservableSet = /*#__PURE__*/function () {
4309
4326
  if (!isFunction(Set)) {
4310
4327
  die(22);
4311
4328
  }
4312
- this.atom_ = createAtom(this.name_);
4313
4329
  this.enhancer_ = function (newV, oldV) {
4314
4330
  return enhancer(newV, oldV, name_);
4315
4331
  };
4316
- if (initialData) {
4317
- this.replace(initialData);
4318
- }
4332
+ initObservable(function () {
4333
+ _this.atom_ = createAtom(_this.name_);
4334
+ if (initialData) {
4335
+ _this.replace(initialData);
4336
+ }
4337
+ });
4319
4338
  }
4320
4339
  var _proto = ObservableSet.prototype;
4321
4340
  _proto.dehanceValue_ = function dehanceValue_(value) {
@@ -4325,12 +4344,12 @@ var ObservableSet = /*#__PURE__*/function () {
4325
4344
  return value;
4326
4345
  };
4327
4346
  _proto.clear = function clear() {
4328
- var _this = this;
4347
+ var _this2 = this;
4329
4348
  transaction(function () {
4330
4349
  untracked(function () {
4331
- for (var _iterator = _createForOfIteratorHelperLoose(_this.data_.values()), _step; !(_step = _iterator()).done;) {
4350
+ for (var _iterator = _createForOfIteratorHelperLoose(_this2.data_.values()), _step; !(_step = _iterator()).done;) {
4332
4351
  var value = _step.value;
4333
- _this["delete"](value);
4352
+ _this2["delete"](value);
4334
4353
  }
4335
4354
  });
4336
4355
  });
@@ -4342,7 +4361,7 @@ var ObservableSet = /*#__PURE__*/function () {
4342
4361
  }
4343
4362
  };
4344
4363
  _proto.add = function add(value) {
4345
- var _this2 = this;
4364
+ var _this3 = this;
4346
4365
  checkIfStateModificationsAreAllowed(this.atom_);
4347
4366
  if (hasInterceptors(this)) {
4348
4367
  var change = interceptChange(this, {
@@ -4359,8 +4378,8 @@ var ObservableSet = /*#__PURE__*/function () {
4359
4378
 
4360
4379
  if (!this.has(value)) {
4361
4380
  transaction(function () {
4362
- _this2.data_.add(_this2.enhancer_(value, undefined));
4363
- _this2.atom_.reportChanged();
4381
+ _this3.data_.add(_this3.enhancer_(value, undefined));
4382
+ _this3.atom_.reportChanged();
4364
4383
  });
4365
4384
  var notifySpy = process.env.NODE_ENV !== "production" && isSpyEnabled();
4366
4385
  var notify = hasListeners(this);
@@ -4384,7 +4403,7 @@ var ObservableSet = /*#__PURE__*/function () {
4384
4403
  return this;
4385
4404
  };
4386
4405
  _proto["delete"] = function _delete(value) {
4387
- var _this3 = this;
4406
+ var _this4 = this;
4388
4407
  if (hasInterceptors(this)) {
4389
4408
  var change = interceptChange(this, {
4390
4409
  type: DELETE,
@@ -4409,8 +4428,8 @@ var ObservableSet = /*#__PURE__*/function () {
4409
4428
  spyReportStart(_change2);
4410
4429
  }
4411
4430
  transaction(function () {
4412
- _this3.atom_.reportChanged();
4413
- _this3.data_["delete"](value);
4431
+ _this4.atom_.reportChanged();
4432
+ _this4.data_["delete"](value);
4414
4433
  });
4415
4434
  if (notify) {
4416
4435
  notifyListeners(this, _change2);
@@ -4463,20 +4482,20 @@ var ObservableSet = /*#__PURE__*/function () {
4463
4482
  });
4464
4483
  };
4465
4484
  _proto.replace = function replace(other) {
4466
- var _this4 = this;
4485
+ var _this5 = this;
4467
4486
  if (isObservableSet(other)) {
4468
4487
  other = new Set(other);
4469
4488
  }
4470
4489
  transaction(function () {
4471
4490
  if (Array.isArray(other)) {
4472
- _this4.clear();
4491
+ _this5.clear();
4473
4492
  other.forEach(function (value) {
4474
- return _this4.add(value);
4493
+ return _this5.add(value);
4475
4494
  });
4476
4495
  } else if (isES6Set(other)) {
4477
- _this4.clear();
4496
+ _this5.clear();
4478
4497
  other.forEach(function (value) {
4479
- return _this4.add(value);
4498
+ return _this5.add(value);
4480
4499
  });
4481
4500
  } else if (other !== null && other !== undefined) {
4482
4501
  die("Cannot initialize set from " + other);
@@ -4740,6 +4759,7 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
4740
4759
  if (proxyTrap === void 0) {
4741
4760
  proxyTrap = false;
4742
4761
  }
4762
+ checkIfStateModificationsAreAllowed(this.keysAtom_);
4743
4763
  try {
4744
4764
  startBatch();
4745
4765
  // Delete
@@ -4787,6 +4807,7 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
4787
4807
  if (proxyTrap === void 0) {
4788
4808
  proxyTrap = false;
4789
4809
  }
4810
+ checkIfStateModificationsAreAllowed(this.keysAtom_);
4790
4811
  try {
4791
4812
  startBatch();
4792
4813
  // Delete
@@ -4838,6 +4859,7 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
4838
4859
  if (proxyTrap === void 0) {
4839
4860
  proxyTrap = false;
4840
4861
  }
4862
+ checkIfStateModificationsAreAllowed(this.keysAtom_);
4841
4863
  try {
4842
4864
  startBatch();
4843
4865
  // Delete
@@ -4893,6 +4915,7 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
4893
4915
  if (proxyTrap === void 0) {
4894
4916
  proxyTrap = false;
4895
4917
  }
4918
+ checkIfStateModificationsAreAllowed(this.keysAtom_);
4896
4919
  // No such prop
4897
4920
  if (!hasProp(this.target_, key)) {
4898
4921
  return true;
@@ -5122,6 +5145,17 @@ function assertAnnotable(adm, annotation, key) {
5122
5145
 
5123
5146
  // Bug in safari 9.* (or iOS 9 safari mobile). See #364
5124
5147
  var ENTRY_0 = /*#__PURE__*/createArrayEntryDescriptor(0);
5148
+ var safariPrototypeSetterInheritanceBug = /*#__PURE__*/function () {
5149
+ var v = false;
5150
+ var p = {};
5151
+ Object.defineProperty(p, "0", {
5152
+ set: function set() {
5153
+ v = true;
5154
+ }
5155
+ });
5156
+ /*#__PURE__*/Object.create(p)["0"] = 1;
5157
+ return v === false;
5158
+ }();
5125
5159
  /**
5126
5160
  * This array buffer contains two lists of properties, so that all arrays
5127
5161
  * can recycle their property definitions, which significantly improves performance of creating
@@ -5154,20 +5188,20 @@ var LegacyObservableArray = /*#__PURE__*/function (_StubArray, _Symbol$toStringT
5154
5188
  owned = false;
5155
5189
  }
5156
5190
  _this = _StubArray.call(this) || this;
5157
- var adm = new ObservableArrayAdministration(name, enhancer, owned, true);
5158
- adm.proxy_ = _assertThisInitialized(_this);
5159
- addHiddenFinalProp(_assertThisInitialized(_this), $mobx, adm);
5160
- if (initialValues && initialValues.length) {
5161
- var prev = allowStateChangesStart(true);
5162
- // @ts-ignore
5163
- _this.spliceWithArray(0, 0, initialValues);
5164
- allowStateChangesEnd(prev);
5165
- }
5166
- {
5167
- // Seems that Safari won't use numeric prototype setter untill any * numeric property is
5168
- // defined on the instance. After that it works fine, even if this property is deleted.
5169
- Object.defineProperty(_assertThisInitialized(_this), "0", ENTRY_0);
5170
- }
5191
+ initObservable(function () {
5192
+ var adm = new ObservableArrayAdministration(name, enhancer, owned, true);
5193
+ adm.proxy_ = _assertThisInitialized(_this);
5194
+ addHiddenFinalProp(_assertThisInitialized(_this), $mobx, adm);
5195
+ if (initialValues && initialValues.length) {
5196
+ // @ts-ignore
5197
+ _this.spliceWithArray(0, 0, initialValues);
5198
+ }
5199
+ if (safariPrototypeSetterInheritanceBug) {
5200
+ // Seems that Safari won't use numeric prototype setter untill any * numeric property is
5201
+ // defined on the instance. After that it works fine, even if this property is deleted.
5202
+ Object.defineProperty(_assertThisInitialized(_this), "0", ENTRY_0);
5203
+ }
5204
+ });
5171
5205
  return _this;
5172
5206
  }
5173
5207
  var _proto = LegacyObservableArray.prototype;
@@ -5322,6 +5356,24 @@ function getDebugName(thing, property) {
5322
5356
  }
5323
5357
  return named.name_;
5324
5358
  }
5359
+ /**
5360
+ * Helper function for initializing observable structures, it applies:
5361
+ * 1. allowStateChanges so we don't violate enforceActions.
5362
+ * 2. untracked so we don't accidentaly subscribe to anything observable accessed during init in case the observable is created inside derivation.
5363
+ * 3. batch to avoid state version updates
5364
+ */
5365
+ function initObservable(cb) {
5366
+ var derivation = untrackedStart();
5367
+ var allowStateChanges = allowStateChangesStart(true);
5368
+ startBatch();
5369
+ try {
5370
+ return cb();
5371
+ } finally {
5372
+ endBatch();
5373
+ allowStateChangesEnd(allowStateChanges);
5374
+ untrackedEnd(derivation);
5375
+ }
5376
+ }
5325
5377
 
5326
5378
  var toString = objectPrototype.toString;
5327
5379
  function deepEqual(a, b, depth) {