mobx 6.16.0 → 6.16.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.
@@ -947,24 +947,44 @@
947
947
  var ann = this;
948
948
  var key = context.name,
949
949
  addInitializer = context.addInitializer;
950
+ var computedValues;
950
951
  // Defer ComputedValue creation until first access — avoids allocating
951
952
  // ComputedValues for getters that are never read on a given instance.
952
953
  // The factory is materialised by ObservableObjectAdministration on demand.
954
+ function createComputedValue(target, adm) {
955
+ var options = _extends({}, ann.options_, {
956
+ get: get,
957
+ context: target
958
+ });
959
+ options.name || (options.name = adm.name_ + "." + key.toString() );
960
+ return new ComputedValue(options);
961
+ }
953
962
  addInitializer(function () {
954
963
  var _adm$lazyComputedKeys;
955
964
  var adm = asObservableObject(this)[$mobx];
956
965
  var target = this;
966
+ var observable = adm.values_.get(key);
967
+ if (observable instanceof ComputedValue && observable.derivation !== get) {
968
+ adm.values_["delete"](key);
969
+ }
957
970
  ((_adm$lazyComputedKeys = adm.lazyComputedKeys_) != null ? _adm$lazyComputedKeys : adm.lazyComputedKeys_ = new Map()).set(key, function () {
958
- var options = _extends({}, ann.options_, {
959
- get: get,
960
- context: target
961
- });
962
- options.name || (options.name = adm.name_ + "." + key.toString() );
963
- return new ComputedValue(options);
971
+ return createComputedValue(target, adm);
964
972
  });
965
973
  });
966
974
  return function () {
967
- return this[$mobx].getObservablePropValue_(key);
975
+ var adm = this[$mobx];
976
+ var observable = adm.values_.get(key);
977
+ if (observable instanceof ComputedValue && observable.derivation !== get) {
978
+ var _computedValues;
979
+ var computed = (_computedValues = computedValues) == null ? void 0 : _computedValues.get(this);
980
+ if (!computed) {
981
+ var _computedValues2;
982
+ computed = createComputedValue(this, adm);
983
+ ((_computedValues2 = computedValues) != null ? _computedValues2 : computedValues = new WeakMap()).set(this, computed);
984
+ }
985
+ return computed.get();
986
+ }
987
+ return adm.getObservablePropValue_(key);
968
988
  };
969
989
  }
970
990
  function assertComputedDescriptor(adm, _ref, key, _ref2) {