mobx 6.0.0 → 6.0.4

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.
@@ -89,9 +89,21 @@
89
89
  }
90
90
  }
91
91
 
92
+ var mockGlobal = {};
92
93
  function getGlobal() {
93
- // @ts-ignore
94
- return typeof global !== "undefined" ? global : window;
94
+ if (typeof window !== "undefined") {
95
+ return window;
96
+ }
97
+
98
+ if (typeof global !== "undefined") {
99
+ return global;
100
+ }
101
+
102
+ if (typeof self !== "undefined") {
103
+ return self;
104
+ }
105
+
106
+ return mockGlobal;
95
107
  }
96
108
 
97
109
  var assign = Object.assign;
@@ -154,11 +166,11 @@
154
166
  if (!isObject(value)) return false;
155
167
  var proto = Object.getPrototypeOf(value);
156
168
  if (proto == null) return true;
157
- return ((_proto$constructor = proto.constructor) === null || _proto$constructor === void 0 ? void 0 : _proto$constructor.toString()) === plainObjectString;
169
+ return ((_proto$constructor = proto.constructor) == null ? void 0 : _proto$constructor.toString()) === plainObjectString;
158
170
  } // https://stackoverflow.com/a/37865170
159
171
 
160
172
  function isGenerator(obj) {
161
- var constructor = obj === null || obj === void 0 ? void 0 : obj.constructor;
173
+ var constructor = obj == null ? void 0 : obj.constructor;
162
174
  if (!constructor) return false;
163
175
  if ("GeneratorFunction" === constructor.name || "GeneratorFunction" === constructor.displayName) return true;
164
176
  return false;
@@ -182,12 +194,12 @@
182
194
  function assertPropertyConfigurable(object, prop) {
183
195
  {
184
196
  var descriptor = getDescriptor(object, prop);
185
- if ((descriptor === null || descriptor === void 0 ? void 0 : descriptor.configurable) === false || (descriptor === null || descriptor === void 0 ? void 0 : descriptor.writable) === false) die("Cannot make property '" + stringifyKey(prop) + "' observable, it is not configurable and writable in the target object");
197
+ if ((descriptor == null ? void 0 : descriptor.configurable) === false || (descriptor == null ? void 0 : descriptor.writable) === false) die("Cannot make property '" + stringifyKey(prop) + "' observable, it is not configurable and writable in the target object");
186
198
  }
187
199
  }
188
- function createInstanceofPredicate(name, clazz) {
200
+ function createInstanceofPredicate(name, theClass) {
189
201
  var propName = "isMobX" + name;
190
- clazz.prototype[propName] = true;
202
+ theClass.prototype[propName] = true;
191
203
  return function (x) {
192
204
  return isObject(x) && x[propName] === true;
193
205
  };
@@ -504,7 +516,7 @@
504
516
  function getEnhancerFromAnnotation(annotation) {
505
517
  var _annotationToEnhancer2;
506
518
 
507
- return !annotation ? deepEnhancer : (_annotationToEnhancer2 = annotationToEnhancer[annotation.annotationType_]) !== null && _annotationToEnhancer2 !== void 0 ? _annotationToEnhancer2 : die(12);
519
+ return !annotation ? deepEnhancer : (_annotationToEnhancer2 = annotationToEnhancer[annotation.annotationType_]) != null ? _annotationToEnhancer2 : die(12);
508
520
  }
509
521
  /**
510
522
  * Turns an object, array or function into a reactive structure.
@@ -548,7 +560,7 @@
548
560
  object: function object(props, decorators, options) {
549
561
  var o = asCreateObservableOptions(options);
550
562
  var base = {};
551
- asObservableObject(base, options === null || options === void 0 ? void 0 : options.name, getEnhancerFromOption(o));
563
+ asObservableObject(base, options == null ? void 0 : options.name, getEnhancerFromOption(o));
552
564
  return extendObservable(globalState.useProxies === false || o.proxy === false ? base : createDynamicObservableObject(base), props, decorators, options);
553
565
  },
554
566
  ref: /*#__PURE__*/createDecorator(OBSERVABLE_REF),
@@ -602,7 +614,7 @@
602
614
 
603
615
  var currentActionId = 0;
604
616
  var nextActionId = 1;
605
- var isFunctionNameConfigurable = (_getDescriptor$config = (_getDescriptor = /*#__PURE__*/getDescriptor(function () {}, "name")) === null || _getDescriptor === void 0 ? void 0 : _getDescriptor.configurable) !== null && _getDescriptor$config !== void 0 ? _getDescriptor$config : false; // we can safely recycle this object
617
+ var isFunctionNameConfigurable = (_getDescriptor$config = (_getDescriptor = /*#__PURE__*/getDescriptor(function () {}, "name")) == null ? void 0 : _getDescriptor.configurable) != null ? _getDescriptor$config : false; // we can safely recycle this object
606
618
 
607
619
  var tmpNameDescriptor = {
608
620
  value: "action",
@@ -645,24 +657,24 @@
645
657
  _endAction(runInfo);
646
658
  }
647
659
  }
648
- function _startAction(actionName, canRunAsDeriviation, // true for autoAction
660
+ function _startAction(actionName, canRunAsDerivation, // true for autoAction
649
661
  scope, args) {
650
662
  var notifySpy_ = isSpyEnabled() && !!actionName;
651
663
  var startTime_ = 0;
652
664
 
653
665
  if ( notifySpy_) {
654
666
  startTime_ = Date.now();
655
- var flattendArgs = args ? Array.from(args) : EMPTY_ARRAY;
667
+ var flattenedArgs = args ? Array.from(args) : EMPTY_ARRAY;
656
668
  spyReportStart({
657
669
  type: ACTION,
658
670
  name: actionName,
659
671
  object: scope,
660
- arguments: flattendArgs
672
+ arguments: flattenedArgs
661
673
  });
662
674
  }
663
675
 
664
676
  var prevDerivation_ = globalState.trackingDerivation;
665
- var runAsAction = !canRunAsDeriviation || !prevDerivation_;
677
+ var runAsAction = !canRunAsDerivation || !prevDerivation_;
666
678
  startBatch();
667
679
  var prevAllowStateChanges_ = globalState.allowStateChanges; // by default preserve previous allow
668
680
 
@@ -1010,7 +1022,7 @@
1010
1022
  *
1011
1023
  * The `equals` property specifies the comparer function to use to determine if a newly produced
1012
1024
  * value differs from the previous value. Two comparers are provided in the library; `defaultComparer`
1013
- * compares based on identity comparison (===), and `structualComparer` deeply compares the structure.
1025
+ * compares based on identity comparison (===), and `structuralComparer` deeply compares the structure.
1014
1026
  * Structural comparison can be convenient if you always produce a new aggregated object and
1015
1027
  * don't want to notify observers if it is structurally the same.
1016
1028
  * This is useful for working with vectors, mouse coordinates etc.
@@ -2343,7 +2355,7 @@
2343
2355
  try {
2344
2356
  var descs = getOwnPropertyDescriptors(properties);
2345
2357
  getPlainObjectKeys(descs).forEach(function (key) {
2346
- makeProperty(adm, target, key, descs[key], !annotations ? true : key in annotations ? annotations[key] : true, true, !!(options === null || options === void 0 ? void 0 : options.autoBind));
2358
+ makeProperty(adm, target, key, descs[key], !annotations ? true : key in annotations ? annotations[key] : true, true, !!(options == null ? void 0 : options.autoBind));
2347
2359
  });
2348
2360
  } finally {
2349
2361
  endBatch();
@@ -2438,7 +2450,7 @@
2438
2450
  }
2439
2451
 
2440
2452
  function next(ret) {
2441
- if (isFunction(ret === null || ret === void 0 ? void 0 : ret.then)) {
2453
+ if (isFunction(ret == null ? void 0 : ret.then)) {
2442
2454
  // an async iterator
2443
2455
  ret.then(next, reject);
2444
2456
  return;
@@ -2485,7 +2497,7 @@
2485
2497
  return result; // just tricking TypeScript :)
2486
2498
  }
2487
2499
  function isFlow(fn) {
2488
- return (fn === null || fn === void 0 ? void 0 : fn.isMobXFlow) === true;
2500
+ return (fn == null ? void 0 : fn.isMobXFlow) === true;
2489
2501
  }
2490
2502
 
2491
2503
  function interceptReads(thing, propOrHandler, handler) {
@@ -3029,7 +3041,7 @@
3029
3041
 
3030
3042
  if (isFunction(desc.value)) return isGenerator(desc.value) ? flow : isAction(desc.value) ? false : autoBind ? autoAction.bound : autoAction; // if (!desc.configurable || !desc.writable) return false
3031
3043
 
3032
- return defaultAnnotation !== null && defaultAnnotation !== void 0 ? defaultAnnotation : observable.deep;
3044
+ return defaultAnnotation != null ? defaultAnnotation : observable.deep;
3033
3045
  }
3034
3046
 
3035
3047
  function getDescriptorInChain(target, prop) {
@@ -3056,7 +3068,7 @@
3056
3068
  var target = adm.target_;
3057
3069
  var defaultAnnotation = observable; // ideally grap this from adm's defaultEnahncer instead!
3058
3070
 
3059
- var origAnnotation = annotation;
3071
+ var originAnnotation = annotation;
3060
3072
 
3061
3073
  if (annotation === true) {
3062
3074
  annotation = getInferredAnnotation(descriptor, defaultAnnotation, autoBind);
@@ -3130,20 +3142,20 @@
3130
3142
  case OBSERVABLE_STRUCT:
3131
3143
  {
3132
3144
  if ( isObservableProp(target, key)) die("Cannot decorate '" + key.toString() + "': the property is already decorated as observable.");
3133
- if ( !("value" in descriptor)) die("Cannot decorate '" + key.toString() + "': observable cannot be used on setter / getter properties."); // if the origAnnotation was true, preferred the adm's default enhancer over the inferred one
3145
+ if ( !("value" in descriptor)) die("Cannot decorate '" + key.toString() + "': observable cannot be used on setter / getter properties."); // if the originAnnotation was true, preferred the adm's default enhancer over the inferred one
3134
3146
 
3135
- var enhancer = origAnnotation === true ? adm.defaultEnhancer_ : getEnhancerFromAnnotation(annotation);
3147
+ var enhancer = originAnnotation === true ? adm.defaultEnhancer_ : getEnhancerFromAnnotation(annotation);
3136
3148
  adm.addObservableProp_(key, descriptor.value, enhancer);
3137
3149
  break;
3138
3150
  }
3139
3151
 
3140
3152
  default:
3141
- die("invalid decorator '" + ((_annotation$annotatio = annotation.annotationType_) !== null && _annotation$annotatio !== void 0 ? _annotation$annotatio : annotation) + "' for '" + key.toString() + "'");
3153
+ die("invalid decorator '" + ((_annotation$annotatio = annotation.annotationType_) != null ? _annotation$annotatio : annotation) + "' for '" + key.toString() + "'");
3142
3154
  }
3143
3155
  }
3144
3156
  function makeObservable(target, annotations, options) {
3145
- var autoBind = !!(options === null || options === void 0 ? void 0 : options.autoBind);
3146
- var adm = asObservableObject(target, options === null || options === void 0 ? void 0 : options.name, getEnhancerFromAnnotation(options === null || options === void 0 ? void 0 : options.defaultDecorator));
3157
+ var autoBind = !!(options == null ? void 0 : options.autoBind);
3158
+ var adm = asObservableObject(target, options == null ? void 0 : options.name, getEnhancerFromAnnotation(options == null ? void 0 : options.defaultDecorator));
3147
3159
  startBatch();
3148
3160
 
3149
3161
  try {
@@ -3170,7 +3182,7 @@
3170
3182
 
3171
3183
  return target;
3172
3184
  }
3173
- function makeAutoObservable(target, excludes, options) {
3185
+ function makeAutoObservable(target, overrides, options) {
3174
3186
  var proto = Object.getPrototypeOf(target);
3175
3187
  var isPlain = proto == null || proto === objectPrototype;
3176
3188
 
@@ -3185,7 +3197,7 @@
3185
3197
  // shortcut, reuse inferred annotations for this type from the previous time
3186
3198
  annotations = proto[CACHED_ANNOTATIONS];
3187
3199
  } else {
3188
- annotations = _extends({}, excludes);
3200
+ annotations = _extends({}, overrides);
3189
3201
  extractAnnotationsFromObject(target, annotations, options);
3190
3202
 
3191
3203
  if (!isPlain) {
@@ -3201,8 +3213,8 @@
3201
3213
  function extractAnnotationsFromObject(target, collector, options) {
3202
3214
  var _options$defaultDecor;
3203
3215
 
3204
- var autoBind = !!(options === null || options === void 0 ? void 0 : options.autoBind);
3205
- var defaultAnnotation = (options === null || options === void 0 ? void 0 : options.deep) ? observable.deep : (_options$defaultDecor = options === null || options === void 0 ? void 0 : options.defaultDecorator) !== null && _options$defaultDecor !== void 0 ? _options$defaultDecor : observable.deep;
3216
+ var autoBind = !!(options == null ? void 0 : options.autoBind);
3217
+ var defaultAnnotation = (options == null ? void 0 : options.deep) === undefined ? (_options$defaultDecor = options == null ? void 0 : options.defaultDecorator) != null ? _options$defaultDecor : observable.deep : (options == null ? void 0 : options.deep) ? observable.deep : observable.ref;
3206
3218
  Object.entries(getOwnPropertyDescriptors(target)).forEach(function (_ref) {
3207
3219
  var key = _ref[0],
3208
3220
  descriptor = _ref[1];
@@ -3220,7 +3232,7 @@
3220
3232
  if (prop.get) {
3221
3233
  collector[key] = computed;
3222
3234
  } else if (isFunction(prop.value)) {
3223
- collector[key] = isGenerator(prop.value) ? flow : (options === null || options === void 0 ? void 0 : options.autoBind) ? autoAction.bound : autoAction;
3235
+ collector[key] = isGenerator(prop.value) ? flow : (options == null ? void 0 : options.autoBind) ? autoAction.bound : autoAction;
3224
3236
  }
3225
3237
  });
3226
3238
  }
@@ -4672,8 +4684,15 @@
4672
4684
 
4673
4685
  if (hasProp(target, $mobx)) return target[$mobx];
4674
4686
  if ( !Object.isExtensible(target)) die("Cannot make the designated object observable; it is not extensible");
4675
- if (!isPlainObject(target)) name = (target.constructor.name || "ObservableObject") + "@" + getNextId();
4676
- if (!name) name = "ObservableObject@" + getNextId();
4687
+
4688
+ if (!name) {
4689
+ if (isPlainObject(target)) {
4690
+ name = "ObservableObject@" + getNextId();
4691
+ } else {
4692
+ name = (target.constructor.name || "ObservableObject") + "@" + getNextId();
4693
+ }
4694
+ }
4695
+
4677
4696
  var adm = new ObservableObjectAdministration(target, new Map(), stringifyKey(name), defaultEnhancer);
4678
4697
  addHiddenProp(target, $mobx, adm);
4679
4698
  return adm;
@@ -5157,5 +5176,7 @@
5157
5176
  exports.values = values;
5158
5177
  exports.when = when;
5159
5178
 
5179
+ Object.defineProperty(exports, '__esModule', { value: true });
5180
+
5160
5181
  })));
5161
5182
  //# sourceMappingURL=mobx.umd.development.js.map