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.
package/dist/mobx.esm.js CHANGED
@@ -733,7 +733,7 @@ function make_$2(adm, key, descriptor, source) {
733
733
  // bound - must annotate protos to support super.flow()
734
734
 
735
735
 
736
- if ((_this$options_ = this.options_) != null && _this$options_.bound && !isFlow(adm.target_[key])) {
736
+ if ((_this$options_ = this.options_) != null && _this$options_.bound && (!hasProp(adm.target_, key) || !isFlow(adm.target_[key]))) {
737
737
  if (this.extend_(adm, key, descriptor, false) === null) return 0
738
738
  /* Cancel */
739
739
  ;
@@ -777,16 +777,23 @@ safeDescriptors) {
777
777
  }
778
778
 
779
779
  assertFlowDescriptor(adm, annotation, key, descriptor);
780
- var value = descriptor.value;
780
+ var value = descriptor.value; // In case of flow.bound, the descriptor can be from already annotated prototype
781
+
782
+ if (!isFlow(value)) {
783
+ value = flow(value);
784
+ }
781
785
 
782
786
  if (bound) {
783
787
  var _adm$proxy_;
784
788
 
785
- value = value.bind((_adm$proxy_ = adm.proxy_) != null ? _adm$proxy_ : adm.target_);
789
+ // We do not keep original function around, so we bind the existing flow
790
+ value = value.bind((_adm$proxy_ = adm.proxy_) != null ? _adm$proxy_ : adm.target_); // This is normally set by `flow`, but `bind` returns new function...
791
+
792
+ value.isMobXFlow = true;
786
793
  }
787
794
 
788
795
  return {
789
- value: flow(value),
796
+ value: value,
790
797
  // Non-configurable for classes
791
798
  // prevents accidental field redefinition in subclass
792
799
  configurable: safeDescriptors ? adm.isPlainObject_ : true,
@@ -3233,7 +3240,10 @@ function toJSHelper(source, __alreadySeen) {
3233
3240
  }
3234
3241
  }
3235
3242
  /**
3236
- * Basically, a deep clone, so that no reactive property will exist anymore.
3243
+ * Recursively converts an observable to it's non-observable native counterpart.
3244
+ * It does NOT recurse into non-observables, these are left as they are, even if they contain observables.
3245
+ * Computed and other non-enumerable properties are completely ignored.
3246
+ * Complex scenarios require custom solution, eg implementing `toJSON` or using `serializr` lib.
3237
3247
  */
3238
3248
 
3239
3249
 
@@ -4026,6 +4036,8 @@ _Symbol$toStringTag = Symbol.toStringTag;
4026
4036
  var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTag2) {
4027
4037
  // hasMap, not hashMap >-).
4028
4038
  function ObservableMap(initialData, enhancer_, name_) {
4039
+ var _this = this;
4040
+
4029
4041
  if (enhancer_ === void 0) {
4030
4042
  enhancer_ = deepEnhancer;
4031
4043
  }
@@ -4053,7 +4065,9 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
4053
4065
  this.keysAtom_ = createAtom(process.env.NODE_ENV !== "production" ? this.name_ + ".keys()" : "ObservableMap.keys()");
4054
4066
  this.data_ = new Map();
4055
4067
  this.hasMap_ = new Map();
4056
- this.merge(initialData);
4068
+ allowStateChanges(true, function () {
4069
+ _this.merge(initialData);
4070
+ });
4057
4071
  }
4058
4072
 
4059
4073
  var _proto = ObservableMap.prototype;
@@ -4063,7 +4077,7 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
4063
4077
  };
4064
4078
 
4065
4079
  _proto.has = function has(key) {
4066
- var _this = this;
4080
+ var _this2 = this;
4067
4081
 
4068
4082
  if (!globalState.trackingDerivation) return this.has_(key);
4069
4083
  var entry = this.hasMap_.get(key);
@@ -4072,7 +4086,7 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
4072
4086
  var newEntry = entry = new ObservableValue(this.has_(key), referenceEnhancer, process.env.NODE_ENV !== "production" ? this.name_ + "." + stringifyKey(key) + "?" : "ObservableMap.key?", false);
4073
4087
  this.hasMap_.set(key, newEntry);
4074
4088
  onBecomeUnobserved(newEntry, function () {
4075
- return _this.hasMap_["delete"](key);
4089
+ return _this2.hasMap_["delete"](key);
4076
4090
  });
4077
4091
  }
4078
4092
 
@@ -4103,7 +4117,7 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
4103
4117
  };
4104
4118
 
4105
4119
  _proto["delete"] = function _delete(key) {
4106
- var _this2 = this;
4120
+ var _this3 = this;
4107
4121
 
4108
4122
  checkIfStateModificationsAreAllowed(this.keysAtom_);
4109
4123
 
@@ -4132,17 +4146,17 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
4132
4146
  if (process.env.NODE_ENV !== "production" && notifySpy) spyReportStart(_change); // TODO fix type
4133
4147
 
4134
4148
  transaction(function () {
4135
- var _this2$hasMap_$get;
4149
+ var _this3$hasMap_$get;
4136
4150
 
4137
- _this2.keysAtom_.reportChanged();
4151
+ _this3.keysAtom_.reportChanged();
4138
4152
 
4139
- (_this2$hasMap_$get = _this2.hasMap_.get(key)) == null ? void 0 : _this2$hasMap_$get.setNewValue_(false);
4153
+ (_this3$hasMap_$get = _this3.hasMap_.get(key)) == null ? void 0 : _this3$hasMap_$get.setNewValue_(false);
4140
4154
 
4141
- var observable = _this2.data_.get(key);
4155
+ var observable = _this3.data_.get(key);
4142
4156
 
4143
4157
  observable.setNewValue_(undefined);
4144
4158
 
4145
- _this2.data_["delete"](key);
4159
+ _this3.data_["delete"](key);
4146
4160
  });
4147
4161
  if (notify) notifyListeners(this, _change);
4148
4162
  if (process.env.NODE_ENV !== "production" && notifySpy) spyReportEnd();
@@ -4177,21 +4191,21 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
4177
4191
  };
4178
4192
 
4179
4193
  _proto.addValue_ = function addValue_(key, newValue) {
4180
- var _this3 = this;
4194
+ var _this4 = this;
4181
4195
 
4182
4196
  checkIfStateModificationsAreAllowed(this.keysAtom_);
4183
4197
  transaction(function () {
4184
- var _this3$hasMap_$get;
4198
+ var _this4$hasMap_$get;
4185
4199
 
4186
- var observable = new ObservableValue(newValue, _this3.enhancer_, process.env.NODE_ENV !== "production" ? _this3.name_ + "." + stringifyKey(key) : "ObservableMap.key", false);
4200
+ var observable = new ObservableValue(newValue, _this4.enhancer_, process.env.NODE_ENV !== "production" ? _this4.name_ + "." + stringifyKey(key) : "ObservableMap.key", false);
4187
4201
 
4188
- _this3.data_.set(key, observable);
4202
+ _this4.data_.set(key, observable);
4189
4203
 
4190
4204
  newValue = observable.value_; // value might have been changed
4191
4205
 
4192
- (_this3$hasMap_$get = _this3.hasMap_.get(key)) == null ? void 0 : _this3$hasMap_$get.setNewValue_(true);
4206
+ (_this4$hasMap_$get = _this4.hasMap_.get(key)) == null ? void 0 : _this4$hasMap_$get.setNewValue_(true);
4193
4207
 
4194
- _this3.keysAtom_.reportChanged();
4208
+ _this4.keysAtom_.reportChanged();
4195
4209
  });
4196
4210
  var notifySpy = isSpyEnabled();
4197
4211
  var notify = hasListeners(this);
@@ -4277,7 +4291,7 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
4277
4291
  ;
4278
4292
 
4279
4293
  _proto.merge = function merge(other) {
4280
- var _this4 = this;
4294
+ var _this5 = this;
4281
4295
 
4282
4296
  if (isObservableMap(other)) {
4283
4297
  other = new Map(other);
@@ -4285,15 +4299,15 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
4285
4299
 
4286
4300
  transaction(function () {
4287
4301
  if (isPlainObject(other)) getPlainObjectKeys(other).forEach(function (key) {
4288
- return _this4.set(key, other[key]);
4302
+ return _this5.set(key, other[key]);
4289
4303
  });else if (Array.isArray(other)) other.forEach(function (_ref) {
4290
4304
  var key = _ref[0],
4291
4305
  value = _ref[1];
4292
- return _this4.set(key, value);
4306
+ return _this5.set(key, value);
4293
4307
  });else if (isES6Map(other)) {
4294
4308
  if (other.constructor !== Map) die(19, other);
4295
4309
  other.forEach(function (value, key) {
4296
- return _this4.set(key, value);
4310
+ return _this5.set(key, value);
4297
4311
  });
4298
4312
  } else if (other !== null && other !== undefined) die(20, other);
4299
4313
  });
@@ -4301,21 +4315,21 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
4301
4315
  };
4302
4316
 
4303
4317
  _proto.clear = function clear() {
4304
- var _this5 = this;
4318
+ var _this6 = this;
4305
4319
 
4306
4320
  transaction(function () {
4307
4321
  untracked(function () {
4308
- for (var _iterator2 = _createForOfIteratorHelperLoose(_this5.keys()), _step2; !(_step2 = _iterator2()).done;) {
4322
+ for (var _iterator2 = _createForOfIteratorHelperLoose(_this6.keys()), _step2; !(_step2 = _iterator2()).done;) {
4309
4323
  var key = _step2.value;
4310
4324
 
4311
- _this5["delete"](key);
4325
+ _this6["delete"](key);
4312
4326
  }
4313
4327
  });
4314
4328
  });
4315
4329
  };
4316
4330
 
4317
4331
  _proto.replace = function replace(values) {
4318
- var _this6 = this;
4332
+ var _this7 = this;
4319
4333
 
4320
4334
  // Implementation requirements:
4321
4335
  // - respect ordering of replacement map
@@ -4332,13 +4346,13 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
4332
4346
  // if the key deletion is prevented by interceptor
4333
4347
  // add entry at the beginning of the result map
4334
4348
 
4335
- for (var _iterator3 = _createForOfIteratorHelperLoose(_this6.data_.keys()), _step3; !(_step3 = _iterator3()).done;) {
4349
+ for (var _iterator3 = _createForOfIteratorHelperLoose(_this7.data_.keys()), _step3; !(_step3 = _iterator3()).done;) {
4336
4350
  var key = _step3.value;
4337
4351
 
4338
4352
  // Concurrently iterating/deleting keys
4339
4353
  // iterator should handle this correctly
4340
4354
  if (!replacementMap.has(key)) {
4341
- var deleted = _this6["delete"](key); // Was the key removed?
4355
+ var deleted = _this7["delete"](key); // Was the key removed?
4342
4356
 
4343
4357
 
4344
4358
  if (deleted) {
@@ -4346,7 +4360,7 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
4346
4360
  keysReportChangedCalled = true;
4347
4361
  } else {
4348
4362
  // Delete prevented by interceptor
4349
- var value = _this6.data_.get(key);
4363
+ var value = _this7.data_.get(key);
4350
4364
 
4351
4365
  orderedData.set(key, value);
4352
4366
  }
@@ -4360,17 +4374,17 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
4360
4374
  _value = _step4$value[1];
4361
4375
 
4362
4376
  // We will want to know whether a new key is added
4363
- var keyExisted = _this6.data_.has(_key); // Add or update value
4377
+ var keyExisted = _this7.data_.has(_key); // Add or update value
4364
4378
 
4365
4379
 
4366
- _this6.set(_key, _value); // The addition could have been prevent by interceptor
4380
+ _this7.set(_key, _value); // The addition could have been prevent by interceptor
4367
4381
 
4368
4382
 
4369
- if (_this6.data_.has(_key)) {
4383
+ if (_this7.data_.has(_key)) {
4370
4384
  // The update could have been prevented by interceptor
4371
4385
  // and also we want to preserve existing values
4372
4386
  // so use value from _data map (instead of replacement map)
4373
- var _value2 = _this6.data_.get(_key);
4387
+ var _value2 = _this7.data_.get(_key);
4374
4388
 
4375
4389
  orderedData.set(_key, _value2); // Was a new key added?
4376
4390
 
@@ -4383,11 +4397,11 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
4383
4397
 
4384
4398
 
4385
4399
  if (!keysReportChangedCalled) {
4386
- if (_this6.data_.size !== orderedData.size) {
4400
+ if (_this7.data_.size !== orderedData.size) {
4387
4401
  // If size differs, keys are definitely modified
4388
- _this6.keysAtom_.reportChanged();
4402
+ _this7.keysAtom_.reportChanged();
4389
4403
  } else {
4390
- var iter1 = _this6.data_.keys();
4404
+ var iter1 = _this7.data_.keys();
4391
4405
 
4392
4406
  var iter2 = orderedData.keys();
4393
4407
  var next1 = iter1.next();
@@ -4395,7 +4409,7 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
4395
4409
 
4396
4410
  while (!next1.done) {
4397
4411
  if (next1.value !== next2.value) {
4398
- _this6.keysAtom_.reportChanged();
4412
+ _this7.keysAtom_.reportChanged();
4399
4413
 
4400
4414
  break;
4401
4415
  }
@@ -4407,7 +4421,7 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
4407
4421
  } // Use correctly ordered map
4408
4422
 
4409
4423
 
4410
- _this6.data_ = orderedData;
4424
+ _this7.data_ = orderedData;
4411
4425
  });
4412
4426
  return this;
4413
4427
  };
@@ -5616,7 +5630,7 @@ function eq(a, b, depth, aStack, bStack) {
5616
5630
  if (a !== a) return b !== b; // Exhaust primitive checks
5617
5631
 
5618
5632
  var type = typeof a;
5619
- if (!isFunction(type) && type !== "object" && typeof b != "object") return false; // Compare `[[Class]]` names.
5633
+ if (type !== "function" && type !== "object" && typeof b != "object") return false; // Compare `[[Class]]` names.
5620
5634
 
5621
5635
  var className = toString.call(a);
5622
5636
  if (className !== toString.call(b)) return false;