mobx 6.3.9 → 6.3.13

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.
@@ -731,7 +731,7 @@ function make_$2(adm, key, descriptor, source) {
731
731
  // bound - must annotate protos to support super.flow()
732
732
 
733
733
 
734
- if ((_this$options_ = this.options_) != null && _this$options_.bound && !isFlow(adm.target_[key])) {
734
+ if ((_this$options_ = this.options_) != null && _this$options_.bound && (!hasProp(adm.target_, key) || !isFlow(adm.target_[key]))) {
735
735
  if (this.extend_(adm, key, descriptor, false) === null) return 0
736
736
  /* Cancel */
737
737
  ;
@@ -775,16 +775,23 @@ safeDescriptors) {
775
775
  }
776
776
 
777
777
  assertFlowDescriptor(adm, annotation, key, descriptor);
778
- var value = descriptor.value;
778
+ var value = descriptor.value; // In case of flow.bound, the descriptor can be from already annotated prototype
779
+
780
+ if (!isFlow(value)) {
781
+ value = flow(value);
782
+ }
779
783
 
780
784
  if (bound) {
781
785
  var _adm$proxy_;
782
786
 
783
- value = value.bind((_adm$proxy_ = adm.proxy_) != null ? _adm$proxy_ : adm.target_);
787
+ // We do not keep original function around, so we bind the existing flow
788
+ value = value.bind((_adm$proxy_ = adm.proxy_) != null ? _adm$proxy_ : adm.target_); // This is normally set by `flow`, but `bind` returns new function...
789
+
790
+ value.isMobXFlow = true;
784
791
  }
785
792
 
786
793
  return {
787
- value: flow(value),
794
+ value: value,
788
795
  // Non-configurable for classes
789
796
  // prevents accidental field redefinition in subclass
790
797
  configurable: safeDescriptors ? adm.isPlainObject_ : true,
@@ -3220,7 +3227,10 @@ function toJSHelper(source, __alreadySeen) {
3220
3227
  }
3221
3228
  }
3222
3229
  /**
3223
- * Basically, a deep clone, so that no reactive property will exist anymore.
3230
+ * Recursively converts an observable to it's non-observable native counterpart.
3231
+ * It does NOT recurse into non-observables, these are left as they are, even if they contain observables.
3232
+ * Computed and other non-enumerable properties are completely ignored.
3233
+ * Complex scenarios require custom solution, eg implementing `toJSON` or using `serializr` lib.
3224
3234
  */
3225
3235
 
3226
3236
 
@@ -4012,6 +4022,8 @@ _Symbol$toStringTag = Symbol.toStringTag;
4012
4022
  var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTag2) {
4013
4023
  // hasMap, not hashMap >-).
4014
4024
  function ObservableMap(initialData, enhancer_, name_) {
4025
+ var _this = this;
4026
+
4015
4027
  if (enhancer_ === void 0) {
4016
4028
  enhancer_ = deepEnhancer;
4017
4029
  }
@@ -4039,7 +4051,9 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
4039
4051
  this.keysAtom_ = createAtom( this.name_ + ".keys()" );
4040
4052
  this.data_ = new Map();
4041
4053
  this.hasMap_ = new Map();
4042
- this.merge(initialData);
4054
+ allowStateChanges(true, function () {
4055
+ _this.merge(initialData);
4056
+ });
4043
4057
  }
4044
4058
 
4045
4059
  var _proto = ObservableMap.prototype;
@@ -4049,7 +4063,7 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
4049
4063
  };
4050
4064
 
4051
4065
  _proto.has = function has(key) {
4052
- var _this = this;
4066
+ var _this2 = this;
4053
4067
 
4054
4068
  if (!globalState.trackingDerivation) return this.has_(key);
4055
4069
  var entry = this.hasMap_.get(key);
@@ -4058,7 +4072,7 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
4058
4072
  var newEntry = entry = new ObservableValue(this.has_(key), referenceEnhancer, this.name_ + "." + stringifyKey(key) + "?" , false);
4059
4073
  this.hasMap_.set(key, newEntry);
4060
4074
  onBecomeUnobserved(newEntry, function () {
4061
- return _this.hasMap_["delete"](key);
4075
+ return _this2.hasMap_["delete"](key);
4062
4076
  });
4063
4077
  }
4064
4078
 
@@ -4089,7 +4103,7 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
4089
4103
  };
4090
4104
 
4091
4105
  _proto["delete"] = function _delete(key) {
4092
- var _this2 = this;
4106
+ var _this3 = this;
4093
4107
 
4094
4108
  checkIfStateModificationsAreAllowed(this.keysAtom_);
4095
4109
 
@@ -4118,17 +4132,17 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
4118
4132
  if ( notifySpy) spyReportStart(_change); // TODO fix type
4119
4133
 
4120
4134
  transaction(function () {
4121
- var _this2$hasMap_$get;
4135
+ var _this3$hasMap_$get;
4122
4136
 
4123
- _this2.keysAtom_.reportChanged();
4137
+ _this3.keysAtom_.reportChanged();
4124
4138
 
4125
- (_this2$hasMap_$get = _this2.hasMap_.get(key)) == null ? void 0 : _this2$hasMap_$get.setNewValue_(false);
4139
+ (_this3$hasMap_$get = _this3.hasMap_.get(key)) == null ? void 0 : _this3$hasMap_$get.setNewValue_(false);
4126
4140
 
4127
- var observable = _this2.data_.get(key);
4141
+ var observable = _this3.data_.get(key);
4128
4142
 
4129
4143
  observable.setNewValue_(undefined);
4130
4144
 
4131
- _this2.data_["delete"](key);
4145
+ _this3.data_["delete"](key);
4132
4146
  });
4133
4147
  if (notify) notifyListeners(this, _change);
4134
4148
  if ( notifySpy) spyReportEnd();
@@ -4163,21 +4177,21 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
4163
4177
  };
4164
4178
 
4165
4179
  _proto.addValue_ = function addValue_(key, newValue) {
4166
- var _this3 = this;
4180
+ var _this4 = this;
4167
4181
 
4168
4182
  checkIfStateModificationsAreAllowed(this.keysAtom_);
4169
4183
  transaction(function () {
4170
- var _this3$hasMap_$get;
4184
+ var _this4$hasMap_$get;
4171
4185
 
4172
- var observable = new ObservableValue(newValue, _this3.enhancer_, _this3.name_ + "." + stringifyKey(key) , false);
4186
+ var observable = new ObservableValue(newValue, _this4.enhancer_, _this4.name_ + "." + stringifyKey(key) , false);
4173
4187
 
4174
- _this3.data_.set(key, observable);
4188
+ _this4.data_.set(key, observable);
4175
4189
 
4176
4190
  newValue = observable.value_; // value might have been changed
4177
4191
 
4178
- (_this3$hasMap_$get = _this3.hasMap_.get(key)) == null ? void 0 : _this3$hasMap_$get.setNewValue_(true);
4192
+ (_this4$hasMap_$get = _this4.hasMap_.get(key)) == null ? void 0 : _this4$hasMap_$get.setNewValue_(true);
4179
4193
 
4180
- _this3.keysAtom_.reportChanged();
4194
+ _this4.keysAtom_.reportChanged();
4181
4195
  });
4182
4196
  var notifySpy = isSpyEnabled();
4183
4197
  var notify = hasListeners(this);
@@ -4263,7 +4277,7 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
4263
4277
  ;
4264
4278
 
4265
4279
  _proto.merge = function merge(other) {
4266
- var _this4 = this;
4280
+ var _this5 = this;
4267
4281
 
4268
4282
  if (isObservableMap(other)) {
4269
4283
  other = new Map(other);
@@ -4271,15 +4285,15 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
4271
4285
 
4272
4286
  transaction(function () {
4273
4287
  if (isPlainObject(other)) getPlainObjectKeys(other).forEach(function (key) {
4274
- return _this4.set(key, other[key]);
4288
+ return _this5.set(key, other[key]);
4275
4289
  });else if (Array.isArray(other)) other.forEach(function (_ref) {
4276
4290
  var key = _ref[0],
4277
4291
  value = _ref[1];
4278
- return _this4.set(key, value);
4292
+ return _this5.set(key, value);
4279
4293
  });else if (isES6Map(other)) {
4280
4294
  if (other.constructor !== Map) die(19, other);
4281
4295
  other.forEach(function (value, key) {
4282
- return _this4.set(key, value);
4296
+ return _this5.set(key, value);
4283
4297
  });
4284
4298
  } else if (other !== null && other !== undefined) die(20, other);
4285
4299
  });
@@ -4287,21 +4301,21 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
4287
4301
  };
4288
4302
 
4289
4303
  _proto.clear = function clear() {
4290
- var _this5 = this;
4304
+ var _this6 = this;
4291
4305
 
4292
4306
  transaction(function () {
4293
4307
  untracked(function () {
4294
- for (var _iterator2 = _createForOfIteratorHelperLoose(_this5.keys()), _step2; !(_step2 = _iterator2()).done;) {
4308
+ for (var _iterator2 = _createForOfIteratorHelperLoose(_this6.keys()), _step2; !(_step2 = _iterator2()).done;) {
4295
4309
  var key = _step2.value;
4296
4310
 
4297
- _this5["delete"](key);
4311
+ _this6["delete"](key);
4298
4312
  }
4299
4313
  });
4300
4314
  });
4301
4315
  };
4302
4316
 
4303
4317
  _proto.replace = function replace(values) {
4304
- var _this6 = this;
4318
+ var _this7 = this;
4305
4319
 
4306
4320
  // Implementation requirements:
4307
4321
  // - respect ordering of replacement map
@@ -4318,13 +4332,13 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
4318
4332
  // if the key deletion is prevented by interceptor
4319
4333
  // add entry at the beginning of the result map
4320
4334
 
4321
- for (var _iterator3 = _createForOfIteratorHelperLoose(_this6.data_.keys()), _step3; !(_step3 = _iterator3()).done;) {
4335
+ for (var _iterator3 = _createForOfIteratorHelperLoose(_this7.data_.keys()), _step3; !(_step3 = _iterator3()).done;) {
4322
4336
  var key = _step3.value;
4323
4337
 
4324
4338
  // Concurrently iterating/deleting keys
4325
4339
  // iterator should handle this correctly
4326
4340
  if (!replacementMap.has(key)) {
4327
- var deleted = _this6["delete"](key); // Was the key removed?
4341
+ var deleted = _this7["delete"](key); // Was the key removed?
4328
4342
 
4329
4343
 
4330
4344
  if (deleted) {
@@ -4332,7 +4346,7 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
4332
4346
  keysReportChangedCalled = true;
4333
4347
  } else {
4334
4348
  // Delete prevented by interceptor
4335
- var value = _this6.data_.get(key);
4349
+ var value = _this7.data_.get(key);
4336
4350
 
4337
4351
  orderedData.set(key, value);
4338
4352
  }
@@ -4346,17 +4360,17 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
4346
4360
  _value = _step4$value[1];
4347
4361
 
4348
4362
  // We will want to know whether a new key is added
4349
- var keyExisted = _this6.data_.has(_key); // Add or update value
4363
+ var keyExisted = _this7.data_.has(_key); // Add or update value
4350
4364
 
4351
4365
 
4352
- _this6.set(_key, _value); // The addition could have been prevent by interceptor
4366
+ _this7.set(_key, _value); // The addition could have been prevent by interceptor
4353
4367
 
4354
4368
 
4355
- if (_this6.data_.has(_key)) {
4369
+ if (_this7.data_.has(_key)) {
4356
4370
  // The update could have been prevented by interceptor
4357
4371
  // and also we want to preserve existing values
4358
4372
  // so use value from _data map (instead of replacement map)
4359
- var _value2 = _this6.data_.get(_key);
4373
+ var _value2 = _this7.data_.get(_key);
4360
4374
 
4361
4375
  orderedData.set(_key, _value2); // Was a new key added?
4362
4376
 
@@ -4369,11 +4383,11 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
4369
4383
 
4370
4384
 
4371
4385
  if (!keysReportChangedCalled) {
4372
- if (_this6.data_.size !== orderedData.size) {
4386
+ if (_this7.data_.size !== orderedData.size) {
4373
4387
  // If size differs, keys are definitely modified
4374
- _this6.keysAtom_.reportChanged();
4388
+ _this7.keysAtom_.reportChanged();
4375
4389
  } else {
4376
- var iter1 = _this6.data_.keys();
4390
+ var iter1 = _this7.data_.keys();
4377
4391
 
4378
4392
  var iter2 = orderedData.keys();
4379
4393
  var next1 = iter1.next();
@@ -4381,7 +4395,7 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
4381
4395
 
4382
4396
  while (!next1.done) {
4383
4397
  if (next1.value !== next2.value) {
4384
- _this6.keysAtom_.reportChanged();
4398
+ _this7.keysAtom_.reportChanged();
4385
4399
 
4386
4400
  break;
4387
4401
  }
@@ -4393,7 +4407,7 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
4393
4407
  } // Use correctly ordered map
4394
4408
 
4395
4409
 
4396
- _this6.data_ = orderedData;
4410
+ _this7.data_ = orderedData;
4397
4411
  });
4398
4412
  return this;
4399
4413
  };
@@ -5602,7 +5616,7 @@ function eq(a, b, depth, aStack, bStack) {
5602
5616
  if (a !== a) return b !== b; // Exhaust primitive checks
5603
5617
 
5604
5618
  var type = typeof a;
5605
- if (!isFunction(type) && type !== "object" && typeof b != "object") return false; // Compare `[[Class]]` names.
5619
+ if (type !== "function" && type !== "object" && typeof b != "object") return false; // Compare `[[Class]]` names.
5606
5620
 
5607
5621
  var className = toString.call(a);
5608
5622
  if (className !== toString.call(b)) return false;