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.
- package/CHANGELOG.md +141 -117
- package/README.md +6 -3
- package/dist/api/annotation.d.ts +1 -1
- package/dist/api/makeObservable.d.ts +1 -1
- package/dist/core/action.d.ts +1 -1
- package/dist/core/computedvalue.d.ts +1 -1
- package/dist/mobx.cjs.development.js +53 -32
- package/dist/mobx.cjs.development.js.map +1 -1
- package/dist/mobx.cjs.production.min.js +1 -1
- package/dist/mobx.cjs.production.min.js.map +1 -1
- package/dist/mobx.esm.development.js +5109 -0
- package/dist/mobx.esm.development.js.map +1 -0
- package/dist/mobx.esm.js +51 -32
- package/dist/mobx.esm.js.map +1 -1
- package/dist/mobx.esm.production.min.js +2 -0
- package/dist/mobx.esm.production.min.js.map +1 -0
- package/dist/mobx.umd.development.js +53 -32
- package/dist/mobx.umd.development.js.map +1 -1
- package/dist/mobx.umd.production.min.js +1 -1
- package/dist/mobx.umd.production.min.js.map +1 -1
- package/dist/utils/utils.d.ts +1 -1
- package/package.json +72 -138
- package/src/api/annotation.ts +1 -1
- package/src/api/makeObservable.ts +12 -9
- package/src/core/action.ts +4 -4
- package/src/core/computedvalue.ts +1 -1
- package/src/types/observableobject.ts +8 -3
- package/src/types/observablevalue.ts +2 -1
- package/src/utils/global.ts +16 -3
- package/src/utils/utils.ts +2 -2
- package/dist/index.js.flow +0 -591
package/dist/mobx.esm.js
CHANGED
|
@@ -85,9 +85,21 @@ function die(error) {
|
|
|
85
85
|
throw new Error(typeof error === "number" ? "[MobX] minified error nr: " + error + (args.length ? " " + args.join(",") : "") + ". Find the full error at: https://github.com/mobxjs/mobx/blob/mobx6/src/errors.ts" : "[MobX] " + error);
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
+
var mockGlobal = {};
|
|
88
89
|
function getGlobal() {
|
|
89
|
-
|
|
90
|
-
|
|
90
|
+
if (typeof window !== "undefined") {
|
|
91
|
+
return window;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (typeof global !== "undefined") {
|
|
95
|
+
return global;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (typeof self !== "undefined") {
|
|
99
|
+
return self;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return mockGlobal;
|
|
91
103
|
}
|
|
92
104
|
|
|
93
105
|
var assign = Object.assign;
|
|
@@ -150,11 +162,11 @@ function isPlainObject(value) {
|
|
|
150
162
|
if (!isObject(value)) return false;
|
|
151
163
|
var proto = Object.getPrototypeOf(value);
|
|
152
164
|
if (proto == null) return true;
|
|
153
|
-
return ((_proto$constructor = proto.constructor)
|
|
165
|
+
return ((_proto$constructor = proto.constructor) == null ? void 0 : _proto$constructor.toString()) === plainObjectString;
|
|
154
166
|
} // https://stackoverflow.com/a/37865170
|
|
155
167
|
|
|
156
168
|
function isGenerator(obj) {
|
|
157
|
-
var constructor = obj
|
|
169
|
+
var constructor = obj == null ? void 0 : obj.constructor;
|
|
158
170
|
if (!constructor) return false;
|
|
159
171
|
if ("GeneratorFunction" === constructor.name || "GeneratorFunction" === constructor.displayName) return true;
|
|
160
172
|
return false;
|
|
@@ -178,12 +190,12 @@ function addHiddenFinalProp(object, propName, value) {
|
|
|
178
190
|
function assertPropertyConfigurable(object, prop) {
|
|
179
191
|
if (process.env.NODE_ENV !== "production") {
|
|
180
192
|
var descriptor = getDescriptor(object, prop);
|
|
181
|
-
if ((descriptor
|
|
193
|
+
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");
|
|
182
194
|
}
|
|
183
195
|
}
|
|
184
|
-
function createInstanceofPredicate(name,
|
|
196
|
+
function createInstanceofPredicate(name, theClass) {
|
|
185
197
|
var propName = "isMobX" + name;
|
|
186
|
-
|
|
198
|
+
theClass.prototype[propName] = true;
|
|
187
199
|
return function (x) {
|
|
188
200
|
return isObject(x) && x[propName] === true;
|
|
189
201
|
};
|
|
@@ -500,7 +512,7 @@ var annotationToEnhancer = (_annotationToEnhancer = {}, _annotationToEnhancer[OB
|
|
|
500
512
|
function getEnhancerFromAnnotation(annotation) {
|
|
501
513
|
var _annotationToEnhancer2;
|
|
502
514
|
|
|
503
|
-
return !annotation ? deepEnhancer : (_annotationToEnhancer2 = annotationToEnhancer[annotation.annotationType_])
|
|
515
|
+
return !annotation ? deepEnhancer : (_annotationToEnhancer2 = annotationToEnhancer[annotation.annotationType_]) != null ? _annotationToEnhancer2 : die(12);
|
|
504
516
|
}
|
|
505
517
|
/**
|
|
506
518
|
* Turns an object, array or function into a reactive structure.
|
|
@@ -544,7 +556,7 @@ var observableFactories = {
|
|
|
544
556
|
object: function object(props, decorators, options) {
|
|
545
557
|
var o = asCreateObservableOptions(options);
|
|
546
558
|
var base = {};
|
|
547
|
-
asObservableObject(base, options
|
|
559
|
+
asObservableObject(base, options == null ? void 0 : options.name, getEnhancerFromOption(o));
|
|
548
560
|
return extendObservable(globalState.useProxies === false || o.proxy === false ? base : createDynamicObservableObject(base), props, decorators, options);
|
|
549
561
|
},
|
|
550
562
|
ref: /*#__PURE__*/createDecorator(OBSERVABLE_REF),
|
|
@@ -598,7 +610,7 @@ var _getDescriptor$config, _getDescriptor;
|
|
|
598
610
|
|
|
599
611
|
var currentActionId = 0;
|
|
600
612
|
var nextActionId = 1;
|
|
601
|
-
var isFunctionNameConfigurable = (_getDescriptor$config = (_getDescriptor = /*#__PURE__*/getDescriptor(function () {}, "name"))
|
|
613
|
+
var isFunctionNameConfigurable = (_getDescriptor$config = (_getDescriptor = /*#__PURE__*/getDescriptor(function () {}, "name")) == null ? void 0 : _getDescriptor.configurable) != null ? _getDescriptor$config : false; // we can safely recycle this object
|
|
602
614
|
|
|
603
615
|
var tmpNameDescriptor = {
|
|
604
616
|
value: "action",
|
|
@@ -641,24 +653,24 @@ function executeAction(actionName, canRunAsDerivation, fn, scope, args) {
|
|
|
641
653
|
_endAction(runInfo);
|
|
642
654
|
}
|
|
643
655
|
}
|
|
644
|
-
function _startAction(actionName,
|
|
656
|
+
function _startAction(actionName, canRunAsDerivation, // true for autoAction
|
|
645
657
|
scope, args) {
|
|
646
658
|
var notifySpy_ = process.env.NODE_ENV !== "production" && isSpyEnabled() && !!actionName;
|
|
647
659
|
var startTime_ = 0;
|
|
648
660
|
|
|
649
661
|
if (process.env.NODE_ENV !== "production" && notifySpy_) {
|
|
650
662
|
startTime_ = Date.now();
|
|
651
|
-
var
|
|
663
|
+
var flattenedArgs = args ? Array.from(args) : EMPTY_ARRAY;
|
|
652
664
|
spyReportStart({
|
|
653
665
|
type: ACTION,
|
|
654
666
|
name: actionName,
|
|
655
667
|
object: scope,
|
|
656
|
-
arguments:
|
|
668
|
+
arguments: flattenedArgs
|
|
657
669
|
});
|
|
658
670
|
}
|
|
659
671
|
|
|
660
672
|
var prevDerivation_ = globalState.trackingDerivation;
|
|
661
|
-
var runAsAction = !
|
|
673
|
+
var runAsAction = !canRunAsDerivation || !prevDerivation_;
|
|
662
674
|
startBatch();
|
|
663
675
|
var prevAllowStateChanges_ = globalState.allowStateChanges; // by default preserve previous allow
|
|
664
676
|
|
|
@@ -1006,7 +1018,7 @@ var ComputedValue = /*#__PURE__*/function () {
|
|
|
1006
1018
|
*
|
|
1007
1019
|
* The `equals` property specifies the comparer function to use to determine if a newly produced
|
|
1008
1020
|
* value differs from the previous value. Two comparers are provided in the library; `defaultComparer`
|
|
1009
|
-
* compares based on identity comparison (===), and `
|
|
1021
|
+
* compares based on identity comparison (===), and `structuralComparer` deeply compares the structure.
|
|
1010
1022
|
* Structural comparison can be convenient if you always produce a new aggregated object and
|
|
1011
1023
|
* don't want to notify observers if it is structurally the same.
|
|
1012
1024
|
* This is useful for working with vectors, mouse coordinates etc.
|
|
@@ -2350,7 +2362,7 @@ function extendObservable(target, properties, annotations, options) {
|
|
|
2350
2362
|
try {
|
|
2351
2363
|
var descs = getOwnPropertyDescriptors(properties);
|
|
2352
2364
|
getPlainObjectKeys(descs).forEach(function (key) {
|
|
2353
|
-
makeProperty(adm, target, key, descs[key], !annotations ? true : key in annotations ? annotations[key] : true, true, !!(options
|
|
2365
|
+
makeProperty(adm, target, key, descs[key], !annotations ? true : key in annotations ? annotations[key] : true, true, !!(options == null ? void 0 : options.autoBind));
|
|
2354
2366
|
});
|
|
2355
2367
|
} finally {
|
|
2356
2368
|
endBatch();
|
|
@@ -2445,7 +2457,7 @@ var flow = /*#__PURE__*/Object.assign(function flow(arg1, arg2) {
|
|
|
2445
2457
|
}
|
|
2446
2458
|
|
|
2447
2459
|
function next(ret) {
|
|
2448
|
-
if (isFunction(ret
|
|
2460
|
+
if (isFunction(ret == null ? void 0 : ret.then)) {
|
|
2449
2461
|
// an async iterator
|
|
2450
2462
|
ret.then(next, reject);
|
|
2451
2463
|
return;
|
|
@@ -2492,7 +2504,7 @@ function flowResult(result) {
|
|
|
2492
2504
|
return result; // just tricking TypeScript :)
|
|
2493
2505
|
}
|
|
2494
2506
|
function isFlow(fn) {
|
|
2495
|
-
return (fn
|
|
2507
|
+
return (fn == null ? void 0 : fn.isMobXFlow) === true;
|
|
2496
2508
|
}
|
|
2497
2509
|
|
|
2498
2510
|
function interceptReads(thing, propOrHandler, handler) {
|
|
@@ -3037,7 +3049,7 @@ function getInferredAnnotation(desc, defaultAnnotation, autoBind) {
|
|
|
3037
3049
|
|
|
3038
3050
|
if (isFunction(desc.value)) return isGenerator(desc.value) ? flow : isAction(desc.value) ? false : autoBind ? autoAction.bound : autoAction; // if (!desc.configurable || !desc.writable) return false
|
|
3039
3051
|
|
|
3040
|
-
return defaultAnnotation
|
|
3052
|
+
return defaultAnnotation != null ? defaultAnnotation : observable.deep;
|
|
3041
3053
|
}
|
|
3042
3054
|
|
|
3043
3055
|
function getDescriptorInChain(target, prop) {
|
|
@@ -3064,7 +3076,7 @@ autoBind) {
|
|
|
3064
3076
|
var target = adm.target_;
|
|
3065
3077
|
var defaultAnnotation = observable; // ideally grap this from adm's defaultEnahncer instead!
|
|
3066
3078
|
|
|
3067
|
-
var
|
|
3079
|
+
var originAnnotation = annotation;
|
|
3068
3080
|
|
|
3069
3081
|
if (annotation === true) {
|
|
3070
3082
|
annotation = getInferredAnnotation(descriptor, defaultAnnotation, autoBind);
|
|
@@ -3138,20 +3150,20 @@ autoBind) {
|
|
|
3138
3150
|
case OBSERVABLE_STRUCT:
|
|
3139
3151
|
{
|
|
3140
3152
|
if (process.env.NODE_ENV !== "production" && isObservableProp(target, key)) die("Cannot decorate '" + key.toString() + "': the property is already decorated as observable.");
|
|
3141
|
-
if (process.env.NODE_ENV !== "production" && !("value" in descriptor)) die("Cannot decorate '" + key.toString() + "': observable cannot be used on setter / getter properties."); // if the
|
|
3153
|
+
if (process.env.NODE_ENV !== "production" && !("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
|
|
3142
3154
|
|
|
3143
|
-
var enhancer =
|
|
3155
|
+
var enhancer = originAnnotation === true ? adm.defaultEnhancer_ : getEnhancerFromAnnotation(annotation);
|
|
3144
3156
|
adm.addObservableProp_(key, descriptor.value, enhancer);
|
|
3145
3157
|
break;
|
|
3146
3158
|
}
|
|
3147
3159
|
|
|
3148
3160
|
default:
|
|
3149
|
-
if (process.env.NODE_ENV !== "production") die("invalid decorator '" + ((_annotation$annotatio = annotation.annotationType_)
|
|
3161
|
+
if (process.env.NODE_ENV !== "production") die("invalid decorator '" + ((_annotation$annotatio = annotation.annotationType_) != null ? _annotation$annotatio : annotation) + "' for '" + key.toString() + "'");
|
|
3150
3162
|
}
|
|
3151
3163
|
}
|
|
3152
3164
|
function makeObservable(target, annotations, options) {
|
|
3153
|
-
var autoBind = !!(options
|
|
3154
|
-
var adm = asObservableObject(target, options
|
|
3165
|
+
var autoBind = !!(options == null ? void 0 : options.autoBind);
|
|
3166
|
+
var adm = asObservableObject(target, options == null ? void 0 : options.name, getEnhancerFromAnnotation(options == null ? void 0 : options.defaultDecorator));
|
|
3155
3167
|
startBatch();
|
|
3156
3168
|
|
|
3157
3169
|
try {
|
|
@@ -3178,7 +3190,7 @@ function makeObservable(target, annotations, options) {
|
|
|
3178
3190
|
|
|
3179
3191
|
return target;
|
|
3180
3192
|
}
|
|
3181
|
-
function makeAutoObservable(target,
|
|
3193
|
+
function makeAutoObservable(target, overrides, options) {
|
|
3182
3194
|
var proto = Object.getPrototypeOf(target);
|
|
3183
3195
|
var isPlain = proto == null || proto === objectPrototype;
|
|
3184
3196
|
|
|
@@ -3193,7 +3205,7 @@ function makeAutoObservable(target, excludes, options) {
|
|
|
3193
3205
|
// shortcut, reuse inferred annotations for this type from the previous time
|
|
3194
3206
|
annotations = proto[CACHED_ANNOTATIONS];
|
|
3195
3207
|
} else {
|
|
3196
|
-
annotations = _extends({},
|
|
3208
|
+
annotations = _extends({}, overrides);
|
|
3197
3209
|
extractAnnotationsFromObject(target, annotations, options);
|
|
3198
3210
|
|
|
3199
3211
|
if (!isPlain) {
|
|
@@ -3209,8 +3221,8 @@ function makeAutoObservable(target, excludes, options) {
|
|
|
3209
3221
|
function extractAnnotationsFromObject(target, collector, options) {
|
|
3210
3222
|
var _options$defaultDecor;
|
|
3211
3223
|
|
|
3212
|
-
var autoBind = !!(options
|
|
3213
|
-
var defaultAnnotation = (options
|
|
3224
|
+
var autoBind = !!(options == null ? void 0 : options.autoBind);
|
|
3225
|
+
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;
|
|
3214
3226
|
Object.entries(getOwnPropertyDescriptors(target)).forEach(function (_ref) {
|
|
3215
3227
|
var key = _ref[0],
|
|
3216
3228
|
descriptor = _ref[1];
|
|
@@ -3228,7 +3240,7 @@ function extractAnnotationsFromProto(proto, collector, options) {
|
|
|
3228
3240
|
if (prop.get) {
|
|
3229
3241
|
collector[key] = computed;
|
|
3230
3242
|
} else if (isFunction(prop.value)) {
|
|
3231
|
-
collector[key] = isGenerator(prop.value) ? flow : (options
|
|
3243
|
+
collector[key] = isGenerator(prop.value) ? flow : (options == null ? void 0 : options.autoBind) ? autoAction.bound : autoAction;
|
|
3232
3244
|
}
|
|
3233
3245
|
});
|
|
3234
3246
|
}
|
|
@@ -4680,8 +4692,15 @@ function asObservableObject(target, name, defaultEnhancer) {
|
|
|
4680
4692
|
|
|
4681
4693
|
if (hasProp(target, $mobx)) return target[$mobx];
|
|
4682
4694
|
if (process.env.NODE_ENV !== "production" && !Object.isExtensible(target)) die("Cannot make the designated object observable; it is not extensible");
|
|
4683
|
-
|
|
4684
|
-
if (!name)
|
|
4695
|
+
|
|
4696
|
+
if (!name) {
|
|
4697
|
+
if (isPlainObject(target)) {
|
|
4698
|
+
name = "ObservableObject@" + getNextId();
|
|
4699
|
+
} else {
|
|
4700
|
+
name = (target.constructor.name || "ObservableObject") + "@" + getNextId();
|
|
4701
|
+
}
|
|
4702
|
+
}
|
|
4703
|
+
|
|
4685
4704
|
var adm = new ObservableObjectAdministration(target, new Map(), stringifyKey(name), defaultEnhancer);
|
|
4686
4705
|
addHiddenProp(target, $mobx, adm);
|
|
4687
4706
|
return adm;
|