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/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # mobx
2
2
 
3
+ ## 6.3.13
4
+
5
+ ### Patch Changes
6
+
7
+ - [`23803202`](https://github.com/mobxjs/mobx/commit/2380320263f5edcd06d7ba6bdf02aff3fd7d305a) [#3273](https://github.com/mobxjs/mobx/pull/3273) Thanks [@urugator](https://github.com/urugator)! - fix `flow.bound` #3271
8
+
9
+ ## 6.3.12
10
+
11
+ ### Patch Changes
12
+
13
+ - [`654a2013`](https://github.com/mobxjs/mobx/commit/654a2013107ac6e5bbe3851e4eed22f0c9130525) [#3257](https://github.com/mobxjs/mobx/pull/3257) Thanks [@urugator](https://github.com/urugator)! - fix: observable map initialization violates `enforceActions: "always"`
14
+
15
+ ## 6.3.11
16
+
17
+ ### Patch Changes
18
+
19
+ - [`bf5da6ba`](https://github.com/mobxjs/mobx/commit/bf5da6bad982dc3d955d5f27f7fea6f94b041ea7) [#3239](https://github.com/mobxjs/mobx/pull/3239) Thanks [@bernardobelchior](https://github.com/bernardobelchior)! - Improved `toJS` jsdoc
20
+
21
+ ## 6.3.10
22
+
23
+ ### Patch Changes
24
+
25
+ - [`2d70798e`](https://github.com/mobxjs/mobx/commit/2d70798eb327187d93757757ceaf410a608735b2) [#3233](https://github.com/mobxjs/mobx/pull/3233) Thanks [@anderlaw](https://github.com/anderlaw)! - `eq.ts` fix comparer logic
26
+
3
27
  ## 6.3.9
4
28
 
5
29
  ### Patch Changes
@@ -1,4 +1,7 @@
1
1
  /**
2
- * Basically, a deep clone, so that no reactive property will exist anymore.
2
+ * Recursively converts an observable to it's non-observable native counterpart.
3
+ * It does NOT recurse into non-observables, these are left as they are, even if they contain observables.
4
+ * Computed and other non-enumerable properties are completely ignored.
5
+ * Complex scenarios require custom solution, eg implementing `toJSON` or using `serializr` lib.
3
6
  */
4
7
  export declare function toJS<T>(source: T, options?: any): T;
@@ -735,7 +735,7 @@ function make_$2(adm, key, descriptor, source) {
735
735
  // bound - must annotate protos to support super.flow()
736
736
 
737
737
 
738
- if ((_this$options_ = this.options_) != null && _this$options_.bound && !isFlow(adm.target_[key])) {
738
+ if ((_this$options_ = this.options_) != null && _this$options_.bound && (!hasProp(adm.target_, key) || !isFlow(adm.target_[key]))) {
739
739
  if (this.extend_(adm, key, descriptor, false) === null) return 0
740
740
  /* Cancel */
741
741
  ;
@@ -779,16 +779,23 @@ safeDescriptors) {
779
779
  }
780
780
 
781
781
  assertFlowDescriptor(adm, annotation, key, descriptor);
782
- var value = descriptor.value;
782
+ var value = descriptor.value; // In case of flow.bound, the descriptor can be from already annotated prototype
783
+
784
+ if (!isFlow(value)) {
785
+ value = flow(value);
786
+ }
783
787
 
784
788
  if (bound) {
785
789
  var _adm$proxy_;
786
790
 
787
- value = value.bind((_adm$proxy_ = adm.proxy_) != null ? _adm$proxy_ : adm.target_);
791
+ // We do not keep original function around, so we bind the existing flow
792
+ value = value.bind((_adm$proxy_ = adm.proxy_) != null ? _adm$proxy_ : adm.target_); // This is normally set by `flow`, but `bind` returns new function...
793
+
794
+ value.isMobXFlow = true;
788
795
  }
789
796
 
790
797
  return {
791
- value: flow(value),
798
+ value: value,
792
799
  // Non-configurable for classes
793
800
  // prevents accidental field redefinition in subclass
794
801
  configurable: safeDescriptors ? adm.isPlainObject_ : true,
@@ -3224,7 +3231,10 @@ function toJSHelper(source, __alreadySeen) {
3224
3231
  }
3225
3232
  }
3226
3233
  /**
3227
- * Basically, a deep clone, so that no reactive property will exist anymore.
3234
+ * Recursively converts an observable to it's non-observable native counterpart.
3235
+ * It does NOT recurse into non-observables, these are left as they are, even if they contain observables.
3236
+ * Computed and other non-enumerable properties are completely ignored.
3237
+ * Complex scenarios require custom solution, eg implementing `toJSON` or using `serializr` lib.
3228
3238
  */
3229
3239
 
3230
3240
 
@@ -4016,6 +4026,8 @@ _Symbol$toStringTag = Symbol.toStringTag;
4016
4026
  var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTag2) {
4017
4027
  // hasMap, not hashMap >-).
4018
4028
  function ObservableMap(initialData, enhancer_, name_) {
4029
+ var _this = this;
4030
+
4019
4031
  if (enhancer_ === void 0) {
4020
4032
  enhancer_ = deepEnhancer;
4021
4033
  }
@@ -4043,7 +4055,9 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
4043
4055
  this.keysAtom_ = createAtom( this.name_ + ".keys()" );
4044
4056
  this.data_ = new Map();
4045
4057
  this.hasMap_ = new Map();
4046
- this.merge(initialData);
4058
+ allowStateChanges(true, function () {
4059
+ _this.merge(initialData);
4060
+ });
4047
4061
  }
4048
4062
 
4049
4063
  var _proto = ObservableMap.prototype;
@@ -4053,7 +4067,7 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
4053
4067
  };
4054
4068
 
4055
4069
  _proto.has = function has(key) {
4056
- var _this = this;
4070
+ var _this2 = this;
4057
4071
 
4058
4072
  if (!globalState.trackingDerivation) return this.has_(key);
4059
4073
  var entry = this.hasMap_.get(key);
@@ -4062,7 +4076,7 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
4062
4076
  var newEntry = entry = new ObservableValue(this.has_(key), referenceEnhancer, this.name_ + "." + stringifyKey(key) + "?" , false);
4063
4077
  this.hasMap_.set(key, newEntry);
4064
4078
  onBecomeUnobserved(newEntry, function () {
4065
- return _this.hasMap_["delete"](key);
4079
+ return _this2.hasMap_["delete"](key);
4066
4080
  });
4067
4081
  }
4068
4082
 
@@ -4093,7 +4107,7 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
4093
4107
  };
4094
4108
 
4095
4109
  _proto["delete"] = function _delete(key) {
4096
- var _this2 = this;
4110
+ var _this3 = this;
4097
4111
 
4098
4112
  checkIfStateModificationsAreAllowed(this.keysAtom_);
4099
4113
 
@@ -4122,17 +4136,17 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
4122
4136
  if ( notifySpy) spyReportStart(_change); // TODO fix type
4123
4137
 
4124
4138
  transaction(function () {
4125
- var _this2$hasMap_$get;
4139
+ var _this3$hasMap_$get;
4126
4140
 
4127
- _this2.keysAtom_.reportChanged();
4141
+ _this3.keysAtom_.reportChanged();
4128
4142
 
4129
- (_this2$hasMap_$get = _this2.hasMap_.get(key)) == null ? void 0 : _this2$hasMap_$get.setNewValue_(false);
4143
+ (_this3$hasMap_$get = _this3.hasMap_.get(key)) == null ? void 0 : _this3$hasMap_$get.setNewValue_(false);
4130
4144
 
4131
- var observable = _this2.data_.get(key);
4145
+ var observable = _this3.data_.get(key);
4132
4146
 
4133
4147
  observable.setNewValue_(undefined);
4134
4148
 
4135
- _this2.data_["delete"](key);
4149
+ _this3.data_["delete"](key);
4136
4150
  });
4137
4151
  if (notify) notifyListeners(this, _change);
4138
4152
  if ( notifySpy) spyReportEnd();
@@ -4167,21 +4181,21 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
4167
4181
  };
4168
4182
 
4169
4183
  _proto.addValue_ = function addValue_(key, newValue) {
4170
- var _this3 = this;
4184
+ var _this4 = this;
4171
4185
 
4172
4186
  checkIfStateModificationsAreAllowed(this.keysAtom_);
4173
4187
  transaction(function () {
4174
- var _this3$hasMap_$get;
4188
+ var _this4$hasMap_$get;
4175
4189
 
4176
- var observable = new ObservableValue(newValue, _this3.enhancer_, _this3.name_ + "." + stringifyKey(key) , false);
4190
+ var observable = new ObservableValue(newValue, _this4.enhancer_, _this4.name_ + "." + stringifyKey(key) , false);
4177
4191
 
4178
- _this3.data_.set(key, observable);
4192
+ _this4.data_.set(key, observable);
4179
4193
 
4180
4194
  newValue = observable.value_; // value might have been changed
4181
4195
 
4182
- (_this3$hasMap_$get = _this3.hasMap_.get(key)) == null ? void 0 : _this3$hasMap_$get.setNewValue_(true);
4196
+ (_this4$hasMap_$get = _this4.hasMap_.get(key)) == null ? void 0 : _this4$hasMap_$get.setNewValue_(true);
4183
4197
 
4184
- _this3.keysAtom_.reportChanged();
4198
+ _this4.keysAtom_.reportChanged();
4185
4199
  });
4186
4200
  var notifySpy = isSpyEnabled();
4187
4201
  var notify = hasListeners(this);
@@ -4267,7 +4281,7 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
4267
4281
  ;
4268
4282
 
4269
4283
  _proto.merge = function merge(other) {
4270
- var _this4 = this;
4284
+ var _this5 = this;
4271
4285
 
4272
4286
  if (isObservableMap(other)) {
4273
4287
  other = new Map(other);
@@ -4275,15 +4289,15 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
4275
4289
 
4276
4290
  transaction(function () {
4277
4291
  if (isPlainObject(other)) getPlainObjectKeys(other).forEach(function (key) {
4278
- return _this4.set(key, other[key]);
4292
+ return _this5.set(key, other[key]);
4279
4293
  });else if (Array.isArray(other)) other.forEach(function (_ref) {
4280
4294
  var key = _ref[0],
4281
4295
  value = _ref[1];
4282
- return _this4.set(key, value);
4296
+ return _this5.set(key, value);
4283
4297
  });else if (isES6Map(other)) {
4284
4298
  if (other.constructor !== Map) die(19, other);
4285
4299
  other.forEach(function (value, key) {
4286
- return _this4.set(key, value);
4300
+ return _this5.set(key, value);
4287
4301
  });
4288
4302
  } else if (other !== null && other !== undefined) die(20, other);
4289
4303
  });
@@ -4291,21 +4305,21 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
4291
4305
  };
4292
4306
 
4293
4307
  _proto.clear = function clear() {
4294
- var _this5 = this;
4308
+ var _this6 = this;
4295
4309
 
4296
4310
  transaction(function () {
4297
4311
  untracked(function () {
4298
- for (var _iterator2 = _createForOfIteratorHelperLoose(_this5.keys()), _step2; !(_step2 = _iterator2()).done;) {
4312
+ for (var _iterator2 = _createForOfIteratorHelperLoose(_this6.keys()), _step2; !(_step2 = _iterator2()).done;) {
4299
4313
  var key = _step2.value;
4300
4314
 
4301
- _this5["delete"](key);
4315
+ _this6["delete"](key);
4302
4316
  }
4303
4317
  });
4304
4318
  });
4305
4319
  };
4306
4320
 
4307
4321
  _proto.replace = function replace(values) {
4308
- var _this6 = this;
4322
+ var _this7 = this;
4309
4323
 
4310
4324
  // Implementation requirements:
4311
4325
  // - respect ordering of replacement map
@@ -4322,13 +4336,13 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
4322
4336
  // if the key deletion is prevented by interceptor
4323
4337
  // add entry at the beginning of the result map
4324
4338
 
4325
- for (var _iterator3 = _createForOfIteratorHelperLoose(_this6.data_.keys()), _step3; !(_step3 = _iterator3()).done;) {
4339
+ for (var _iterator3 = _createForOfIteratorHelperLoose(_this7.data_.keys()), _step3; !(_step3 = _iterator3()).done;) {
4326
4340
  var key = _step3.value;
4327
4341
 
4328
4342
  // Concurrently iterating/deleting keys
4329
4343
  // iterator should handle this correctly
4330
4344
  if (!replacementMap.has(key)) {
4331
- var deleted = _this6["delete"](key); // Was the key removed?
4345
+ var deleted = _this7["delete"](key); // Was the key removed?
4332
4346
 
4333
4347
 
4334
4348
  if (deleted) {
@@ -4336,7 +4350,7 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
4336
4350
  keysReportChangedCalled = true;
4337
4351
  } else {
4338
4352
  // Delete prevented by interceptor
4339
- var value = _this6.data_.get(key);
4353
+ var value = _this7.data_.get(key);
4340
4354
 
4341
4355
  orderedData.set(key, value);
4342
4356
  }
@@ -4350,17 +4364,17 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
4350
4364
  _value = _step4$value[1];
4351
4365
 
4352
4366
  // We will want to know whether a new key is added
4353
- var keyExisted = _this6.data_.has(_key); // Add or update value
4367
+ var keyExisted = _this7.data_.has(_key); // Add or update value
4354
4368
 
4355
4369
 
4356
- _this6.set(_key, _value); // The addition could have been prevent by interceptor
4370
+ _this7.set(_key, _value); // The addition could have been prevent by interceptor
4357
4371
 
4358
4372
 
4359
- if (_this6.data_.has(_key)) {
4373
+ if (_this7.data_.has(_key)) {
4360
4374
  // The update could have been prevented by interceptor
4361
4375
  // and also we want to preserve existing values
4362
4376
  // so use value from _data map (instead of replacement map)
4363
- var _value2 = _this6.data_.get(_key);
4377
+ var _value2 = _this7.data_.get(_key);
4364
4378
 
4365
4379
  orderedData.set(_key, _value2); // Was a new key added?
4366
4380
 
@@ -4373,11 +4387,11 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
4373
4387
 
4374
4388
 
4375
4389
  if (!keysReportChangedCalled) {
4376
- if (_this6.data_.size !== orderedData.size) {
4390
+ if (_this7.data_.size !== orderedData.size) {
4377
4391
  // If size differs, keys are definitely modified
4378
- _this6.keysAtom_.reportChanged();
4392
+ _this7.keysAtom_.reportChanged();
4379
4393
  } else {
4380
- var iter1 = _this6.data_.keys();
4394
+ var iter1 = _this7.data_.keys();
4381
4395
 
4382
4396
  var iter2 = orderedData.keys();
4383
4397
  var next1 = iter1.next();
@@ -4385,7 +4399,7 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
4385
4399
 
4386
4400
  while (!next1.done) {
4387
4401
  if (next1.value !== next2.value) {
4388
- _this6.keysAtom_.reportChanged();
4402
+ _this7.keysAtom_.reportChanged();
4389
4403
 
4390
4404
  break;
4391
4405
  }
@@ -4397,7 +4411,7 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
4397
4411
  } // Use correctly ordered map
4398
4412
 
4399
4413
 
4400
- _this6.data_ = orderedData;
4414
+ _this7.data_ = orderedData;
4401
4415
  });
4402
4416
  return this;
4403
4417
  };
@@ -5606,7 +5620,7 @@ function eq(a, b, depth, aStack, bStack) {
5606
5620
  if (a !== a) return b !== b; // Exhaust primitive checks
5607
5621
 
5608
5622
  var type = typeof a;
5609
- if (!isFunction(type) && type !== "object" && typeof b != "object") return false; // Compare `[[Class]]` names.
5623
+ if (type !== "function" && type !== "object" && typeof b != "object") return false; // Compare `[[Class]]` names.
5610
5624
 
5611
5625
  var className = toString.call(a);
5612
5626
  if (className !== toString.call(b)) return false;