mobx 6.3.11 → 6.4.1
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 +28 -0
- package/README.md +1 -0
- package/dist/api/intercept.d.ts +1 -1
- package/dist/api/observe.d.ts +1 -1
- package/dist/errors.d.ts +2 -2
- package/dist/mobx.cjs.development.js +991 -303
- 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 +991 -303
- package/dist/mobx.esm.development.js.map +1 -1
- package/dist/mobx.esm.js +1006 -306
- package/dist/mobx.esm.js.map +1 -1
- package/dist/mobx.esm.production.min.js +1 -1
- package/dist/mobx.esm.production.min.js.map +1 -1
- package/dist/mobx.umd.development.js +991 -303
- 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/types/observablemap.d.ts +2 -2
- package/dist/utils/utils.d.ts +1 -1
- package/package.json +1 -1
- package/src/api/action.ts +8 -3
- package/src/api/annotation.ts +1 -2
- package/src/api/autorun.ts +22 -8
- package/src/api/computed.ts +5 -2
- package/src/api/configure.ts +6 -2
- package/src/api/extendobservable.ts +11 -5
- package/src/api/extras.ts +4 -2
- package/src/api/flow.ts +11 -4
- package/src/api/intercept-read.ts +4 -2
- package/src/api/intercept.ts +6 -3
- package/src/api/iscomputed.ts +10 -4
- package/src/api/isobservable.ts +10 -4
- package/src/api/makeObservable.ts +4 -2
- package/src/api/object-api.ts +30 -16
- package/src/api/observable.ts +23 -9
- package/src/api/observe.ts +5 -3
- package/src/api/tojs.ts +7 -3
- package/src/api/trace.ts +6 -2
- package/src/api/when.ts +12 -5
- package/src/core/action.ts +8 -3
- package/src/core/computedvalue.ts +29 -9
- package/src/core/derivation.ts +25 -9
- package/src/core/globalstate.ts +18 -7
- package/src/core/observable.ts +14 -5
- package/src/core/reaction.ts +15 -6
- package/src/core/spy.ts +20 -7
- package/src/errors.ts +2 -2
- package/src/types/actionannotation.ts +2 -2
- package/src/types/dynamicobject.ts +10 -4
- package/src/types/flowannotation.ts +14 -4
- package/src/types/intercept-utils.ts +9 -3
- package/src/types/legacyobservablearray.ts +5 -3
- package/src/types/listen-utils.ts +6 -2
- package/src/types/modifiers.ts +39 -14
- package/src/types/observablearray.ts +78 -30
- package/src/types/observablemap.ts +65 -26
- package/src/types/observableobject.ts +52 -18
- package/src/types/observableset.ts +29 -10
- package/src/types/observablevalue.ts +13 -5
- package/src/types/type-utils.ts +33 -11
- package/src/utils/comparer.ts +4 -4
- package/src/utils/eq.ts +45 -15
- package/src/utils/utils.ts +42 -20
|
@@ -27,9 +27,9 @@ var niceErrors = {
|
|
|
27
27
|
10: "'has()' can only be used on observable objects, arrays and maps",
|
|
28
28
|
11: "'get()' can only be used on observable objects, arrays and maps",
|
|
29
29
|
12: "Invalid annotation",
|
|
30
|
-
13: "Dynamic observable objects cannot be frozen",
|
|
30
|
+
13: "Dynamic observable objects cannot be frozen. If you're passing observables to 3rd party component/function that calls Object.freeze, pass copy instead: toJS(observable)",
|
|
31
31
|
14: "Intercept handlers should return nothing or a change object",
|
|
32
|
-
15: "Observable arrays cannot be frozen",
|
|
32
|
+
15: "Observable arrays cannot be frozen. If you're passing observables to 3rd party component/function that calls Object.freeze, pass copy instead: toJS(observable)",
|
|
33
33
|
16: "Modification exception: the internal structure of an observable array was changed.",
|
|
34
34
|
17: function _(index, length) {
|
|
35
35
|
return "[mobx.array] Index out of bounds, " + index + " is larger than " + length;
|
|
@@ -143,7 +143,10 @@ function getNextId() {
|
|
|
143
143
|
function once(func) {
|
|
144
144
|
var invoked = false;
|
|
145
145
|
return function () {
|
|
146
|
-
if (invoked)
|
|
146
|
+
if (invoked) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
|
|
147
150
|
invoked = true;
|
|
148
151
|
return func.apply(this, arguments);
|
|
149
152
|
};
|
|
@@ -168,17 +171,31 @@ function isObject(value) {
|
|
|
168
171
|
return value !== null && typeof value === "object";
|
|
169
172
|
}
|
|
170
173
|
function isPlainObject(value) {
|
|
171
|
-
if (!isObject(value))
|
|
174
|
+
if (!isObject(value)) {
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
|
|
172
178
|
var proto = Object.getPrototypeOf(value);
|
|
173
|
-
|
|
179
|
+
|
|
180
|
+
if (proto == null) {
|
|
181
|
+
return true;
|
|
182
|
+
}
|
|
183
|
+
|
|
174
184
|
var protoConstructor = Object.hasOwnProperty.call(proto, "constructor") && proto.constructor;
|
|
175
185
|
return typeof protoConstructor === "function" && protoConstructor.toString() === plainObjectString;
|
|
176
186
|
} // https://stackoverflow.com/a/37865170
|
|
177
187
|
|
|
178
188
|
function isGenerator(obj) {
|
|
179
189
|
var constructor = obj == null ? void 0 : obj.constructor;
|
|
180
|
-
|
|
181
|
-
if (
|
|
190
|
+
|
|
191
|
+
if (!constructor) {
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if ("GeneratorFunction" === constructor.name || "GeneratorFunction" === constructor.displayName) {
|
|
196
|
+
return true;
|
|
197
|
+
}
|
|
198
|
+
|
|
182
199
|
return false;
|
|
183
200
|
}
|
|
184
201
|
function addHiddenProp(object, propName, value) {
|
|
@@ -218,9 +235,16 @@ var hasGetOwnPropertySymbols = typeof Object.getOwnPropertySymbols !== "undefine
|
|
|
218
235
|
function getPlainObjectKeys(object) {
|
|
219
236
|
var keys = Object.keys(object); // Not supported in IE, so there are not going to be symbol props anyway...
|
|
220
237
|
|
|
221
|
-
if (!hasGetOwnPropertySymbols)
|
|
238
|
+
if (!hasGetOwnPropertySymbols) {
|
|
239
|
+
return keys;
|
|
240
|
+
}
|
|
241
|
+
|
|
222
242
|
var symbols = Object.getOwnPropertySymbols(object);
|
|
223
|
-
|
|
243
|
+
|
|
244
|
+
if (!symbols.length) {
|
|
245
|
+
return keys;
|
|
246
|
+
}
|
|
247
|
+
|
|
224
248
|
return [].concat(keys, symbols.filter(function (s) {
|
|
225
249
|
return objectPrototype.propertyIsEnumerable.call(object, s);
|
|
226
250
|
}));
|
|
@@ -233,8 +257,14 @@ var ownKeys = typeof Reflect !== "undefined" && Reflect.ownKeys ? Reflect.ownKey
|
|
|
233
257
|
/* istanbul ignore next */
|
|
234
258
|
Object.getOwnPropertyNames;
|
|
235
259
|
function stringifyKey(key) {
|
|
236
|
-
if (typeof key === "string")
|
|
237
|
-
|
|
260
|
+
if (typeof key === "string") {
|
|
261
|
+
return key;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if (typeof key === "symbol") {
|
|
265
|
+
return key.toString();
|
|
266
|
+
}
|
|
267
|
+
|
|
238
268
|
return new String(key).toString();
|
|
239
269
|
}
|
|
240
270
|
function toPrimitive(value) {
|
|
@@ -522,7 +552,10 @@ function shallowComparer(a, b) {
|
|
|
522
552
|
}
|
|
523
553
|
|
|
524
554
|
function defaultComparer(a, b) {
|
|
525
|
-
if (Object.is)
|
|
555
|
+
if (Object.is) {
|
|
556
|
+
return Object.is(a, b);
|
|
557
|
+
}
|
|
558
|
+
|
|
526
559
|
return a === b ? a !== 0 || 1 / a === 1 / b : a !== a && b !== b;
|
|
527
560
|
}
|
|
528
561
|
|
|
@@ -535,20 +568,34 @@ var comparer = {
|
|
|
535
568
|
|
|
536
569
|
function deepEnhancer(v, _, name) {
|
|
537
570
|
// it is an observable already, done
|
|
538
|
-
if (isObservable(v))
|
|
571
|
+
if (isObservable(v)) {
|
|
572
|
+
return v;
|
|
573
|
+
} // something that can be converted and mutated?
|
|
539
574
|
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
}
|
|
575
|
+
|
|
576
|
+
if (Array.isArray(v)) {
|
|
577
|
+
return observable.array(v, {
|
|
578
|
+
name: name
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
if (isPlainObject(v)) {
|
|
583
|
+
return observable.object(v, undefined, {
|
|
584
|
+
name: name
|
|
585
|
+
});
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
if (isES6Map(v)) {
|
|
589
|
+
return observable.map(v, {
|
|
590
|
+
name: name
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
if (isES6Set(v)) {
|
|
595
|
+
return observable.set(v, {
|
|
596
|
+
name: name
|
|
597
|
+
});
|
|
598
|
+
}
|
|
552
599
|
|
|
553
600
|
if (typeof v === "function" && !isAction(v) && !isFlow(v)) {
|
|
554
601
|
if (isGenerator(v)) {
|
|
@@ -561,33 +608,59 @@ function deepEnhancer(v, _, name) {
|
|
|
561
608
|
return v;
|
|
562
609
|
}
|
|
563
610
|
function shallowEnhancer(v, _, name) {
|
|
564
|
-
if (v === undefined || v === null)
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
611
|
+
if (v === undefined || v === null) {
|
|
612
|
+
return v;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
if (isObservableObject(v) || isObservableArray(v) || isObservableMap(v) || isObservableSet(v)) {
|
|
616
|
+
return v;
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
if (Array.isArray(v)) {
|
|
620
|
+
return observable.array(v, {
|
|
621
|
+
name: name,
|
|
622
|
+
deep: false
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
if (isPlainObject(v)) {
|
|
627
|
+
return observable.object(v, undefined, {
|
|
628
|
+
name: name,
|
|
629
|
+
deep: false
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
if (isES6Map(v)) {
|
|
634
|
+
return observable.map(v, {
|
|
635
|
+
name: name,
|
|
636
|
+
deep: false
|
|
637
|
+
});
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
if (isES6Set(v)) {
|
|
641
|
+
return observable.set(v, {
|
|
642
|
+
name: name,
|
|
643
|
+
deep: false
|
|
644
|
+
});
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
{
|
|
648
|
+
die("The shallow modifier / decorator can only used in combination with arrays, objects, maps and sets");
|
|
649
|
+
}
|
|
583
650
|
}
|
|
584
651
|
function referenceEnhancer(newValue) {
|
|
585
652
|
// never turn into an observable
|
|
586
653
|
return newValue;
|
|
587
654
|
}
|
|
588
655
|
function refStructEnhancer(v, oldValue) {
|
|
589
|
-
if ( isObservable(v))
|
|
590
|
-
|
|
656
|
+
if ( isObservable(v)) {
|
|
657
|
+
die("observable.struct should not be used with observable values");
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
if (deepEqual(v, oldValue)) {
|
|
661
|
+
return oldValue;
|
|
662
|
+
}
|
|
663
|
+
|
|
591
664
|
return v;
|
|
592
665
|
}
|
|
593
666
|
|
|
@@ -735,10 +808,12 @@ function make_$2(adm, key, descriptor, source) {
|
|
|
735
808
|
// bound - must annotate protos to support super.flow()
|
|
736
809
|
|
|
737
810
|
|
|
738
|
-
if ((_this$options_ = this.options_) != null && _this$options_.bound && !isFlow(adm.target_[key])) {
|
|
739
|
-
if (this.extend_(adm, key, descriptor, false) === null)
|
|
740
|
-
|
|
741
|
-
|
|
811
|
+
if ((_this$options_ = this.options_) != null && _this$options_.bound && (!hasProp(adm.target_, key) || !isFlow(adm.target_[key]))) {
|
|
812
|
+
if (this.extend_(adm, key, descriptor, false) === null) {
|
|
813
|
+
return 0
|
|
814
|
+
/* Cancel */
|
|
815
|
+
;
|
|
816
|
+
}
|
|
742
817
|
}
|
|
743
818
|
|
|
744
819
|
if (isFlow(descriptor.value)) {
|
|
@@ -779,16 +854,23 @@ safeDescriptors) {
|
|
|
779
854
|
}
|
|
780
855
|
|
|
781
856
|
assertFlowDescriptor(adm, annotation, key, descriptor);
|
|
782
|
-
var value = descriptor.value;
|
|
857
|
+
var value = descriptor.value; // In case of flow.bound, the descriptor can be from already annotated prototype
|
|
858
|
+
|
|
859
|
+
if (!isFlow(value)) {
|
|
860
|
+
value = flow(value);
|
|
861
|
+
}
|
|
783
862
|
|
|
784
863
|
if (bound) {
|
|
785
864
|
var _adm$proxy_;
|
|
786
865
|
|
|
787
|
-
|
|
866
|
+
// We do not keep original function around, so we bind the existing flow
|
|
867
|
+
value = value.bind((_adm$proxy_ = adm.proxy_) != null ? _adm$proxy_ : adm.target_); // This is normally set by `flow`, but `bind` returns new function...
|
|
868
|
+
|
|
869
|
+
value.isMobXFlow = true;
|
|
788
870
|
}
|
|
789
871
|
|
|
790
872
|
return {
|
|
791
|
-
value:
|
|
873
|
+
value: value,
|
|
792
874
|
// Non-configurable for classes
|
|
793
875
|
// prevents accidental field redefinition in subclass
|
|
794
876
|
configurable: safeDescriptors ? adm.isPlainObject_ : true,
|
|
@@ -1022,17 +1104,35 @@ function createObservable(v, arg2, arg3) {
|
|
|
1022
1104
|
} // already observable - ignore
|
|
1023
1105
|
|
|
1024
1106
|
|
|
1025
|
-
if (isObservable(v))
|
|
1107
|
+
if (isObservable(v)) {
|
|
1108
|
+
return v;
|
|
1109
|
+
} // plain object
|
|
1026
1110
|
|
|
1027
|
-
if (isPlainObject(v)) return observable.object(v, arg2, arg3); // Array
|
|
1028
1111
|
|
|
1029
|
-
if (
|
|
1112
|
+
if (isPlainObject(v)) {
|
|
1113
|
+
return observable.object(v, arg2, arg3);
|
|
1114
|
+
} // Array
|
|
1030
1115
|
|
|
1031
|
-
if (isES6Map(v)) return observable.map(v, arg2); // Set
|
|
1032
1116
|
|
|
1033
|
-
if (
|
|
1117
|
+
if (Array.isArray(v)) {
|
|
1118
|
+
return observable.array(v, arg2);
|
|
1119
|
+
} // Map
|
|
1120
|
+
|
|
1121
|
+
|
|
1122
|
+
if (isES6Map(v)) {
|
|
1123
|
+
return observable.map(v, arg2);
|
|
1124
|
+
} // Set
|
|
1125
|
+
|
|
1126
|
+
|
|
1127
|
+
if (isES6Set(v)) {
|
|
1128
|
+
return observable.set(v, arg2);
|
|
1129
|
+
} // other object - ignore
|
|
1130
|
+
|
|
1131
|
+
|
|
1132
|
+
if (typeof v === "object" && v !== null) {
|
|
1133
|
+
return v;
|
|
1134
|
+
} // anything else
|
|
1034
1135
|
|
|
1035
|
-
if (typeof v === "object" && v !== null) return v; // anything else
|
|
1036
1136
|
|
|
1037
1137
|
return observable.box(v, arg2);
|
|
1038
1138
|
}
|
|
@@ -1090,8 +1190,13 @@ var computed = function computed(arg1, arg2) {
|
|
|
1090
1190
|
|
|
1091
1191
|
|
|
1092
1192
|
{
|
|
1093
|
-
if (!isFunction(arg1))
|
|
1094
|
-
|
|
1193
|
+
if (!isFunction(arg1)) {
|
|
1194
|
+
die("First argument to `computed` should be an expression.");
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
if (isFunction(arg2)) {
|
|
1198
|
+
die("A setter as second argument is no longer supported, use `{ set: fn }` option instead");
|
|
1199
|
+
}
|
|
1095
1200
|
}
|
|
1096
1201
|
|
|
1097
1202
|
var opts = isPlainObject(arg2) ? arg2 : {};
|
|
@@ -1123,8 +1228,13 @@ function createAction(actionName, fn, autoAction, ref) {
|
|
|
1123
1228
|
}
|
|
1124
1229
|
|
|
1125
1230
|
{
|
|
1126
|
-
if (!isFunction(fn))
|
|
1127
|
-
|
|
1231
|
+
if (!isFunction(fn)) {
|
|
1232
|
+
die("`action` can only be invoked on functions");
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
if (typeof actionName !== "string" || !actionName) {
|
|
1236
|
+
die("actions should have valid names, got: '" + actionName + "'");
|
|
1237
|
+
}
|
|
1128
1238
|
}
|
|
1129
1239
|
|
|
1130
1240
|
function res() {
|
|
@@ -1206,7 +1316,10 @@ function _endAction(runInfo) {
|
|
|
1206
1316
|
allowStateChangesEnd(runInfo.prevAllowStateChanges_);
|
|
1207
1317
|
allowStateReadsEnd(runInfo.prevAllowStateReads_);
|
|
1208
1318
|
endBatch();
|
|
1209
|
-
|
|
1319
|
+
|
|
1320
|
+
if (runInfo.runAsAction_) {
|
|
1321
|
+
untrackedEnd(runInfo.prevDerivation_);
|
|
1322
|
+
}
|
|
1210
1323
|
|
|
1211
1324
|
if ( runInfo.notifySpy_) {
|
|
1212
1325
|
spyReportEnd({
|
|
@@ -1286,7 +1399,10 @@ var ObservableValue = /*#__PURE__*/function (_Atom, _Symbol$toPrimitive2) {
|
|
|
1286
1399
|
var _proto = ObservableValue.prototype;
|
|
1287
1400
|
|
|
1288
1401
|
_proto.dehanceValue = function dehanceValue(value) {
|
|
1289
|
-
if (this.dehancer !== undefined)
|
|
1402
|
+
if (this.dehancer !== undefined) {
|
|
1403
|
+
return this.dehancer(value);
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1290
1406
|
return value;
|
|
1291
1407
|
};
|
|
1292
1408
|
|
|
@@ -1309,7 +1425,10 @@ var ObservableValue = /*#__PURE__*/function (_Atom, _Symbol$toPrimitive2) {
|
|
|
1309
1425
|
}
|
|
1310
1426
|
|
|
1311
1427
|
this.setNewValue_(newValue);
|
|
1312
|
-
|
|
1428
|
+
|
|
1429
|
+
if ( notifySpy) {
|
|
1430
|
+
spyReportEnd();
|
|
1431
|
+
}
|
|
1313
1432
|
}
|
|
1314
1433
|
};
|
|
1315
1434
|
|
|
@@ -1322,7 +1441,11 @@ var ObservableValue = /*#__PURE__*/function (_Atom, _Symbol$toPrimitive2) {
|
|
|
1322
1441
|
type: UPDATE,
|
|
1323
1442
|
newValue: newValue
|
|
1324
1443
|
});
|
|
1325
|
-
|
|
1444
|
+
|
|
1445
|
+
if (!change) {
|
|
1446
|
+
return globalState.UNCHANGED;
|
|
1447
|
+
}
|
|
1448
|
+
|
|
1326
1449
|
newValue = change.newValue;
|
|
1327
1450
|
} // apply modifier
|
|
1328
1451
|
|
|
@@ -1356,14 +1479,17 @@ var ObservableValue = /*#__PURE__*/function (_Atom, _Symbol$toPrimitive2) {
|
|
|
1356
1479
|
};
|
|
1357
1480
|
|
|
1358
1481
|
_proto.observe_ = function observe_(listener, fireImmediately) {
|
|
1359
|
-
if (fireImmediately)
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1482
|
+
if (fireImmediately) {
|
|
1483
|
+
listener({
|
|
1484
|
+
observableKind: "value",
|
|
1485
|
+
debugObjectName: this.name_,
|
|
1486
|
+
object: this,
|
|
1487
|
+
type: UPDATE,
|
|
1488
|
+
newValue: this.value_,
|
|
1489
|
+
oldValue: undefined
|
|
1490
|
+
});
|
|
1491
|
+
}
|
|
1492
|
+
|
|
1367
1493
|
return registerListener(this, listener);
|
|
1368
1494
|
};
|
|
1369
1495
|
|
|
@@ -1458,7 +1584,11 @@ var ComputedValue = /*#__PURE__*/function (_Symbol$toPrimitive2) {
|
|
|
1458
1584
|
this.keepAlive_ = void 0;
|
|
1459
1585
|
this.onBOL = void 0;
|
|
1460
1586
|
this.onBUOL = void 0;
|
|
1461
|
-
|
|
1587
|
+
|
|
1588
|
+
if (!options.get) {
|
|
1589
|
+
die(31);
|
|
1590
|
+
}
|
|
1591
|
+
|
|
1462
1592
|
this.derivation = options.get;
|
|
1463
1593
|
this.name_ = options.name || ( "ComputedValue@" + getNextId() );
|
|
1464
1594
|
|
|
@@ -1500,7 +1630,9 @@ var ComputedValue = /*#__PURE__*/function (_Symbol$toPrimitive2) {
|
|
|
1500
1630
|
;
|
|
1501
1631
|
|
|
1502
1632
|
_proto.get = function get() {
|
|
1503
|
-
if (this.isComputing_)
|
|
1633
|
+
if (this.isComputing_) {
|
|
1634
|
+
die(32, this.name_, this.derivation);
|
|
1635
|
+
}
|
|
1504
1636
|
|
|
1505
1637
|
if (globalState.inBatch === 0 && // !globalState.trackingDerivatpion &&
|
|
1506
1638
|
this.observers_.size === 0 && !this.keepAlive_) {
|
|
@@ -1516,20 +1648,34 @@ var ComputedValue = /*#__PURE__*/function (_Symbol$toPrimitive2) {
|
|
|
1516
1648
|
|
|
1517
1649
|
if (shouldCompute(this)) {
|
|
1518
1650
|
var prevTrackingContext = globalState.trackingContext;
|
|
1519
|
-
|
|
1520
|
-
if (this.
|
|
1651
|
+
|
|
1652
|
+
if (this.keepAlive_ && !prevTrackingContext) {
|
|
1653
|
+
globalState.trackingContext = this;
|
|
1654
|
+
}
|
|
1655
|
+
|
|
1656
|
+
if (this.trackAndCompute()) {
|
|
1657
|
+
propagateChangeConfirmed(this);
|
|
1658
|
+
}
|
|
1659
|
+
|
|
1521
1660
|
globalState.trackingContext = prevTrackingContext;
|
|
1522
1661
|
}
|
|
1523
1662
|
}
|
|
1524
1663
|
|
|
1525
1664
|
var result = this.value_;
|
|
1526
|
-
|
|
1665
|
+
|
|
1666
|
+
if (isCaughtException(result)) {
|
|
1667
|
+
throw result.cause;
|
|
1668
|
+
}
|
|
1669
|
+
|
|
1527
1670
|
return result;
|
|
1528
1671
|
};
|
|
1529
1672
|
|
|
1530
1673
|
_proto.set = function set(value) {
|
|
1531
1674
|
if (this.setter_) {
|
|
1532
|
-
if (this.isRunningSetter_)
|
|
1675
|
+
if (this.isRunningSetter_) {
|
|
1676
|
+
die(33, this.name_);
|
|
1677
|
+
}
|
|
1678
|
+
|
|
1533
1679
|
this.isRunningSetter_ = true;
|
|
1534
1680
|
|
|
1535
1681
|
try {
|
|
@@ -1537,7 +1683,9 @@ var ComputedValue = /*#__PURE__*/function (_Symbol$toPrimitive2) {
|
|
|
1537
1683
|
} finally {
|
|
1538
1684
|
this.isRunningSetter_ = false;
|
|
1539
1685
|
}
|
|
1540
|
-
} else
|
|
1686
|
+
} else {
|
|
1687
|
+
die(34, this.name_);
|
|
1688
|
+
}
|
|
1541
1689
|
};
|
|
1542
1690
|
|
|
1543
1691
|
_proto.trackAndCompute = function trackAndCompute() {
|
|
@@ -1766,7 +1914,9 @@ function checkIfStateModificationsAreAllowed(atom) {
|
|
|
1766
1914
|
|
|
1767
1915
|
var hasObservers = atom.observers_.size > 0; // Should not be possible to change observed state outside strict mode, except during initialization, see #563
|
|
1768
1916
|
|
|
1769
|
-
if (!globalState.allowStateChanges && (hasObservers || globalState.enforceActions === "always"))
|
|
1917
|
+
if (!globalState.allowStateChanges && (hasObservers || globalState.enforceActions === "always")) {
|
|
1918
|
+
console.warn("[MobX] " + (globalState.enforceActions ? "Since strict-mode is enabled, changing (observed) observable values without using an action is not allowed. Tried to modify: " : "Side effects like changing state are not allowed at this point. Are you trying to modify state from, for example, a computed value or the render function of a React component? You can wrap side effects in 'runInAction' (or decorate functions with 'action') if needed. Tried to modify: ") + atom.name_);
|
|
1919
|
+
}
|
|
1770
1920
|
}
|
|
1771
1921
|
function checkIfStateReadsAreAllowed(observable) {
|
|
1772
1922
|
if ( !globalState.allowStateReads && globalState.observableRequiresReaction) {
|
|
@@ -1811,7 +1961,10 @@ function trackDerivedFunction(derivation, f, context) {
|
|
|
1811
1961
|
}
|
|
1812
1962
|
|
|
1813
1963
|
function warnAboutDerivationWithoutDependencies(derivation) {
|
|
1814
|
-
|
|
1964
|
+
|
|
1965
|
+
if (derivation.observing_.length !== 0) {
|
|
1966
|
+
return;
|
|
1967
|
+
}
|
|
1815
1968
|
|
|
1816
1969
|
if (globalState.reactionRequiresObservable || derivation.requiresObservable_) {
|
|
1817
1970
|
console.warn("[mobx] Derivation '" + derivation.name_ + "' is created/updated without reading any observable value.");
|
|
@@ -1840,7 +1993,11 @@ function bindDependencies(derivation) {
|
|
|
1840
1993
|
|
|
1841
1994
|
if (dep.diffValue_ === 0) {
|
|
1842
1995
|
dep.diffValue_ = 1;
|
|
1843
|
-
|
|
1996
|
+
|
|
1997
|
+
if (i0 !== i) {
|
|
1998
|
+
observing[i0] = dep;
|
|
1999
|
+
}
|
|
2000
|
+
|
|
1844
2001
|
i0++;
|
|
1845
2002
|
} // Upcast is 'safe' here, because if dep is IObservable, `dependenciesState` will be undefined,
|
|
1846
2003
|
// not hitting the condition
|
|
@@ -1932,7 +2089,10 @@ function allowStateReadsEnd(prev) {
|
|
|
1932
2089
|
*/
|
|
1933
2090
|
|
|
1934
2091
|
function changeDependenciesStateTo0(derivation) {
|
|
1935
|
-
if (derivation.dependenciesState_ === IDerivationState_.UP_TO_DATE_)
|
|
2092
|
+
if (derivation.dependenciesState_ === IDerivationState_.UP_TO_DATE_) {
|
|
2093
|
+
return;
|
|
2094
|
+
}
|
|
2095
|
+
|
|
1936
2096
|
derivation.dependenciesState_ = IDerivationState_.UP_TO_DATE_;
|
|
1937
2097
|
var obs = derivation.observing_;
|
|
1938
2098
|
var i = obs.length;
|
|
@@ -1976,8 +2136,14 @@ var canMergeGlobalState = true;
|
|
|
1976
2136
|
var isolateCalled = false;
|
|
1977
2137
|
var globalState = /*#__PURE__*/function () {
|
|
1978
2138
|
var global = /*#__PURE__*/getGlobal();
|
|
1979
|
-
|
|
1980
|
-
if (global.
|
|
2139
|
+
|
|
2140
|
+
if (global.__mobxInstanceCount > 0 && !global.__mobxGlobals) {
|
|
2141
|
+
canMergeGlobalState = false;
|
|
2142
|
+
}
|
|
2143
|
+
|
|
2144
|
+
if (global.__mobxGlobals && global.__mobxGlobals.version !== new MobXGlobals().version) {
|
|
2145
|
+
canMergeGlobalState = false;
|
|
2146
|
+
}
|
|
1981
2147
|
|
|
1982
2148
|
if (!canMergeGlobalState) {
|
|
1983
2149
|
// Because this is a IIFE we need to let isolateCalled a chance to change
|
|
@@ -1990,7 +2156,11 @@ var globalState = /*#__PURE__*/function () {
|
|
|
1990
2156
|
return new MobXGlobals();
|
|
1991
2157
|
} else if (global.__mobxGlobals) {
|
|
1992
2158
|
global.__mobxInstanceCount += 1;
|
|
1993
|
-
|
|
2159
|
+
|
|
2160
|
+
if (!global.__mobxGlobals.UNCHANGED) {
|
|
2161
|
+
global.__mobxGlobals.UNCHANGED = {};
|
|
2162
|
+
} // make merge backward compatible
|
|
2163
|
+
|
|
1994
2164
|
|
|
1995
2165
|
return global.__mobxGlobals;
|
|
1996
2166
|
} else {
|
|
@@ -1999,12 +2169,19 @@ var globalState = /*#__PURE__*/function () {
|
|
|
1999
2169
|
}
|
|
2000
2170
|
}();
|
|
2001
2171
|
function isolateGlobalState() {
|
|
2002
|
-
if (globalState.pendingReactions.length || globalState.inBatch || globalState.isRunningReactions)
|
|
2172
|
+
if (globalState.pendingReactions.length || globalState.inBatch || globalState.isRunningReactions) {
|
|
2173
|
+
die(36);
|
|
2174
|
+
}
|
|
2175
|
+
|
|
2003
2176
|
isolateCalled = true;
|
|
2004
2177
|
|
|
2005
2178
|
if (canMergeGlobalState) {
|
|
2006
2179
|
var global = getGlobal();
|
|
2007
|
-
|
|
2180
|
+
|
|
2181
|
+
if (--global.__mobxInstanceCount === 0) {
|
|
2182
|
+
global.__mobxGlobals = undefined;
|
|
2183
|
+
}
|
|
2184
|
+
|
|
2008
2185
|
globalState = new MobXGlobals();
|
|
2009
2186
|
}
|
|
2010
2187
|
}
|
|
@@ -2020,7 +2197,9 @@ function resetGlobalState() {
|
|
|
2020
2197
|
var defaultGlobals = new MobXGlobals();
|
|
2021
2198
|
|
|
2022
2199
|
for (var key in defaultGlobals) {
|
|
2023
|
-
if (persistentKeys.indexOf(key) === -1)
|
|
2200
|
+
if (persistentKeys.indexOf(key) === -1) {
|
|
2201
|
+
globalState[key] = defaultGlobals[key];
|
|
2202
|
+
}
|
|
2024
2203
|
}
|
|
2025
2204
|
|
|
2026
2205
|
globalState.allowStateChanges = !globalState.enforceActions;
|
|
@@ -2054,8 +2233,12 @@ function addObserver(observable, node) {
|
|
|
2054
2233
|
// invariant(observable._observers.indexOf(node) === -1, "INTERNAL ERROR add already added node");
|
|
2055
2234
|
// invariantObservers(observable);
|
|
2056
2235
|
observable.observers_.add(node);
|
|
2057
|
-
|
|
2236
|
+
|
|
2237
|
+
if (observable.lowestObserverState_ > node.dependenciesState_) {
|
|
2238
|
+
observable.lowestObserverState_ = node.dependenciesState_;
|
|
2239
|
+
} // invariantObservers(observable);
|
|
2058
2240
|
// invariant(observable._observers.indexOf(node) !== -1, "INTERNAL ERROR didn't add node");
|
|
2241
|
+
|
|
2059
2242
|
}
|
|
2060
2243
|
function removeObserver(observable, node) {
|
|
2061
2244
|
// invariant(globalState.inBatch > 0, "INTERNAL ERROR, remove should be called only inside batch");
|
|
@@ -2166,7 +2349,10 @@ function reportObserved(observable) {
|
|
|
2166
2349
|
|
|
2167
2350
|
function propagateChanged(observable) {
|
|
2168
2351
|
// invariantLOS(observable, "changed start");
|
|
2169
|
-
if (observable.lowestObserverState_ === IDerivationState_.STALE_)
|
|
2352
|
+
if (observable.lowestObserverState_ === IDerivationState_.STALE_) {
|
|
2353
|
+
return;
|
|
2354
|
+
}
|
|
2355
|
+
|
|
2170
2356
|
observable.lowestObserverState_ = IDerivationState_.STALE_; // Ideally we use for..of here, but the downcompiled version is really slow...
|
|
2171
2357
|
|
|
2172
2358
|
observable.observers_.forEach(function (d) {
|
|
@@ -2184,7 +2370,10 @@ function propagateChanged(observable) {
|
|
|
2184
2370
|
|
|
2185
2371
|
function propagateChangeConfirmed(observable) {
|
|
2186
2372
|
// invariantLOS(observable, "confirmed start");
|
|
2187
|
-
if (observable.lowestObserverState_ === IDerivationState_.STALE_)
|
|
2373
|
+
if (observable.lowestObserverState_ === IDerivationState_.STALE_) {
|
|
2374
|
+
return;
|
|
2375
|
+
}
|
|
2376
|
+
|
|
2188
2377
|
observable.lowestObserverState_ = IDerivationState_.STALE_;
|
|
2189
2378
|
observable.observers_.forEach(function (d) {
|
|
2190
2379
|
if (d.dependenciesState_ === IDerivationState_.POSSIBLY_STALE_) {
|
|
@@ -2202,7 +2391,10 @@ function propagateChangeConfirmed(observable) {
|
|
|
2202
2391
|
|
|
2203
2392
|
function propagateMaybeChanged(observable) {
|
|
2204
2393
|
// invariantLOS(observable, "maybe start");
|
|
2205
|
-
if (observable.lowestObserverState_ !== IDerivationState_.UP_TO_DATE_)
|
|
2394
|
+
if (observable.lowestObserverState_ !== IDerivationState_.UP_TO_DATE_) {
|
|
2395
|
+
return;
|
|
2396
|
+
}
|
|
2397
|
+
|
|
2206
2398
|
observable.lowestObserverState_ = IDerivationState_.POSSIBLY_STALE_;
|
|
2207
2399
|
observable.observers_.forEach(function (d) {
|
|
2208
2400
|
if (d.dependenciesState_ === IDerivationState_.UP_TO_DATE_) {
|
|
@@ -2230,9 +2422,12 @@ function printDepTree(tree, lines, depth) {
|
|
|
2230
2422
|
}
|
|
2231
2423
|
|
|
2232
2424
|
lines.push("" + "\t".repeat(depth - 1) + tree.name);
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2425
|
+
|
|
2426
|
+
if (tree.dependencies) {
|
|
2427
|
+
tree.dependencies.forEach(function (child) {
|
|
2428
|
+
return printDepTree(child, lines, depth + 1);
|
|
2429
|
+
});
|
|
2430
|
+
}
|
|
2236
2431
|
}
|
|
2237
2432
|
|
|
2238
2433
|
var Reaction = /*#__PURE__*/function () {
|
|
@@ -2350,7 +2545,9 @@ var Reaction = /*#__PURE__*/function () {
|
|
|
2350
2545
|
clearObserving(this);
|
|
2351
2546
|
}
|
|
2352
2547
|
|
|
2353
|
-
if (isCaughtException(result))
|
|
2548
|
+
if (isCaughtException(result)) {
|
|
2549
|
+
this.reportExceptionInDerivation_(result.cause);
|
|
2550
|
+
}
|
|
2354
2551
|
|
|
2355
2552
|
if ( notify) {
|
|
2356
2553
|
spyReportEnd({
|
|
@@ -2369,13 +2566,18 @@ var Reaction = /*#__PURE__*/function () {
|
|
|
2369
2566
|
return;
|
|
2370
2567
|
}
|
|
2371
2568
|
|
|
2372
|
-
if (globalState.disableErrorBoundaries)
|
|
2569
|
+
if (globalState.disableErrorBoundaries) {
|
|
2570
|
+
throw error;
|
|
2571
|
+
}
|
|
2572
|
+
|
|
2373
2573
|
var message = "[mobx] Encountered an uncaught exception that was thrown by a reaction or observer component, in: '" + this + "'" ;
|
|
2374
2574
|
|
|
2375
2575
|
if (!globalState.suppressReactionErrors) {
|
|
2376
2576
|
console.error(message, error);
|
|
2377
2577
|
/** If debugging brought you here, please, read the above message :-). Tnx! */
|
|
2378
|
-
} else
|
|
2578
|
+
} else {
|
|
2579
|
+
console.warn("[mobx] (error in reaction '" + this.name_ + "' suppressed, fix error of causing action below)");
|
|
2580
|
+
} // prettier-ignore
|
|
2379
2581
|
|
|
2380
2582
|
|
|
2381
2583
|
if ( isSpyEnabled()) {
|
|
@@ -2429,7 +2631,10 @@ function onReactionError(handler) {
|
|
|
2429
2631
|
globalState.globalReactionErrorHandlers.push(handler);
|
|
2430
2632
|
return function () {
|
|
2431
2633
|
var idx = globalState.globalReactionErrorHandlers.indexOf(handler);
|
|
2432
|
-
|
|
2634
|
+
|
|
2635
|
+
if (idx >= 0) {
|
|
2636
|
+
globalState.globalReactionErrorHandlers.splice(idx, 1);
|
|
2637
|
+
}
|
|
2433
2638
|
};
|
|
2434
2639
|
}
|
|
2435
2640
|
/**
|
|
@@ -2446,7 +2651,10 @@ var reactionScheduler = function reactionScheduler(f) {
|
|
|
2446
2651
|
|
|
2447
2652
|
function runReactions() {
|
|
2448
2653
|
// Trampolining, if runReactions are already running, new reactions will be picked up
|
|
2449
|
-
if (globalState.inBatch > 0 || globalState.isRunningReactions)
|
|
2654
|
+
if (globalState.inBatch > 0 || globalState.isRunningReactions) {
|
|
2655
|
+
return;
|
|
2656
|
+
}
|
|
2657
|
+
|
|
2450
2658
|
reactionScheduler(runReactionsHelper);
|
|
2451
2659
|
}
|
|
2452
2660
|
|
|
@@ -2489,7 +2697,11 @@ function isSpyEnabled() {
|
|
|
2489
2697
|
}
|
|
2490
2698
|
function spyReport(event) {
|
|
2491
2699
|
|
|
2492
|
-
|
|
2700
|
+
|
|
2701
|
+
if (!globalState.spyListeners.length) {
|
|
2702
|
+
return;
|
|
2703
|
+
}
|
|
2704
|
+
|
|
2493
2705
|
var listeners = globalState.spyListeners;
|
|
2494
2706
|
|
|
2495
2707
|
for (var i = 0, l = listeners.length; i < l; i++) {
|
|
@@ -2509,10 +2721,15 @@ var END_EVENT = {
|
|
|
2509
2721
|
spyReportEnd: true
|
|
2510
2722
|
};
|
|
2511
2723
|
function spyReportEnd(change) {
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2724
|
+
|
|
2725
|
+
if (change) {
|
|
2726
|
+
spyReport(_extends({}, change, {
|
|
2727
|
+
type: "report-end",
|
|
2728
|
+
spyReportEnd: true
|
|
2729
|
+
}));
|
|
2730
|
+
} else {
|
|
2731
|
+
spyReport(END_EVENT);
|
|
2732
|
+
}
|
|
2516
2733
|
}
|
|
2517
2734
|
function spy(listener) {
|
|
2518
2735
|
{
|
|
@@ -2545,9 +2762,15 @@ var autoActionBoundAnnotation = /*#__PURE__*/createActionAnnotation(AUTOACTION_B
|
|
|
2545
2762
|
function createActionFactory(autoAction) {
|
|
2546
2763
|
var res = function action(arg1, arg2) {
|
|
2547
2764
|
// action(fn() {})
|
|
2548
|
-
if (isFunction(arg1))
|
|
2765
|
+
if (isFunction(arg1)) {
|
|
2766
|
+
return createAction(arg1.name || DEFAULT_ACTION_NAME, arg1, autoAction);
|
|
2767
|
+
} // action("name", fn() {})
|
|
2768
|
+
|
|
2769
|
+
|
|
2770
|
+
if (isFunction(arg2)) {
|
|
2771
|
+
return createAction(arg1, arg2, autoAction);
|
|
2772
|
+
} // @action
|
|
2549
2773
|
|
|
2550
|
-
if (isFunction(arg2)) return createAction(arg1, arg2, autoAction); // @action
|
|
2551
2774
|
|
|
2552
2775
|
if (isStringish(arg2)) {
|
|
2553
2776
|
return storeAnnotation(arg1, arg2, autoAction ? autoActionAnnotation : actionAnnotation);
|
|
@@ -2561,7 +2784,9 @@ function createActionFactory(autoAction) {
|
|
|
2561
2784
|
}));
|
|
2562
2785
|
}
|
|
2563
2786
|
|
|
2564
|
-
|
|
2787
|
+
{
|
|
2788
|
+
die("Invalid arguments for `action`");
|
|
2789
|
+
}
|
|
2565
2790
|
};
|
|
2566
2791
|
|
|
2567
2792
|
return res;
|
|
@@ -2595,8 +2820,13 @@ function autorun(view, opts) {
|
|
|
2595
2820
|
}
|
|
2596
2821
|
|
|
2597
2822
|
{
|
|
2598
|
-
if (!isFunction(view))
|
|
2599
|
-
|
|
2823
|
+
if (!isFunction(view)) {
|
|
2824
|
+
die("Autorun expects a function as first argument");
|
|
2825
|
+
}
|
|
2826
|
+
|
|
2827
|
+
if (isAction(view)) {
|
|
2828
|
+
die("Autorun does not accept actions since actions are untrackable");
|
|
2829
|
+
}
|
|
2600
2830
|
}
|
|
2601
2831
|
|
|
2602
2832
|
var name = (_opts$name = (_opts = opts) == null ? void 0 : _opts.name) != null ? _opts$name : view.name || "Autorun@" + getNextId() ;
|
|
@@ -2617,7 +2847,10 @@ function autorun(view, opts) {
|
|
|
2617
2847
|
isScheduled = true;
|
|
2618
2848
|
scheduler(function () {
|
|
2619
2849
|
isScheduled = false;
|
|
2620
|
-
|
|
2850
|
+
|
|
2851
|
+
if (!reaction.isDisposed_) {
|
|
2852
|
+
reaction.track(reactionRunner);
|
|
2853
|
+
}
|
|
2621
2854
|
});
|
|
2622
2855
|
}
|
|
2623
2856
|
}, opts.onError, opts.requiresObservable);
|
|
@@ -2649,8 +2882,13 @@ function reaction(expression, effect, opts) {
|
|
|
2649
2882
|
}
|
|
2650
2883
|
|
|
2651
2884
|
{
|
|
2652
|
-
if (!isFunction(expression) || !isFunction(effect))
|
|
2653
|
-
|
|
2885
|
+
if (!isFunction(expression) || !isFunction(effect)) {
|
|
2886
|
+
die("First and second argument to reaction should be functions");
|
|
2887
|
+
}
|
|
2888
|
+
|
|
2889
|
+
if (!isPlainObject(opts)) {
|
|
2890
|
+
die("Third argument of reactions should be an object");
|
|
2891
|
+
}
|
|
2654
2892
|
}
|
|
2655
2893
|
|
|
2656
2894
|
var name = (_opts$name2 = opts.name) != null ? _opts$name2 : "Reaction@" + getNextId() ;
|
|
@@ -2673,7 +2911,11 @@ function reaction(expression, effect, opts) {
|
|
|
2673
2911
|
|
|
2674
2912
|
function reactionRunner() {
|
|
2675
2913
|
isScheduled = false;
|
|
2676
|
-
|
|
2914
|
+
|
|
2915
|
+
if (r.isDisposed_) {
|
|
2916
|
+
return;
|
|
2917
|
+
}
|
|
2918
|
+
|
|
2677
2919
|
var changed = false;
|
|
2678
2920
|
r.track(function () {
|
|
2679
2921
|
var nextValue = allowStateChanges(false, function () {
|
|
@@ -2683,7 +2925,13 @@ function reaction(expression, effect, opts) {
|
|
|
2683
2925
|
oldValue = value;
|
|
2684
2926
|
value = nextValue;
|
|
2685
2927
|
});
|
|
2686
|
-
|
|
2928
|
+
|
|
2929
|
+
if (firstTime && opts.fireImmediately) {
|
|
2930
|
+
effectAction(value, oldValue, r);
|
|
2931
|
+
} else if (!firstTime && changed) {
|
|
2932
|
+
effectAction(value, oldValue, r);
|
|
2933
|
+
}
|
|
2934
|
+
|
|
2687
2935
|
firstTime = false;
|
|
2688
2936
|
}
|
|
2689
2937
|
|
|
@@ -2750,7 +2998,9 @@ function configure(options) {
|
|
|
2750
2998
|
globalState.useProxies = useProxies === ALWAYS ? true : useProxies === NEVER ? false : typeof Proxy !== "undefined";
|
|
2751
2999
|
}
|
|
2752
3000
|
|
|
2753
|
-
if (useProxies === "ifavailable")
|
|
3001
|
+
if (useProxies === "ifavailable") {
|
|
3002
|
+
globalState.verifyProxies = true;
|
|
3003
|
+
}
|
|
2754
3004
|
|
|
2755
3005
|
if (enforceActions !== undefined) {
|
|
2756
3006
|
var ea = enforceActions === ALWAYS ? ALWAYS : enforceActions === OBSERVED;
|
|
@@ -2758,7 +3008,9 @@ function configure(options) {
|
|
|
2758
3008
|
globalState.allowStateChanges = ea === true || ea === ALWAYS ? false : true;
|
|
2759
3009
|
}
|
|
2760
3010
|
["computedRequiresReaction", "reactionRequiresObservable", "observableRequiresReaction", "disableErrorBoundaries", "safeDescriptors"].forEach(function (key) {
|
|
2761
|
-
if (key in options)
|
|
3011
|
+
if (key in options) {
|
|
3012
|
+
globalState[key] = !!options[key];
|
|
3013
|
+
}
|
|
2762
3014
|
});
|
|
2763
3015
|
globalState.allowStateReads = !globalState.observableRequiresReaction;
|
|
2764
3016
|
|
|
@@ -2773,11 +3025,25 @@ function configure(options) {
|
|
|
2773
3025
|
|
|
2774
3026
|
function extendObservable(target, properties, annotations, options) {
|
|
2775
3027
|
{
|
|
2776
|
-
if (arguments.length > 4)
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
if (
|
|
3028
|
+
if (arguments.length > 4) {
|
|
3029
|
+
die("'extendObservable' expected 2-4 arguments");
|
|
3030
|
+
}
|
|
3031
|
+
|
|
3032
|
+
if (typeof target !== "object") {
|
|
3033
|
+
die("'extendObservable' expects an object as first argument");
|
|
3034
|
+
}
|
|
3035
|
+
|
|
3036
|
+
if (isObservableMap(target)) {
|
|
3037
|
+
die("'extendObservable' should not be used on maps, use map.merge instead");
|
|
3038
|
+
}
|
|
3039
|
+
|
|
3040
|
+
if (!isPlainObject(properties)) {
|
|
3041
|
+
die("'extendObservable' only accepts plain objects as second argument");
|
|
3042
|
+
}
|
|
3043
|
+
|
|
3044
|
+
if (isObservable(properties) || isObservable(annotations)) {
|
|
3045
|
+
die("Extending an object with another observable (object) is not supported");
|
|
3046
|
+
}
|
|
2781
3047
|
} // Pull descriptors first, so we don't have to deal with props added by administration ($mobx)
|
|
2782
3048
|
|
|
2783
3049
|
|
|
@@ -2805,7 +3071,11 @@ function nodeToDependencyTree(node) {
|
|
|
2805
3071
|
var result = {
|
|
2806
3072
|
name: node.name_
|
|
2807
3073
|
};
|
|
2808
|
-
|
|
3074
|
+
|
|
3075
|
+
if (node.observing_ && node.observing_.length > 0) {
|
|
3076
|
+
result.dependencies = unique(node.observing_).map(nodeToDependencyTree);
|
|
3077
|
+
}
|
|
3078
|
+
|
|
2809
3079
|
return result;
|
|
2810
3080
|
}
|
|
2811
3081
|
|
|
@@ -2817,7 +3087,11 @@ function nodeToObserverTree(node) {
|
|
|
2817
3087
|
var result = {
|
|
2818
3088
|
name: node.name_
|
|
2819
3089
|
};
|
|
2820
|
-
|
|
3090
|
+
|
|
3091
|
+
if (hasObservers(node)) {
|
|
3092
|
+
result.observers = Array.from(getObservers(node)).map(nodeToObserverTree);
|
|
3093
|
+
}
|
|
3094
|
+
|
|
2821
3095
|
return result;
|
|
2822
3096
|
}
|
|
2823
3097
|
|
|
@@ -2844,7 +3118,10 @@ var flow = /*#__PURE__*/Object.assign(function flow(arg1, arg2) {
|
|
|
2844
3118
|
} // flow(fn)
|
|
2845
3119
|
|
|
2846
3120
|
|
|
2847
|
-
if ( arguments.length !== 1)
|
|
3121
|
+
if ( arguments.length !== 1) {
|
|
3122
|
+
die("Flow expects single argument with generator function");
|
|
3123
|
+
}
|
|
3124
|
+
|
|
2848
3125
|
var generator = arg1;
|
|
2849
3126
|
var name = generator.name || "<unnamed flow>"; // Implementation based on https://github.com/tj/co/blob/master/index.js
|
|
2850
3127
|
|
|
@@ -2892,7 +3169,10 @@ var flow = /*#__PURE__*/Object.assign(function flow(arg1, arg2) {
|
|
|
2892
3169
|
return;
|
|
2893
3170
|
}
|
|
2894
3171
|
|
|
2895
|
-
if (ret.done)
|
|
3172
|
+
if (ret.done) {
|
|
3173
|
+
return resolve(ret.value);
|
|
3174
|
+
}
|
|
3175
|
+
|
|
2896
3176
|
pendingPromise = Promise.resolve(ret.value);
|
|
2897
3177
|
return pendingPromise.then(onFulfilled, onRejected);
|
|
2898
3178
|
}
|
|
@@ -2901,7 +3181,10 @@ var flow = /*#__PURE__*/Object.assign(function flow(arg1, arg2) {
|
|
|
2901
3181
|
});
|
|
2902
3182
|
promise.cancel = action(name + " - runid: " + runId + " - cancel", function () {
|
|
2903
3183
|
try {
|
|
2904
|
-
if (pendingPromise)
|
|
3184
|
+
if (pendingPromise) {
|
|
3185
|
+
cancelPromise(pendingPromise);
|
|
3186
|
+
} // Finally block can return (or yield) stuff..
|
|
3187
|
+
|
|
2905
3188
|
|
|
2906
3189
|
var _res = gen["return"](undefined); // eat anything that promise would do, it's cancelled!
|
|
2907
3190
|
|
|
@@ -2925,7 +3208,9 @@ var flow = /*#__PURE__*/Object.assign(function flow(arg1, arg2) {
|
|
|
2925
3208
|
flow.bound = /*#__PURE__*/createDecoratorAnnotation(flowBoundAnnotation);
|
|
2926
3209
|
|
|
2927
3210
|
function cancelPromise(promise) {
|
|
2928
|
-
if (isFunction(promise.cancel))
|
|
3211
|
+
if (isFunction(promise.cancel)) {
|
|
3212
|
+
promise.cancel();
|
|
3213
|
+
}
|
|
2929
3214
|
}
|
|
2930
3215
|
|
|
2931
3216
|
function flowResult(result) {
|
|
@@ -2941,13 +3226,19 @@ function interceptReads(thing, propOrHandler, handler) {
|
|
|
2941
3226
|
if (isObservableMap(thing) || isObservableArray(thing) || isObservableValue(thing)) {
|
|
2942
3227
|
target = getAdministration(thing);
|
|
2943
3228
|
} else if (isObservableObject(thing)) {
|
|
2944
|
-
if ( !isStringish(propOrHandler))
|
|
3229
|
+
if ( !isStringish(propOrHandler)) {
|
|
3230
|
+
return die("InterceptReads can only be used with a specific property, not with an object in general");
|
|
3231
|
+
}
|
|
3232
|
+
|
|
2945
3233
|
target = getAdministration(thing, propOrHandler);
|
|
2946
3234
|
} else {
|
|
2947
3235
|
return die("Expected observable map, object or array as first array");
|
|
2948
3236
|
}
|
|
2949
3237
|
|
|
2950
|
-
if ( target.dehancer !== undefined)
|
|
3238
|
+
if ( target.dehancer !== undefined) {
|
|
3239
|
+
return die("An intercept reader was already established");
|
|
3240
|
+
}
|
|
3241
|
+
|
|
2951
3242
|
target.dehancer = typeof propOrHandler === "function" ? propOrHandler : handler;
|
|
2952
3243
|
return function () {
|
|
2953
3244
|
target.dehancer = undefined;
|
|
@@ -2955,7 +3246,11 @@ function interceptReads(thing, propOrHandler, handler) {
|
|
|
2955
3246
|
}
|
|
2956
3247
|
|
|
2957
3248
|
function intercept(thing, propOrHandler, handler) {
|
|
2958
|
-
if (isFunction(handler))
|
|
3249
|
+
if (isFunction(handler)) {
|
|
3250
|
+
return interceptProperty(thing, propOrHandler, handler);
|
|
3251
|
+
} else {
|
|
3252
|
+
return interceptInterceptable(thing, propOrHandler);
|
|
3253
|
+
}
|
|
2959
3254
|
}
|
|
2960
3255
|
|
|
2961
3256
|
function interceptInterceptable(thing, handler) {
|
|
@@ -2971,25 +3266,41 @@ function _isComputed(value, property) {
|
|
|
2971
3266
|
return isComputedValue(value);
|
|
2972
3267
|
}
|
|
2973
3268
|
|
|
2974
|
-
if (isObservableObject(value) === false)
|
|
2975
|
-
|
|
3269
|
+
if (isObservableObject(value) === false) {
|
|
3270
|
+
return false;
|
|
3271
|
+
}
|
|
3272
|
+
|
|
3273
|
+
if (!value[$mobx].values_.has(property)) {
|
|
3274
|
+
return false;
|
|
3275
|
+
}
|
|
3276
|
+
|
|
2976
3277
|
var atom = getAtom(value, property);
|
|
2977
3278
|
return isComputedValue(atom);
|
|
2978
3279
|
}
|
|
2979
3280
|
function isComputed(value) {
|
|
2980
|
-
if ( arguments.length > 1)
|
|
3281
|
+
if ( arguments.length > 1) {
|
|
3282
|
+
return die("isComputed expects only 1 argument. Use isComputedProp to inspect the observability of a property");
|
|
3283
|
+
}
|
|
3284
|
+
|
|
2981
3285
|
return _isComputed(value);
|
|
2982
3286
|
}
|
|
2983
3287
|
function isComputedProp(value, propName) {
|
|
2984
|
-
if ( !isStringish(propName))
|
|
3288
|
+
if ( !isStringish(propName)) {
|
|
3289
|
+
return die("isComputed expected a property name as second argument");
|
|
3290
|
+
}
|
|
3291
|
+
|
|
2985
3292
|
return _isComputed(value, propName);
|
|
2986
3293
|
}
|
|
2987
3294
|
|
|
2988
3295
|
function _isObservable(value, property) {
|
|
2989
|
-
if (!value)
|
|
3296
|
+
if (!value) {
|
|
3297
|
+
return false;
|
|
3298
|
+
}
|
|
2990
3299
|
|
|
2991
3300
|
if (property !== undefined) {
|
|
2992
|
-
if ( (isObservableMap(value) || isObservableArray(value)))
|
|
3301
|
+
if ( (isObservableMap(value) || isObservableArray(value))) {
|
|
3302
|
+
return die("isObservable(object, propertyName) is not supported for arrays and maps. Use map.has or array.length instead.");
|
|
3303
|
+
}
|
|
2993
3304
|
|
|
2994
3305
|
if (isObservableObject(value)) {
|
|
2995
3306
|
return value[$mobx].values_.has(property);
|
|
@@ -3003,11 +3314,17 @@ function _isObservable(value, property) {
|
|
|
3003
3314
|
}
|
|
3004
3315
|
|
|
3005
3316
|
function isObservable(value) {
|
|
3006
|
-
if ( arguments.length !== 1)
|
|
3317
|
+
if ( arguments.length !== 1) {
|
|
3318
|
+
die("isObservable expects only 1 argument. Use isObservableProp to inspect the observability of a property");
|
|
3319
|
+
}
|
|
3320
|
+
|
|
3007
3321
|
return _isObservable(value);
|
|
3008
3322
|
}
|
|
3009
3323
|
function isObservableProp(value, propName) {
|
|
3010
|
-
if ( !isStringish(propName))
|
|
3324
|
+
if ( !isStringish(propName)) {
|
|
3325
|
+
return die("expected a property name as second argument");
|
|
3326
|
+
}
|
|
3327
|
+
|
|
3011
3328
|
return _isObservable(value, propName);
|
|
3012
3329
|
}
|
|
3013
3330
|
|
|
@@ -3099,13 +3416,25 @@ function set(obj, key, value) {
|
|
|
3099
3416
|
} else if (isObservableSet(obj)) {
|
|
3100
3417
|
obj.add(key);
|
|
3101
3418
|
} else if (isObservableArray(obj)) {
|
|
3102
|
-
if (typeof key !== "number")
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3419
|
+
if (typeof key !== "number") {
|
|
3420
|
+
key = parseInt(key, 10);
|
|
3421
|
+
}
|
|
3422
|
+
|
|
3423
|
+
if (key < 0) {
|
|
3424
|
+
die("Invalid index: '" + key + "'");
|
|
3425
|
+
}
|
|
3426
|
+
|
|
3427
|
+
startBatch();
|
|
3428
|
+
|
|
3429
|
+
if (key >= obj.length) {
|
|
3430
|
+
obj.length = key + 1;
|
|
3431
|
+
}
|
|
3432
|
+
|
|
3433
|
+
obj[key] = value;
|
|
3434
|
+
endBatch();
|
|
3435
|
+
} else {
|
|
3436
|
+
die(8);
|
|
3437
|
+
}
|
|
3109
3438
|
}
|
|
3110
3439
|
function remove(obj, key) {
|
|
3111
3440
|
if (isObservableObject(obj)) {
|
|
@@ -3115,7 +3444,10 @@ function remove(obj, key) {
|
|
|
3115
3444
|
} else if (isObservableSet(obj)) {
|
|
3116
3445
|
obj["delete"](key);
|
|
3117
3446
|
} else if (isObservableArray(obj)) {
|
|
3118
|
-
if (typeof key !== "number")
|
|
3447
|
+
if (typeof key !== "number") {
|
|
3448
|
+
key = parseInt(key, 10);
|
|
3449
|
+
}
|
|
3450
|
+
|
|
3119
3451
|
obj.splice(key, 1);
|
|
3120
3452
|
} else {
|
|
3121
3453
|
die(9);
|
|
@@ -3135,7 +3467,9 @@ function has(obj, key) {
|
|
|
3135
3467
|
die(10);
|
|
3136
3468
|
}
|
|
3137
3469
|
function get(obj, key) {
|
|
3138
|
-
if (!has(obj, key))
|
|
3470
|
+
if (!has(obj, key)) {
|
|
3471
|
+
return undefined;
|
|
3472
|
+
}
|
|
3139
3473
|
|
|
3140
3474
|
if (isObservableObject(obj)) {
|
|
3141
3475
|
return obj[$mobx].get_(key);
|
|
@@ -3163,7 +3497,11 @@ function apiOwnKeys(obj) {
|
|
|
3163
3497
|
}
|
|
3164
3498
|
|
|
3165
3499
|
function observe(thing, propOrCb, cbOrFire, fireImmediately) {
|
|
3166
|
-
if (isFunction(cbOrFire))
|
|
3500
|
+
if (isFunction(cbOrFire)) {
|
|
3501
|
+
return observeObservableProperty(thing, propOrCb, cbOrFire, fireImmediately);
|
|
3502
|
+
} else {
|
|
3503
|
+
return observeObservable(thing, propOrCb, cbOrFire);
|
|
3504
|
+
}
|
|
3167
3505
|
}
|
|
3168
3506
|
|
|
3169
3507
|
function observeObservable(thing, listener, fireImmediately) {
|
|
@@ -3180,8 +3518,13 @@ function cache(map, key, value) {
|
|
|
3180
3518
|
}
|
|
3181
3519
|
|
|
3182
3520
|
function toJSHelper(source, __alreadySeen) {
|
|
3183
|
-
if (source == null || typeof source !== "object" || source instanceof Date || !isObservable(source))
|
|
3184
|
-
|
|
3521
|
+
if (source == null || typeof source !== "object" || source instanceof Date || !isObservable(source)) {
|
|
3522
|
+
return source;
|
|
3523
|
+
}
|
|
3524
|
+
|
|
3525
|
+
if (isObservableValue(source) || isComputedValue(source)) {
|
|
3526
|
+
return toJSHelper(source.get(), __alreadySeen);
|
|
3527
|
+
}
|
|
3185
3528
|
|
|
3186
3529
|
if (__alreadySeen.has(source)) {
|
|
3187
3530
|
return __alreadySeen.get(source);
|
|
@@ -3232,18 +3575,25 @@ function toJSHelper(source, __alreadySeen) {
|
|
|
3232
3575
|
|
|
3233
3576
|
|
|
3234
3577
|
function toJS(source, options) {
|
|
3235
|
-
if ( options)
|
|
3578
|
+
if ( options) {
|
|
3579
|
+
die("toJS no longer supports options");
|
|
3580
|
+
}
|
|
3581
|
+
|
|
3236
3582
|
return toJSHelper(source, new Map());
|
|
3237
3583
|
}
|
|
3238
3584
|
|
|
3239
3585
|
function trace() {
|
|
3586
|
+
|
|
3240
3587
|
var enterBreakPoint = false;
|
|
3241
3588
|
|
|
3242
3589
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
3243
3590
|
args[_key] = arguments[_key];
|
|
3244
3591
|
}
|
|
3245
3592
|
|
|
3246
|
-
if (typeof args[args.length - 1] === "boolean")
|
|
3593
|
+
if (typeof args[args.length - 1] === "boolean") {
|
|
3594
|
+
enterBreakPoint = args.pop();
|
|
3595
|
+
}
|
|
3596
|
+
|
|
3247
3597
|
var derivation = getAtomFromArgs(args);
|
|
3248
3598
|
|
|
3249
3599
|
if (!derivation) {
|
|
@@ -3293,7 +3643,10 @@ function transaction(action, thisArg) {
|
|
|
3293
3643
|
}
|
|
3294
3644
|
|
|
3295
3645
|
function when(predicate, arg1, arg2) {
|
|
3296
|
-
if (arguments.length === 1 || arg1 && typeof arg1 === "object")
|
|
3646
|
+
if (arguments.length === 1 || arg1 && typeof arg1 === "object") {
|
|
3647
|
+
return whenPromise(predicate, arg1);
|
|
3648
|
+
}
|
|
3649
|
+
|
|
3297
3650
|
return _when(predicate, arg1, arg2 || {});
|
|
3298
3651
|
}
|
|
3299
3652
|
|
|
@@ -3305,7 +3658,12 @@ function _when(predicate, effect, opts) {
|
|
|
3305
3658
|
timeoutHandle = setTimeout(function () {
|
|
3306
3659
|
if (!disposer[$mobx].isDisposed_) {
|
|
3307
3660
|
disposer();
|
|
3308
|
-
|
|
3661
|
+
|
|
3662
|
+
if (opts.onError) {
|
|
3663
|
+
opts.onError(error);
|
|
3664
|
+
} else {
|
|
3665
|
+
throw error;
|
|
3666
|
+
}
|
|
3309
3667
|
}
|
|
3310
3668
|
}, opts.timeout);
|
|
3311
3669
|
}
|
|
@@ -3319,7 +3677,11 @@ function _when(predicate, effect, opts) {
|
|
|
3319
3677
|
|
|
3320
3678
|
if (cond) {
|
|
3321
3679
|
r.dispose();
|
|
3322
|
-
|
|
3680
|
+
|
|
3681
|
+
if (timeoutHandle) {
|
|
3682
|
+
clearTimeout(timeoutHandle);
|
|
3683
|
+
}
|
|
3684
|
+
|
|
3323
3685
|
effectAction();
|
|
3324
3686
|
}
|
|
3325
3687
|
}, opts);
|
|
@@ -3327,7 +3689,10 @@ function _when(predicate, effect, opts) {
|
|
|
3327
3689
|
}
|
|
3328
3690
|
|
|
3329
3691
|
function whenPromise(predicate, opts) {
|
|
3330
|
-
if ( opts && opts.onError)
|
|
3692
|
+
if ( opts && opts.onError) {
|
|
3693
|
+
return die("the options 'onError' and 'promise' cannot be combined");
|
|
3694
|
+
}
|
|
3695
|
+
|
|
3331
3696
|
var cancel;
|
|
3332
3697
|
var res = new Promise(function (resolve, reject) {
|
|
3333
3698
|
var disposer = _when(predicate, resolve, _extends({}, opts, {
|
|
@@ -3351,7 +3716,10 @@ function getAdm(target) {
|
|
|
3351
3716
|
|
|
3352
3717
|
var objectProxyTraps = {
|
|
3353
3718
|
has: function has(target, name) {
|
|
3354
|
-
if ( globalState.trackingDerivation)
|
|
3719
|
+
if ( globalState.trackingDerivation) {
|
|
3720
|
+
warnAboutProxyRequirement("detect new properties using the 'in' operator. Use 'has' from 'mobx' instead.");
|
|
3721
|
+
}
|
|
3722
|
+
|
|
3355
3723
|
return getAdm(target).has_(name);
|
|
3356
3724
|
},
|
|
3357
3725
|
get: function get(target, name) {
|
|
@@ -3360,7 +3728,9 @@ var objectProxyTraps = {
|
|
|
3360
3728
|
set: function set(target, name, value) {
|
|
3361
3729
|
var _getAdm$set_;
|
|
3362
3730
|
|
|
3363
|
-
if (!isStringish(name))
|
|
3731
|
+
if (!isStringish(name)) {
|
|
3732
|
+
return false;
|
|
3733
|
+
}
|
|
3364
3734
|
|
|
3365
3735
|
if ( !getAdm(target).values_.has(name)) {
|
|
3366
3736
|
warnAboutProxyRequirement("add a new observable property through direct assignment. Use 'set' from 'mobx' instead.");
|
|
@@ -3376,7 +3746,10 @@ var objectProxyTraps = {
|
|
|
3376
3746
|
warnAboutProxyRequirement("delete properties from an observable object. Use 'remove' from 'mobx' instead.");
|
|
3377
3747
|
}
|
|
3378
3748
|
|
|
3379
|
-
if (!isStringish(name))
|
|
3749
|
+
if (!isStringish(name)) {
|
|
3750
|
+
return false;
|
|
3751
|
+
} // null (intercepted) -> true (success)
|
|
3752
|
+
|
|
3380
3753
|
|
|
3381
3754
|
return (_getAdm$delete_ = getAdm(target).delete_(name, true)) != null ? _getAdm$delete_ : true;
|
|
3382
3755
|
},
|
|
@@ -3391,7 +3764,10 @@ var objectProxyTraps = {
|
|
|
3391
3764
|
return (_getAdm$definePropert = getAdm(target).defineProperty_(name, descriptor)) != null ? _getAdm$definePropert : true;
|
|
3392
3765
|
},
|
|
3393
3766
|
ownKeys: function ownKeys(target) {
|
|
3394
|
-
if ( globalState.trackingDerivation)
|
|
3767
|
+
if ( globalState.trackingDerivation) {
|
|
3768
|
+
warnAboutProxyRequirement("iterate keys to detect added / removed properties. Use 'keys' from 'mobx' instead.");
|
|
3769
|
+
}
|
|
3770
|
+
|
|
3395
3771
|
return getAdm(target).ownKeys_();
|
|
3396
3772
|
},
|
|
3397
3773
|
preventExtensions: function preventExtensions(target) {
|
|
@@ -3414,7 +3790,10 @@ function registerInterceptor(interceptable, handler) {
|
|
|
3414
3790
|
interceptors.push(handler);
|
|
3415
3791
|
return once(function () {
|
|
3416
3792
|
var idx = interceptors.indexOf(handler);
|
|
3417
|
-
|
|
3793
|
+
|
|
3794
|
+
if (idx !== -1) {
|
|
3795
|
+
interceptors.splice(idx, 1);
|
|
3796
|
+
}
|
|
3418
3797
|
});
|
|
3419
3798
|
}
|
|
3420
3799
|
function interceptChange(interceptable, change) {
|
|
@@ -3426,8 +3805,14 @@ function interceptChange(interceptable, change) {
|
|
|
3426
3805
|
|
|
3427
3806
|
for (var i = 0, l = interceptors.length; i < l; i++) {
|
|
3428
3807
|
change = interceptors[i](change);
|
|
3429
|
-
|
|
3430
|
-
if (!change)
|
|
3808
|
+
|
|
3809
|
+
if (change && !change.type) {
|
|
3810
|
+
die(14);
|
|
3811
|
+
}
|
|
3812
|
+
|
|
3813
|
+
if (!change) {
|
|
3814
|
+
break;
|
|
3815
|
+
}
|
|
3431
3816
|
}
|
|
3432
3817
|
|
|
3433
3818
|
return change;
|
|
@@ -3444,13 +3829,20 @@ function registerListener(listenable, handler) {
|
|
|
3444
3829
|
listeners.push(handler);
|
|
3445
3830
|
return once(function () {
|
|
3446
3831
|
var idx = listeners.indexOf(handler);
|
|
3447
|
-
|
|
3832
|
+
|
|
3833
|
+
if (idx !== -1) {
|
|
3834
|
+
listeners.splice(idx, 1);
|
|
3835
|
+
}
|
|
3448
3836
|
});
|
|
3449
3837
|
}
|
|
3450
3838
|
function notifyListeners(listenable, change) {
|
|
3451
3839
|
var prevU = untrackedStart();
|
|
3452
3840
|
var listeners = listenable.changeListeners_;
|
|
3453
|
-
|
|
3841
|
+
|
|
3842
|
+
if (!listeners) {
|
|
3843
|
+
return;
|
|
3844
|
+
}
|
|
3845
|
+
|
|
3454
3846
|
listeners = listeners.slice();
|
|
3455
3847
|
|
|
3456
3848
|
for (var i = 0, l = listeners.length; i < l; i++) {
|
|
@@ -3487,8 +3879,13 @@ function makeObservable(target, annotations, options) {
|
|
|
3487
3879
|
var keysSymbol = /*#__PURE__*/Symbol("mobx-keys");
|
|
3488
3880
|
function makeAutoObservable(target, overrides, options) {
|
|
3489
3881
|
{
|
|
3490
|
-
if (!isPlainObject(target) && !isPlainObject(Object.getPrototypeOf(target)))
|
|
3491
|
-
|
|
3882
|
+
if (!isPlainObject(target) && !isPlainObject(Object.getPrototypeOf(target))) {
|
|
3883
|
+
die("'makeAutoObservable' can only be used for classes that don't have a superclass");
|
|
3884
|
+
}
|
|
3885
|
+
|
|
3886
|
+
if (isObservableObject(target)) {
|
|
3887
|
+
die("makeAutoObservable can only be used on objects not already made observable");
|
|
3888
|
+
}
|
|
3492
3889
|
} // Optimization: avoid visiting protos
|
|
3493
3890
|
// Assumes that annotation.make_/.extend_ works the same for plain objects
|
|
3494
3891
|
|
|
@@ -3529,8 +3926,14 @@ var MAX_SPLICE_SIZE = 10000; // See e.g. https://github.com/mobxjs/mobx/issues/8
|
|
|
3529
3926
|
var arrayTraps = {
|
|
3530
3927
|
get: function get(target, name) {
|
|
3531
3928
|
var adm = target[$mobx];
|
|
3532
|
-
|
|
3533
|
-
if (name ===
|
|
3929
|
+
|
|
3930
|
+
if (name === $mobx) {
|
|
3931
|
+
return adm;
|
|
3932
|
+
}
|
|
3933
|
+
|
|
3934
|
+
if (name === "length") {
|
|
3935
|
+
return adm.getArrayLength_();
|
|
3936
|
+
}
|
|
3534
3937
|
|
|
3535
3938
|
if (typeof name === "string" && !isNaN(name)) {
|
|
3536
3939
|
return adm.get_(parseInt(name));
|
|
@@ -3591,12 +3994,18 @@ var ObservableArrayAdministration = /*#__PURE__*/function () {
|
|
|
3591
3994
|
var _proto = ObservableArrayAdministration.prototype;
|
|
3592
3995
|
|
|
3593
3996
|
_proto.dehanceValue_ = function dehanceValue_(value) {
|
|
3594
|
-
if (this.dehancer !== undefined)
|
|
3997
|
+
if (this.dehancer !== undefined) {
|
|
3998
|
+
return this.dehancer(value);
|
|
3999
|
+
}
|
|
4000
|
+
|
|
3595
4001
|
return value;
|
|
3596
4002
|
};
|
|
3597
4003
|
|
|
3598
4004
|
_proto.dehanceValues_ = function dehanceValues_(values) {
|
|
3599
|
-
if (this.dehancer !== undefined && values.length > 0)
|
|
4005
|
+
if (this.dehancer !== undefined && values.length > 0) {
|
|
4006
|
+
return values.map(this.dehancer);
|
|
4007
|
+
}
|
|
4008
|
+
|
|
3600
4009
|
return values;
|
|
3601
4010
|
};
|
|
3602
4011
|
|
|
@@ -3632,9 +4041,15 @@ var ObservableArrayAdministration = /*#__PURE__*/function () {
|
|
|
3632
4041
|
};
|
|
3633
4042
|
|
|
3634
4043
|
_proto.setArrayLength_ = function setArrayLength_(newLength) {
|
|
3635
|
-
if (typeof newLength !== "number" || isNaN(newLength) || newLength < 0)
|
|
4044
|
+
if (typeof newLength !== "number" || isNaN(newLength) || newLength < 0) {
|
|
4045
|
+
die("Out of range: " + newLength);
|
|
4046
|
+
}
|
|
4047
|
+
|
|
3636
4048
|
var currentLength = this.values_.length;
|
|
3637
|
-
|
|
4049
|
+
|
|
4050
|
+
if (newLength === currentLength) {
|
|
4051
|
+
return;
|
|
4052
|
+
} else if (newLength > currentLength) {
|
|
3638
4053
|
var newItems = new Array(newLength - currentLength);
|
|
3639
4054
|
|
|
3640
4055
|
for (var i = 0; i < newLength - currentLength; i++) {
|
|
@@ -3643,13 +4058,21 @@ var ObservableArrayAdministration = /*#__PURE__*/function () {
|
|
|
3643
4058
|
|
|
3644
4059
|
|
|
3645
4060
|
this.spliceWithArray_(currentLength, 0, newItems);
|
|
3646
|
-
} else
|
|
4061
|
+
} else {
|
|
4062
|
+
this.spliceWithArray_(newLength, currentLength - newLength);
|
|
4063
|
+
}
|
|
3647
4064
|
};
|
|
3648
4065
|
|
|
3649
4066
|
_proto.updateArrayLength_ = function updateArrayLength_(oldLength, delta) {
|
|
3650
|
-
if (oldLength !== this.lastKnownLength_)
|
|
4067
|
+
if (oldLength !== this.lastKnownLength_) {
|
|
4068
|
+
die(16);
|
|
4069
|
+
}
|
|
4070
|
+
|
|
3651
4071
|
this.lastKnownLength_ += delta;
|
|
3652
|
-
|
|
4072
|
+
|
|
4073
|
+
if (this.legacyMode_ && delta > 0) {
|
|
4074
|
+
reserveArrayBuffer(oldLength + delta + 1);
|
|
4075
|
+
}
|
|
3653
4076
|
};
|
|
3654
4077
|
|
|
3655
4078
|
_proto.spliceWithArray_ = function spliceWithArray_(index, deleteCount, newItems) {
|
|
@@ -3657,9 +4080,26 @@ var ObservableArrayAdministration = /*#__PURE__*/function () {
|
|
|
3657
4080
|
|
|
3658
4081
|
checkIfStateModificationsAreAllowed(this.atom_);
|
|
3659
4082
|
var length = this.values_.length;
|
|
3660
|
-
|
|
3661
|
-
if (
|
|
3662
|
-
|
|
4083
|
+
|
|
4084
|
+
if (index === undefined) {
|
|
4085
|
+
index = 0;
|
|
4086
|
+
} else if (index > length) {
|
|
4087
|
+
index = length;
|
|
4088
|
+
} else if (index < 0) {
|
|
4089
|
+
index = Math.max(0, length + index);
|
|
4090
|
+
}
|
|
4091
|
+
|
|
4092
|
+
if (arguments.length === 1) {
|
|
4093
|
+
deleteCount = length - index;
|
|
4094
|
+
} else if (deleteCount === undefined || deleteCount === null) {
|
|
4095
|
+
deleteCount = 0;
|
|
4096
|
+
} else {
|
|
4097
|
+
deleteCount = Math.max(0, Math.min(deleteCount, length - index));
|
|
4098
|
+
}
|
|
4099
|
+
|
|
4100
|
+
if (newItems === undefined) {
|
|
4101
|
+
newItems = EMPTY_ARRAY;
|
|
4102
|
+
}
|
|
3663
4103
|
|
|
3664
4104
|
if (hasInterceptors(this)) {
|
|
3665
4105
|
var change = interceptChange(this, {
|
|
@@ -3669,7 +4109,11 @@ var ObservableArrayAdministration = /*#__PURE__*/function () {
|
|
|
3669
4109
|
removedCount: deleteCount,
|
|
3670
4110
|
added: newItems
|
|
3671
4111
|
});
|
|
3672
|
-
|
|
4112
|
+
|
|
4113
|
+
if (!change) {
|
|
4114
|
+
return EMPTY_ARRAY;
|
|
4115
|
+
}
|
|
4116
|
+
|
|
3673
4117
|
deleteCount = change.removedCount;
|
|
3674
4118
|
newItems = change.added;
|
|
3675
4119
|
}
|
|
@@ -3684,7 +4128,11 @@ var ObservableArrayAdministration = /*#__PURE__*/function () {
|
|
|
3684
4128
|
}
|
|
3685
4129
|
|
|
3686
4130
|
var res = this.spliceItemsIntoValues_(index, deleteCount, newItems);
|
|
3687
|
-
|
|
4131
|
+
|
|
4132
|
+
if (deleteCount !== 0 || newItems.length !== 0) {
|
|
4133
|
+
this.notifyArraySplice_(index, newItems, res);
|
|
4134
|
+
}
|
|
4135
|
+
|
|
3688
4136
|
return this.dehanceValues_(res);
|
|
3689
4137
|
};
|
|
3690
4138
|
|
|
@@ -3727,10 +4175,19 @@ var ObservableArrayAdministration = /*#__PURE__*/function () {
|
|
|
3727
4175
|
} : null; // The reason why this is on right hand side here (and not above), is this way the uglifier will drop it, but it won't
|
|
3728
4176
|
// cause any runtime overhead in development mode without NODE_ENV set, unless spying is enabled
|
|
3729
4177
|
|
|
3730
|
-
if ( notifySpy)
|
|
4178
|
+
if ( notifySpy) {
|
|
4179
|
+
spyReportStart(change);
|
|
4180
|
+
}
|
|
4181
|
+
|
|
3731
4182
|
this.atom_.reportChanged();
|
|
3732
|
-
|
|
3733
|
-
if (
|
|
4183
|
+
|
|
4184
|
+
if (notify) {
|
|
4185
|
+
notifyListeners(this, change);
|
|
4186
|
+
}
|
|
4187
|
+
|
|
4188
|
+
if ( notifySpy) {
|
|
4189
|
+
spyReportEnd();
|
|
4190
|
+
}
|
|
3734
4191
|
};
|
|
3735
4192
|
|
|
3736
4193
|
_proto.notifyArraySplice_ = function notifyArraySplice_(index, added, removed) {
|
|
@@ -3747,11 +4204,20 @@ var ObservableArrayAdministration = /*#__PURE__*/function () {
|
|
|
3747
4204
|
removedCount: removed.length,
|
|
3748
4205
|
addedCount: added.length
|
|
3749
4206
|
} : null;
|
|
3750
|
-
|
|
4207
|
+
|
|
4208
|
+
if ( notifySpy) {
|
|
4209
|
+
spyReportStart(change);
|
|
4210
|
+
}
|
|
4211
|
+
|
|
3751
4212
|
this.atom_.reportChanged(); // conform: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/observe
|
|
3752
4213
|
|
|
3753
|
-
if (notify)
|
|
3754
|
-
|
|
4214
|
+
if (notify) {
|
|
4215
|
+
notifyListeners(this, change);
|
|
4216
|
+
}
|
|
4217
|
+
|
|
4218
|
+
if ( notifySpy) {
|
|
4219
|
+
spyReportEnd();
|
|
4220
|
+
}
|
|
3755
4221
|
};
|
|
3756
4222
|
|
|
3757
4223
|
_proto.get_ = function get_(index) {
|
|
@@ -3778,7 +4244,11 @@ var ObservableArrayAdministration = /*#__PURE__*/function () {
|
|
|
3778
4244
|
index: index,
|
|
3779
4245
|
newValue: newValue
|
|
3780
4246
|
});
|
|
3781
|
-
|
|
4247
|
+
|
|
4248
|
+
if (!change) {
|
|
4249
|
+
return;
|
|
4250
|
+
}
|
|
4251
|
+
|
|
3782
4252
|
newValue = change.newValue;
|
|
3783
4253
|
}
|
|
3784
4254
|
|
|
@@ -4019,6 +4489,8 @@ _Symbol$toStringTag = Symbol.toStringTag;
|
|
|
4019
4489
|
var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTag2) {
|
|
4020
4490
|
// hasMap, not hashMap >-).
|
|
4021
4491
|
function ObservableMap(initialData, enhancer_, name_) {
|
|
4492
|
+
var _this = this;
|
|
4493
|
+
|
|
4022
4494
|
if (enhancer_ === void 0) {
|
|
4023
4495
|
enhancer_ = deepEnhancer;
|
|
4024
4496
|
}
|
|
@@ -4046,7 +4518,9 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4046
4518
|
this.keysAtom_ = createAtom( this.name_ + ".keys()" );
|
|
4047
4519
|
this.data_ = new Map();
|
|
4048
4520
|
this.hasMap_ = new Map();
|
|
4049
|
-
|
|
4521
|
+
allowStateChanges(true, function () {
|
|
4522
|
+
_this.merge(initialData);
|
|
4523
|
+
});
|
|
4050
4524
|
}
|
|
4051
4525
|
|
|
4052
4526
|
var _proto = ObservableMap.prototype;
|
|
@@ -4056,16 +4530,19 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4056
4530
|
};
|
|
4057
4531
|
|
|
4058
4532
|
_proto.has = function has(key) {
|
|
4059
|
-
var
|
|
4533
|
+
var _this2 = this;
|
|
4534
|
+
|
|
4535
|
+
if (!globalState.trackingDerivation) {
|
|
4536
|
+
return this.has_(key);
|
|
4537
|
+
}
|
|
4060
4538
|
|
|
4061
|
-
if (!globalState.trackingDerivation) return this.has_(key);
|
|
4062
4539
|
var entry = this.hasMap_.get(key);
|
|
4063
4540
|
|
|
4064
4541
|
if (!entry) {
|
|
4065
4542
|
var newEntry = entry = new ObservableValue(this.has_(key), referenceEnhancer, this.name_ + "." + stringifyKey(key) + "?" , false);
|
|
4066
4543
|
this.hasMap_.set(key, newEntry);
|
|
4067
4544
|
onBecomeUnobserved(newEntry, function () {
|
|
4068
|
-
return
|
|
4545
|
+
return _this2.hasMap_["delete"](key);
|
|
4069
4546
|
});
|
|
4070
4547
|
}
|
|
4071
4548
|
|
|
@@ -4082,7 +4559,11 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4082
4559
|
newValue: value,
|
|
4083
4560
|
name: key
|
|
4084
4561
|
});
|
|
4085
|
-
|
|
4562
|
+
|
|
4563
|
+
if (!change) {
|
|
4564
|
+
return this;
|
|
4565
|
+
}
|
|
4566
|
+
|
|
4086
4567
|
value = change.newValue;
|
|
4087
4568
|
}
|
|
4088
4569
|
|
|
@@ -4096,7 +4577,7 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4096
4577
|
};
|
|
4097
4578
|
|
|
4098
4579
|
_proto["delete"] = function _delete(key) {
|
|
4099
|
-
var
|
|
4580
|
+
var _this3 = this;
|
|
4100
4581
|
|
|
4101
4582
|
checkIfStateModificationsAreAllowed(this.keysAtom_);
|
|
4102
4583
|
|
|
@@ -4106,7 +4587,10 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4106
4587
|
object: this,
|
|
4107
4588
|
name: key
|
|
4108
4589
|
});
|
|
4109
|
-
|
|
4590
|
+
|
|
4591
|
+
if (!change) {
|
|
4592
|
+
return false;
|
|
4593
|
+
}
|
|
4110
4594
|
}
|
|
4111
4595
|
|
|
4112
4596
|
if (this.has_(key)) {
|
|
@@ -4122,23 +4606,33 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4122
4606
|
name: key
|
|
4123
4607
|
} : null;
|
|
4124
4608
|
|
|
4125
|
-
if ( notifySpy)
|
|
4609
|
+
if ( notifySpy) {
|
|
4610
|
+
spyReportStart(_change);
|
|
4611
|
+
} // TODO fix type
|
|
4612
|
+
|
|
4126
4613
|
|
|
4127
4614
|
transaction(function () {
|
|
4128
|
-
var
|
|
4615
|
+
var _this3$hasMap_$get;
|
|
4129
4616
|
|
|
4130
|
-
|
|
4617
|
+
_this3.keysAtom_.reportChanged();
|
|
4131
4618
|
|
|
4132
|
-
(
|
|
4619
|
+
(_this3$hasMap_$get = _this3.hasMap_.get(key)) == null ? void 0 : _this3$hasMap_$get.setNewValue_(false);
|
|
4133
4620
|
|
|
4134
|
-
var observable =
|
|
4621
|
+
var observable = _this3.data_.get(key);
|
|
4135
4622
|
|
|
4136
4623
|
observable.setNewValue_(undefined);
|
|
4137
4624
|
|
|
4138
|
-
|
|
4625
|
+
_this3.data_["delete"](key);
|
|
4139
4626
|
});
|
|
4140
|
-
|
|
4141
|
-
if (
|
|
4627
|
+
|
|
4628
|
+
if (notify) {
|
|
4629
|
+
notifyListeners(this, _change);
|
|
4630
|
+
}
|
|
4631
|
+
|
|
4632
|
+
if ( notifySpy) {
|
|
4633
|
+
spyReportEnd();
|
|
4634
|
+
}
|
|
4635
|
+
|
|
4142
4636
|
return true;
|
|
4143
4637
|
}
|
|
4144
4638
|
|
|
@@ -4161,30 +4655,40 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4161
4655
|
name: key,
|
|
4162
4656
|
newValue: newValue
|
|
4163
4657
|
} : null;
|
|
4164
|
-
|
|
4658
|
+
|
|
4659
|
+
if ( notifySpy) {
|
|
4660
|
+
spyReportStart(change);
|
|
4661
|
+
} // TODO fix type
|
|
4662
|
+
|
|
4165
4663
|
|
|
4166
4664
|
observable.setNewValue_(newValue);
|
|
4167
|
-
|
|
4168
|
-
if (
|
|
4665
|
+
|
|
4666
|
+
if (notify) {
|
|
4667
|
+
notifyListeners(this, change);
|
|
4668
|
+
}
|
|
4669
|
+
|
|
4670
|
+
if ( notifySpy) {
|
|
4671
|
+
spyReportEnd();
|
|
4672
|
+
}
|
|
4169
4673
|
}
|
|
4170
4674
|
};
|
|
4171
4675
|
|
|
4172
4676
|
_proto.addValue_ = function addValue_(key, newValue) {
|
|
4173
|
-
var
|
|
4677
|
+
var _this4 = this;
|
|
4174
4678
|
|
|
4175
4679
|
checkIfStateModificationsAreAllowed(this.keysAtom_);
|
|
4176
4680
|
transaction(function () {
|
|
4177
|
-
var
|
|
4681
|
+
var _this4$hasMap_$get;
|
|
4178
4682
|
|
|
4179
|
-
var observable = new ObservableValue(newValue,
|
|
4683
|
+
var observable = new ObservableValue(newValue, _this4.enhancer_, _this4.name_ + "." + stringifyKey(key) , false);
|
|
4180
4684
|
|
|
4181
|
-
|
|
4685
|
+
_this4.data_.set(key, observable);
|
|
4182
4686
|
|
|
4183
4687
|
newValue = observable.value_; // value might have been changed
|
|
4184
4688
|
|
|
4185
|
-
(
|
|
4689
|
+
(_this4$hasMap_$get = _this4.hasMap_.get(key)) == null ? void 0 : _this4$hasMap_$get.setNewValue_(true);
|
|
4186
4690
|
|
|
4187
|
-
|
|
4691
|
+
_this4.keysAtom_.reportChanged();
|
|
4188
4692
|
});
|
|
4189
4693
|
var notifySpy = isSpyEnabled();
|
|
4190
4694
|
var notify = hasListeners(this);
|
|
@@ -4196,14 +4700,26 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4196
4700
|
name: key,
|
|
4197
4701
|
newValue: newValue
|
|
4198
4702
|
} : null;
|
|
4199
|
-
if ( notifySpy) spyReportStart(change); // TODO fix type
|
|
4200
4703
|
|
|
4201
|
-
if (
|
|
4202
|
-
|
|
4704
|
+
if ( notifySpy) {
|
|
4705
|
+
spyReportStart(change);
|
|
4706
|
+
} // TODO fix type
|
|
4707
|
+
|
|
4708
|
+
|
|
4709
|
+
if (notify) {
|
|
4710
|
+
notifyListeners(this, change);
|
|
4711
|
+
}
|
|
4712
|
+
|
|
4713
|
+
if ( notifySpy) {
|
|
4714
|
+
spyReportEnd();
|
|
4715
|
+
}
|
|
4203
4716
|
};
|
|
4204
4717
|
|
|
4205
4718
|
_proto.get = function get(key) {
|
|
4206
|
-
if (this.has(key))
|
|
4719
|
+
if (this.has(key)) {
|
|
4720
|
+
return this.dehanceValue_(this.data_.get(key).get());
|
|
4721
|
+
}
|
|
4722
|
+
|
|
4207
4723
|
return this.dehanceValue_(undefined);
|
|
4208
4724
|
};
|
|
4209
4725
|
|
|
@@ -4270,45 +4786,54 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4270
4786
|
;
|
|
4271
4787
|
|
|
4272
4788
|
_proto.merge = function merge(other) {
|
|
4273
|
-
var
|
|
4789
|
+
var _this5 = this;
|
|
4274
4790
|
|
|
4275
4791
|
if (isObservableMap(other)) {
|
|
4276
4792
|
other = new Map(other);
|
|
4277
4793
|
}
|
|
4278
4794
|
|
|
4279
4795
|
transaction(function () {
|
|
4280
|
-
if (isPlainObject(other))
|
|
4281
|
-
|
|
4282
|
-
|
|
4283
|
-
|
|
4284
|
-
|
|
4285
|
-
|
|
4286
|
-
|
|
4287
|
-
|
|
4796
|
+
if (isPlainObject(other)) {
|
|
4797
|
+
getPlainObjectKeys(other).forEach(function (key) {
|
|
4798
|
+
return _this5.set(key, other[key]);
|
|
4799
|
+
});
|
|
4800
|
+
} else if (Array.isArray(other)) {
|
|
4801
|
+
other.forEach(function (_ref) {
|
|
4802
|
+
var key = _ref[0],
|
|
4803
|
+
value = _ref[1];
|
|
4804
|
+
return _this5.set(key, value);
|
|
4805
|
+
});
|
|
4806
|
+
} else if (isES6Map(other)) {
|
|
4807
|
+
if (other.constructor !== Map) {
|
|
4808
|
+
die(19, other);
|
|
4809
|
+
}
|
|
4810
|
+
|
|
4288
4811
|
other.forEach(function (value, key) {
|
|
4289
|
-
return
|
|
4812
|
+
return _this5.set(key, value);
|
|
4290
4813
|
});
|
|
4291
|
-
} else if (other !== null && other !== undefined)
|
|
4814
|
+
} else if (other !== null && other !== undefined) {
|
|
4815
|
+
die(20, other);
|
|
4816
|
+
}
|
|
4292
4817
|
});
|
|
4293
4818
|
return this;
|
|
4294
4819
|
};
|
|
4295
4820
|
|
|
4296
4821
|
_proto.clear = function clear() {
|
|
4297
|
-
var
|
|
4822
|
+
var _this6 = this;
|
|
4298
4823
|
|
|
4299
4824
|
transaction(function () {
|
|
4300
4825
|
untracked(function () {
|
|
4301
|
-
for (var _iterator2 = _createForOfIteratorHelperLoose(
|
|
4826
|
+
for (var _iterator2 = _createForOfIteratorHelperLoose(_this6.keys()), _step2; !(_step2 = _iterator2()).done;) {
|
|
4302
4827
|
var key = _step2.value;
|
|
4303
4828
|
|
|
4304
|
-
|
|
4829
|
+
_this6["delete"](key);
|
|
4305
4830
|
}
|
|
4306
4831
|
});
|
|
4307
4832
|
});
|
|
4308
4833
|
};
|
|
4309
4834
|
|
|
4310
4835
|
_proto.replace = function replace(values) {
|
|
4311
|
-
var
|
|
4836
|
+
var _this7 = this;
|
|
4312
4837
|
|
|
4313
4838
|
// Implementation requirements:
|
|
4314
4839
|
// - respect ordering of replacement map
|
|
@@ -4325,13 +4850,13 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4325
4850
|
// if the key deletion is prevented by interceptor
|
|
4326
4851
|
// add entry at the beginning of the result map
|
|
4327
4852
|
|
|
4328
|
-
for (var _iterator3 = _createForOfIteratorHelperLoose(
|
|
4853
|
+
for (var _iterator3 = _createForOfIteratorHelperLoose(_this7.data_.keys()), _step3; !(_step3 = _iterator3()).done;) {
|
|
4329
4854
|
var key = _step3.value;
|
|
4330
4855
|
|
|
4331
4856
|
// Concurrently iterating/deleting keys
|
|
4332
4857
|
// iterator should handle this correctly
|
|
4333
4858
|
if (!replacementMap.has(key)) {
|
|
4334
|
-
var deleted =
|
|
4859
|
+
var deleted = _this7["delete"](key); // Was the key removed?
|
|
4335
4860
|
|
|
4336
4861
|
|
|
4337
4862
|
if (deleted) {
|
|
@@ -4339,7 +4864,7 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4339
4864
|
keysReportChangedCalled = true;
|
|
4340
4865
|
} else {
|
|
4341
4866
|
// Delete prevented by interceptor
|
|
4342
|
-
var value =
|
|
4867
|
+
var value = _this7.data_.get(key);
|
|
4343
4868
|
|
|
4344
4869
|
orderedData.set(key, value);
|
|
4345
4870
|
}
|
|
@@ -4353,17 +4878,17 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4353
4878
|
_value = _step4$value[1];
|
|
4354
4879
|
|
|
4355
4880
|
// We will want to know whether a new key is added
|
|
4356
|
-
var keyExisted =
|
|
4881
|
+
var keyExisted = _this7.data_.has(_key); // Add or update value
|
|
4357
4882
|
|
|
4358
4883
|
|
|
4359
|
-
|
|
4884
|
+
_this7.set(_key, _value); // The addition could have been prevent by interceptor
|
|
4360
4885
|
|
|
4361
4886
|
|
|
4362
|
-
if (
|
|
4887
|
+
if (_this7.data_.has(_key)) {
|
|
4363
4888
|
// The update could have been prevented by interceptor
|
|
4364
4889
|
// and also we want to preserve existing values
|
|
4365
4890
|
// so use value from _data map (instead of replacement map)
|
|
4366
|
-
var _value2 =
|
|
4891
|
+
var _value2 = _this7.data_.get(_key);
|
|
4367
4892
|
|
|
4368
4893
|
orderedData.set(_key, _value2); // Was a new key added?
|
|
4369
4894
|
|
|
@@ -4376,11 +4901,11 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4376
4901
|
|
|
4377
4902
|
|
|
4378
4903
|
if (!keysReportChangedCalled) {
|
|
4379
|
-
if (
|
|
4904
|
+
if (_this7.data_.size !== orderedData.size) {
|
|
4380
4905
|
// If size differs, keys are definitely modified
|
|
4381
|
-
|
|
4906
|
+
_this7.keysAtom_.reportChanged();
|
|
4382
4907
|
} else {
|
|
4383
|
-
var iter1 =
|
|
4908
|
+
var iter1 = _this7.data_.keys();
|
|
4384
4909
|
|
|
4385
4910
|
var iter2 = orderedData.keys();
|
|
4386
4911
|
var next1 = iter1.next();
|
|
@@ -4388,7 +4913,7 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4388
4913
|
|
|
4389
4914
|
while (!next1.done) {
|
|
4390
4915
|
if (next1.value !== next2.value) {
|
|
4391
|
-
|
|
4916
|
+
_this7.keysAtom_.reportChanged();
|
|
4392
4917
|
|
|
4393
4918
|
break;
|
|
4394
4919
|
}
|
|
@@ -4400,7 +4925,7 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4400
4925
|
} // Use correctly ordered map
|
|
4401
4926
|
|
|
4402
4927
|
|
|
4403
|
-
|
|
4928
|
+
_this7.data_ = orderedData;
|
|
4404
4929
|
});
|
|
4405
4930
|
return this;
|
|
4406
4931
|
};
|
|
@@ -4419,7 +4944,10 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4419
4944
|
* for callback details
|
|
4420
4945
|
*/
|
|
4421
4946
|
_proto.observe_ = function observe_(listener, fireImmediately) {
|
|
4422
|
-
if ( fireImmediately === true)
|
|
4947
|
+
if ( fireImmediately === true) {
|
|
4948
|
+
die("`observe` doesn't support fireImmediately=true in combination with maps.");
|
|
4949
|
+
}
|
|
4950
|
+
|
|
4423
4951
|
return registerListener(this, listener);
|
|
4424
4952
|
};
|
|
4425
4953
|
|
|
@@ -4544,8 +5072,12 @@ var ObservableSet = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4544
5072
|
object: this,
|
|
4545
5073
|
newValue: value
|
|
4546
5074
|
});
|
|
4547
|
-
|
|
5075
|
+
|
|
5076
|
+
if (!change) {
|
|
5077
|
+
return this;
|
|
5078
|
+
} // ideally, value = change.value would be done here, so that values can be
|
|
4548
5079
|
// changed by interceptor. Same applies for other Set and Map api's.
|
|
5080
|
+
|
|
4549
5081
|
}
|
|
4550
5082
|
|
|
4551
5083
|
if (!this.has(value)) {
|
|
@@ -4565,9 +5097,17 @@ var ObservableSet = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4565
5097
|
newValue: value
|
|
4566
5098
|
} : null;
|
|
4567
5099
|
|
|
4568
|
-
if (notifySpy && "development" !== "production")
|
|
4569
|
-
|
|
4570
|
-
|
|
5100
|
+
if (notifySpy && "development" !== "production") {
|
|
5101
|
+
spyReportStart(_change);
|
|
5102
|
+
}
|
|
5103
|
+
|
|
5104
|
+
if (notify) {
|
|
5105
|
+
notifyListeners(this, _change);
|
|
5106
|
+
}
|
|
5107
|
+
|
|
5108
|
+
if (notifySpy && "development" !== "production") {
|
|
5109
|
+
spyReportEnd();
|
|
5110
|
+
}
|
|
4571
5111
|
}
|
|
4572
5112
|
|
|
4573
5113
|
return this;
|
|
@@ -4582,7 +5122,10 @@ var ObservableSet = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4582
5122
|
object: this,
|
|
4583
5123
|
oldValue: value
|
|
4584
5124
|
});
|
|
4585
|
-
|
|
5125
|
+
|
|
5126
|
+
if (!change) {
|
|
5127
|
+
return false;
|
|
5128
|
+
}
|
|
4586
5129
|
}
|
|
4587
5130
|
|
|
4588
5131
|
if (this.has(value)) {
|
|
@@ -4597,14 +5140,24 @@ var ObservableSet = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4597
5140
|
oldValue: value
|
|
4598
5141
|
} : null;
|
|
4599
5142
|
|
|
4600
|
-
if (notifySpy && "development" !== "production")
|
|
5143
|
+
if (notifySpy && "development" !== "production") {
|
|
5144
|
+
spyReportStart(_change2);
|
|
5145
|
+
}
|
|
5146
|
+
|
|
4601
5147
|
transaction(function () {
|
|
4602
5148
|
_this3.atom_.reportChanged();
|
|
4603
5149
|
|
|
4604
5150
|
_this3.data_["delete"](value);
|
|
4605
5151
|
});
|
|
4606
|
-
|
|
4607
|
-
if (
|
|
5152
|
+
|
|
5153
|
+
if (notify) {
|
|
5154
|
+
notifyListeners(this, _change2);
|
|
5155
|
+
}
|
|
5156
|
+
|
|
5157
|
+
if (notifySpy && "development" !== "production") {
|
|
5158
|
+
spyReportEnd();
|
|
5159
|
+
}
|
|
5160
|
+
|
|
4608
5161
|
return true;
|
|
4609
5162
|
}
|
|
4610
5163
|
|
|
@@ -4684,7 +5237,10 @@ var ObservableSet = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4684
5237
|
|
|
4685
5238
|
_proto.observe_ = function observe_(listener, fireImmediately) {
|
|
4686
5239
|
// ... 'fireImmediately' could also be true?
|
|
4687
|
-
if ( fireImmediately === true)
|
|
5240
|
+
if ( fireImmediately === true) {
|
|
5241
|
+
die("`observe` doesn't support fireImmediately=true in combination with sets.");
|
|
5242
|
+
}
|
|
5243
|
+
|
|
4688
5244
|
return registerListener(this, listener);
|
|
4689
5245
|
};
|
|
4690
5246
|
|
|
@@ -4786,7 +5342,11 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
4786
5342
|
name: key,
|
|
4787
5343
|
newValue: newValue
|
|
4788
5344
|
});
|
|
4789
|
-
|
|
5345
|
+
|
|
5346
|
+
if (!change) {
|
|
5347
|
+
return null;
|
|
5348
|
+
}
|
|
5349
|
+
|
|
4790
5350
|
newValue = change.newValue;
|
|
4791
5351
|
}
|
|
4792
5352
|
|
|
@@ -4806,10 +5366,18 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
4806
5366
|
newValue: newValue
|
|
4807
5367
|
} : null;
|
|
4808
5368
|
|
|
4809
|
-
if ( notifySpy)
|
|
5369
|
+
if ( notifySpy) {
|
|
5370
|
+
spyReportStart(_change);
|
|
5371
|
+
}
|
|
4810
5372
|
observable.setNewValue_(newValue);
|
|
4811
|
-
|
|
4812
|
-
if (
|
|
5373
|
+
|
|
5374
|
+
if (notify) {
|
|
5375
|
+
notifyListeners(this, _change);
|
|
5376
|
+
}
|
|
5377
|
+
|
|
5378
|
+
if ( notifySpy) {
|
|
5379
|
+
spyReportEnd();
|
|
5380
|
+
}
|
|
4813
5381
|
}
|
|
4814
5382
|
|
|
4815
5383
|
return true;
|
|
@@ -4918,12 +5486,18 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
4918
5486
|
|
|
4919
5487
|
if (descriptor) {
|
|
4920
5488
|
var outcome = annotation.make_(this, key, descriptor, source);
|
|
5489
|
+
|
|
4921
5490
|
if (outcome === 0
|
|
4922
5491
|
/* Cancel */
|
|
4923
|
-
)
|
|
5492
|
+
) {
|
|
5493
|
+
return;
|
|
5494
|
+
}
|
|
5495
|
+
|
|
4924
5496
|
if (outcome === 1
|
|
4925
5497
|
/* Break */
|
|
4926
|
-
)
|
|
5498
|
+
) {
|
|
5499
|
+
break;
|
|
5500
|
+
}
|
|
4927
5501
|
}
|
|
4928
5502
|
|
|
4929
5503
|
source = Object.getPrototypeOf(source);
|
|
@@ -4993,7 +5567,11 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
4993
5567
|
type: ADD,
|
|
4994
5568
|
newValue: descriptor.value
|
|
4995
5569
|
});
|
|
4996
|
-
|
|
5570
|
+
|
|
5571
|
+
if (!change) {
|
|
5572
|
+
return null;
|
|
5573
|
+
}
|
|
5574
|
+
|
|
4997
5575
|
var newValue = change.newValue;
|
|
4998
5576
|
|
|
4999
5577
|
if (descriptor.value !== newValue) {
|
|
@@ -5045,7 +5623,11 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
5045
5623
|
type: ADD,
|
|
5046
5624
|
newValue: value
|
|
5047
5625
|
});
|
|
5048
|
-
|
|
5626
|
+
|
|
5627
|
+
if (!change) {
|
|
5628
|
+
return null;
|
|
5629
|
+
}
|
|
5630
|
+
|
|
5049
5631
|
value = change.newValue;
|
|
5050
5632
|
}
|
|
5051
5633
|
|
|
@@ -5100,7 +5682,10 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
5100
5682
|
type: ADD,
|
|
5101
5683
|
newValue: undefined
|
|
5102
5684
|
});
|
|
5103
|
-
|
|
5685
|
+
|
|
5686
|
+
if (!change) {
|
|
5687
|
+
return null;
|
|
5688
|
+
}
|
|
5104
5689
|
}
|
|
5105
5690
|
|
|
5106
5691
|
options.name || (options.name = "development" !== "production" ? this.name_ + "." + key.toString() : "ObservableObject.key");
|
|
@@ -5156,7 +5741,9 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
5156
5741
|
type: REMOVE
|
|
5157
5742
|
}); // Cancelled
|
|
5158
5743
|
|
|
5159
|
-
if (!change)
|
|
5744
|
+
if (!change) {
|
|
5745
|
+
return null;
|
|
5746
|
+
}
|
|
5160
5747
|
} // Delete
|
|
5161
5748
|
|
|
5162
5749
|
|
|
@@ -5217,9 +5804,18 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
5217
5804
|
oldValue: value,
|
|
5218
5805
|
name: key
|
|
5219
5806
|
};
|
|
5220
|
-
|
|
5221
|
-
if (
|
|
5222
|
-
|
|
5807
|
+
|
|
5808
|
+
if ("development" !== "production" && notifySpy) {
|
|
5809
|
+
spyReportStart(_change2);
|
|
5810
|
+
}
|
|
5811
|
+
|
|
5812
|
+
if (notify) {
|
|
5813
|
+
notifyListeners(this, _change2);
|
|
5814
|
+
}
|
|
5815
|
+
|
|
5816
|
+
if ("development" !== "production" && notifySpy) {
|
|
5817
|
+
spyReportEnd();
|
|
5818
|
+
}
|
|
5223
5819
|
}
|
|
5224
5820
|
} finally {
|
|
5225
5821
|
endBatch();
|
|
@@ -5235,7 +5831,10 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
5235
5831
|
;
|
|
5236
5832
|
|
|
5237
5833
|
_proto.observe_ = function observe_(callback, fireImmediately) {
|
|
5238
|
-
if ( fireImmediately === true)
|
|
5834
|
+
if ( fireImmediately === true) {
|
|
5835
|
+
die("`observe` doesn't support the fire immediately property for observable objects.");
|
|
5836
|
+
}
|
|
5837
|
+
|
|
5239
5838
|
return registerListener(this, callback);
|
|
5240
5839
|
};
|
|
5241
5840
|
|
|
@@ -5258,9 +5857,18 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
5258
5857
|
name: key,
|
|
5259
5858
|
newValue: value
|
|
5260
5859
|
} : null;
|
|
5261
|
-
|
|
5262
|
-
if (
|
|
5263
|
-
|
|
5860
|
+
|
|
5861
|
+
if ( notifySpy) {
|
|
5862
|
+
spyReportStart(change);
|
|
5863
|
+
}
|
|
5864
|
+
|
|
5865
|
+
if (notify) {
|
|
5866
|
+
notifyListeners(this, change);
|
|
5867
|
+
}
|
|
5868
|
+
|
|
5869
|
+
if ( notifySpy) {
|
|
5870
|
+
spyReportEnd();
|
|
5871
|
+
}
|
|
5264
5872
|
}
|
|
5265
5873
|
|
|
5266
5874
|
(_this$pendingKeys_2 = this.pendingKeys_) == null ? void 0 : (_this$pendingKeys_2$g = _this$pendingKeys_2.get(key)) == null ? void 0 : _this$pendingKeys_2$g.set(true); // Notify "keys/entries/values" observers
|
|
@@ -5301,7 +5909,10 @@ function asObservableObject(target, options) {
|
|
|
5301
5909
|
return target;
|
|
5302
5910
|
}
|
|
5303
5911
|
|
|
5304
|
-
if ( !Object.isExtensible(target))
|
|
5912
|
+
if ( !Object.isExtensible(target)) {
|
|
5913
|
+
die("Cannot make the designated object observable; it is not extensible");
|
|
5914
|
+
}
|
|
5915
|
+
|
|
5305
5916
|
var name = (_options$name = options == null ? void 0 : options.name) != null ? _options$name : (isPlainObject(target) ? "ObservableObject" : target.constructor.name) + "@" + getNextId() ;
|
|
5306
5917
|
var adm = new ObservableObjectAdministration(target, new Map(), String(name), getAnnotationFromOptions(options));
|
|
5307
5918
|
addHiddenProp(target, $mobx, adm);
|
|
@@ -5458,7 +6069,6 @@ var LegacyObservableArray = /*#__PURE__*/function (_StubArray, _Symbol$toStringT
|
|
|
5458
6069
|
var nextIndex = 0;
|
|
5459
6070
|
return makeIterable({
|
|
5460
6071
|
next: function next() {
|
|
5461
|
-
// @ts-ignore
|
|
5462
6072
|
return nextIndex < self.length ? {
|
|
5463
6073
|
value: self[nextIndex++],
|
|
5464
6074
|
done: false
|
|
@@ -5491,7 +6101,10 @@ var LegacyObservableArray = /*#__PURE__*/function (_StubArray, _Symbol$toStringT
|
|
|
5491
6101
|
Object.entries(arrayExtensions).forEach(function (_ref) {
|
|
5492
6102
|
var prop = _ref[0],
|
|
5493
6103
|
fn = _ref[1];
|
|
5494
|
-
|
|
6104
|
+
|
|
6105
|
+
if (prop !== "concat") {
|
|
6106
|
+
addHiddenProp(LegacyObservableArray.prototype, prop, fn);
|
|
6107
|
+
}
|
|
5495
6108
|
});
|
|
5496
6109
|
|
|
5497
6110
|
function createArrayEntryDescriptor(index) {
|
|
@@ -5528,7 +6141,10 @@ function createLegacyArray(initialValues, enhancer, name) {
|
|
|
5528
6141
|
function getAtom(thing, property) {
|
|
5529
6142
|
if (typeof thing === "object" && thing !== null) {
|
|
5530
6143
|
if (isObservableArray(thing)) {
|
|
5531
|
-
if (property !== undefined)
|
|
6144
|
+
if (property !== undefined) {
|
|
6145
|
+
die(23);
|
|
6146
|
+
}
|
|
6147
|
+
|
|
5532
6148
|
return thing[$mobx].atom_;
|
|
5533
6149
|
}
|
|
5534
6150
|
|
|
@@ -5537,18 +6153,31 @@ function getAtom(thing, property) {
|
|
|
5537
6153
|
}
|
|
5538
6154
|
|
|
5539
6155
|
if (isObservableMap(thing)) {
|
|
5540
|
-
if (property === undefined)
|
|
6156
|
+
if (property === undefined) {
|
|
6157
|
+
return thing.keysAtom_;
|
|
6158
|
+
}
|
|
6159
|
+
|
|
5541
6160
|
var observable = thing.data_.get(property) || thing.hasMap_.get(property);
|
|
5542
|
-
|
|
6161
|
+
|
|
6162
|
+
if (!observable) {
|
|
6163
|
+
die(25, property, getDebugName(thing));
|
|
6164
|
+
}
|
|
6165
|
+
|
|
5543
6166
|
return observable;
|
|
5544
6167
|
}
|
|
5545
6168
|
|
|
6169
|
+
|
|
5546
6170
|
if (isObservableObject(thing)) {
|
|
5547
|
-
if (!property)
|
|
6171
|
+
if (!property) {
|
|
6172
|
+
return die(26);
|
|
6173
|
+
}
|
|
5548
6174
|
|
|
5549
6175
|
var _observable = thing[$mobx].values_.get(property);
|
|
5550
6176
|
|
|
5551
|
-
if (!_observable)
|
|
6177
|
+
if (!_observable) {
|
|
6178
|
+
die(27, property, getDebugName(thing));
|
|
6179
|
+
}
|
|
6180
|
+
|
|
5552
6181
|
return _observable;
|
|
5553
6182
|
}
|
|
5554
6183
|
|
|
@@ -5565,11 +6194,26 @@ function getAtom(thing, property) {
|
|
|
5565
6194
|
die(28);
|
|
5566
6195
|
}
|
|
5567
6196
|
function getAdministration(thing, property) {
|
|
5568
|
-
if (!thing)
|
|
5569
|
-
|
|
5570
|
-
|
|
5571
|
-
|
|
5572
|
-
if (
|
|
6197
|
+
if (!thing) {
|
|
6198
|
+
die(29);
|
|
6199
|
+
}
|
|
6200
|
+
|
|
6201
|
+
if (property !== undefined) {
|
|
6202
|
+
return getAdministration(getAtom(thing, property));
|
|
6203
|
+
}
|
|
6204
|
+
|
|
6205
|
+
if (isAtom(thing) || isComputedValue(thing) || isReaction(thing)) {
|
|
6206
|
+
return thing;
|
|
6207
|
+
}
|
|
6208
|
+
|
|
6209
|
+
if (isObservableMap(thing) || isObservableSet(thing)) {
|
|
6210
|
+
return thing;
|
|
6211
|
+
}
|
|
6212
|
+
|
|
6213
|
+
if (thing[$mobx]) {
|
|
6214
|
+
return thing[$mobx];
|
|
6215
|
+
}
|
|
6216
|
+
|
|
5573
6217
|
die(24, thing);
|
|
5574
6218
|
}
|
|
5575
6219
|
function getDebugName(thing, property) {
|
|
@@ -5602,17 +6246,33 @@ function deepEqual(a, b, depth) {
|
|
|
5602
6246
|
function eq(a, b, depth, aStack, bStack) {
|
|
5603
6247
|
// Identical objects are equal. `0 === -0`, but they aren't identical.
|
|
5604
6248
|
// See the [Harmony `egal` proposal](http://wiki.ecmascript.org/doku.php?id=harmony:egal).
|
|
5605
|
-
if (a === b)
|
|
6249
|
+
if (a === b) {
|
|
6250
|
+
return a !== 0 || 1 / a === 1 / b;
|
|
6251
|
+
} // `null` or `undefined` only equal to itself (strict comparison).
|
|
5606
6252
|
|
|
5607
|
-
if (a == null || b == null) return false; // `NaN`s are equivalent, but non-reflexive.
|
|
5608
6253
|
|
|
5609
|
-
if (a
|
|
6254
|
+
if (a == null || b == null) {
|
|
6255
|
+
return false;
|
|
6256
|
+
} // `NaN`s are equivalent, but non-reflexive.
|
|
6257
|
+
|
|
6258
|
+
|
|
6259
|
+
if (a !== a) {
|
|
6260
|
+
return b !== b;
|
|
6261
|
+
} // Exhaust primitive checks
|
|
6262
|
+
|
|
5610
6263
|
|
|
5611
6264
|
var type = typeof a;
|
|
5612
|
-
|
|
6265
|
+
|
|
6266
|
+
if (type !== "function" && type !== "object" && typeof b != "object") {
|
|
6267
|
+
return false;
|
|
6268
|
+
} // Compare `[[Class]]` names.
|
|
6269
|
+
|
|
5613
6270
|
|
|
5614
6271
|
var className = toString.call(a);
|
|
5615
|
-
|
|
6272
|
+
|
|
6273
|
+
if (className !== toString.call(b)) {
|
|
6274
|
+
return false;
|
|
6275
|
+
}
|
|
5616
6276
|
|
|
5617
6277
|
switch (className) {
|
|
5618
6278
|
// Strings, numbers, regular expressions, dates, and booleans are compared by value.
|
|
@@ -5626,7 +6286,10 @@ function eq(a, b, depth, aStack, bStack) {
|
|
|
5626
6286
|
case "[object Number]":
|
|
5627
6287
|
// `NaN`s are equivalent, but non-reflexive.
|
|
5628
6288
|
// Object(NaN) is equivalent to NaN.
|
|
5629
|
-
if (+a !== +a)
|
|
6289
|
+
if (+a !== +a) {
|
|
6290
|
+
return +b !== +b;
|
|
6291
|
+
} // An `egal` comparison is performed for other numeric values.
|
|
6292
|
+
|
|
5630
6293
|
|
|
5631
6294
|
return +a === 0 ? 1 / +a === 1 / b : +a === +b;
|
|
5632
6295
|
|
|
@@ -5657,9 +6320,12 @@ function eq(a, b, depth, aStack, bStack) {
|
|
|
5657
6320
|
var areArrays = className === "[object Array]";
|
|
5658
6321
|
|
|
5659
6322
|
if (!areArrays) {
|
|
5660
|
-
if (typeof a != "object" || typeof b != "object")
|
|
6323
|
+
if (typeof a != "object" || typeof b != "object") {
|
|
6324
|
+
return false;
|
|
6325
|
+
} // Objects with different constructors are not equivalent, but `Object`s or `Array`s
|
|
5661
6326
|
// from different frames are.
|
|
5662
6327
|
|
|
6328
|
+
|
|
5663
6329
|
var aCtor = a.constructor,
|
|
5664
6330
|
bCtor = b.constructor;
|
|
5665
6331
|
|
|
@@ -5685,7 +6351,9 @@ function eq(a, b, depth, aStack, bStack) {
|
|
|
5685
6351
|
while (length--) {
|
|
5686
6352
|
// Linear search. Performance is inversely proportional to the number of
|
|
5687
6353
|
// unique nested structures.
|
|
5688
|
-
if (aStack[length] === a)
|
|
6354
|
+
if (aStack[length] === a) {
|
|
6355
|
+
return bStack[length] === b;
|
|
6356
|
+
}
|
|
5689
6357
|
} // Add the first object to the stack of traversed objects.
|
|
5690
6358
|
|
|
5691
6359
|
|
|
@@ -5695,10 +6363,16 @@ function eq(a, b, depth, aStack, bStack) {
|
|
|
5695
6363
|
if (areArrays) {
|
|
5696
6364
|
// Compare array lengths to determine if a deep comparison is necessary.
|
|
5697
6365
|
length = a.length;
|
|
5698
|
-
|
|
6366
|
+
|
|
6367
|
+
if (length !== b.length) {
|
|
6368
|
+
return false;
|
|
6369
|
+
} // Deep compare the contents, ignoring non-numeric properties.
|
|
6370
|
+
|
|
5699
6371
|
|
|
5700
6372
|
while (length--) {
|
|
5701
|
-
if (!eq(a[length], b[length], depth - 1, aStack, bStack))
|
|
6373
|
+
if (!eq(a[length], b[length], depth - 1, aStack, bStack)) {
|
|
6374
|
+
return false;
|
|
6375
|
+
}
|
|
5702
6376
|
}
|
|
5703
6377
|
} else {
|
|
5704
6378
|
// Deep compare objects.
|
|
@@ -5706,12 +6380,17 @@ function eq(a, b, depth, aStack, bStack) {
|
|
|
5706
6380
|
var key;
|
|
5707
6381
|
length = keys.length; // Ensure that both objects contain the same number of properties before comparing deep equality.
|
|
5708
6382
|
|
|
5709
|
-
if (Object.keys(b).length !== length)
|
|
6383
|
+
if (Object.keys(b).length !== length) {
|
|
6384
|
+
return false;
|
|
6385
|
+
}
|
|
5710
6386
|
|
|
5711
6387
|
while (length--) {
|
|
5712
6388
|
// Deep compare each member
|
|
5713
6389
|
key = keys[length];
|
|
5714
|
-
|
|
6390
|
+
|
|
6391
|
+
if (!(hasProp(b, key) && eq(a[key], b[key], depth - 1, aStack, bStack))) {
|
|
6392
|
+
return false;
|
|
6393
|
+
}
|
|
5715
6394
|
}
|
|
5716
6395
|
} // Remove the first object from the stack of traversed objects.
|
|
5717
6396
|
|
|
@@ -5722,9 +6401,18 @@ function eq(a, b, depth, aStack, bStack) {
|
|
|
5722
6401
|
}
|
|
5723
6402
|
|
|
5724
6403
|
function unwrap(a) {
|
|
5725
|
-
if (isObservableArray(a))
|
|
5726
|
-
|
|
5727
|
-
|
|
6404
|
+
if (isObservableArray(a)) {
|
|
6405
|
+
return a.slice();
|
|
6406
|
+
}
|
|
6407
|
+
|
|
6408
|
+
if (isES6Map(a) || isObservableMap(a)) {
|
|
6409
|
+
return Array.from(a.entries());
|
|
6410
|
+
}
|
|
6411
|
+
|
|
6412
|
+
if (isES6Set(a) || isObservableSet(a)) {
|
|
6413
|
+
return Array.from(a.entries());
|
|
6414
|
+
}
|
|
6415
|
+
|
|
5728
6416
|
return a;
|
|
5729
6417
|
}
|
|
5730
6418
|
|