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
|
@@ -23,9 +23,9 @@ var niceErrors = {
|
|
|
23
23
|
10: "'has()' can only be used on observable objects, arrays and maps",
|
|
24
24
|
11: "'get()' can only be used on observable objects, arrays and maps",
|
|
25
25
|
12: "Invalid annotation",
|
|
26
|
-
13: "Dynamic observable objects cannot be frozen",
|
|
26
|
+
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)",
|
|
27
27
|
14: "Intercept handlers should return nothing or a change object",
|
|
28
|
-
15: "Observable arrays cannot be frozen",
|
|
28
|
+
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)",
|
|
29
29
|
16: "Modification exception: the internal structure of an observable array was changed.",
|
|
30
30
|
17: function _(index, length) {
|
|
31
31
|
return "[mobx.array] Index out of bounds, " + index + " is larger than " + length;
|
|
@@ -139,7 +139,10 @@ function getNextId() {
|
|
|
139
139
|
function once(func) {
|
|
140
140
|
var invoked = false;
|
|
141
141
|
return function () {
|
|
142
|
-
if (invoked)
|
|
142
|
+
if (invoked) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
|
|
143
146
|
invoked = true;
|
|
144
147
|
return func.apply(this, arguments);
|
|
145
148
|
};
|
|
@@ -164,17 +167,31 @@ function isObject(value) {
|
|
|
164
167
|
return value !== null && typeof value === "object";
|
|
165
168
|
}
|
|
166
169
|
function isPlainObject(value) {
|
|
167
|
-
if (!isObject(value))
|
|
170
|
+
if (!isObject(value)) {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
|
|
168
174
|
var proto = Object.getPrototypeOf(value);
|
|
169
|
-
|
|
175
|
+
|
|
176
|
+
if (proto == null) {
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
|
|
170
180
|
var protoConstructor = Object.hasOwnProperty.call(proto, "constructor") && proto.constructor;
|
|
171
181
|
return typeof protoConstructor === "function" && protoConstructor.toString() === plainObjectString;
|
|
172
182
|
} // https://stackoverflow.com/a/37865170
|
|
173
183
|
|
|
174
184
|
function isGenerator(obj) {
|
|
175
185
|
var constructor = obj == null ? void 0 : obj.constructor;
|
|
176
|
-
|
|
177
|
-
if (
|
|
186
|
+
|
|
187
|
+
if (!constructor) {
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if ("GeneratorFunction" === constructor.name || "GeneratorFunction" === constructor.displayName) {
|
|
192
|
+
return true;
|
|
193
|
+
}
|
|
194
|
+
|
|
178
195
|
return false;
|
|
179
196
|
}
|
|
180
197
|
function addHiddenProp(object, propName, value) {
|
|
@@ -214,9 +231,16 @@ var hasGetOwnPropertySymbols = typeof Object.getOwnPropertySymbols !== "undefine
|
|
|
214
231
|
function getPlainObjectKeys(object) {
|
|
215
232
|
var keys = Object.keys(object); // Not supported in IE, so there are not going to be symbol props anyway...
|
|
216
233
|
|
|
217
|
-
if (!hasGetOwnPropertySymbols)
|
|
234
|
+
if (!hasGetOwnPropertySymbols) {
|
|
235
|
+
return keys;
|
|
236
|
+
}
|
|
237
|
+
|
|
218
238
|
var symbols = Object.getOwnPropertySymbols(object);
|
|
219
|
-
|
|
239
|
+
|
|
240
|
+
if (!symbols.length) {
|
|
241
|
+
return keys;
|
|
242
|
+
}
|
|
243
|
+
|
|
220
244
|
return [].concat(keys, symbols.filter(function (s) {
|
|
221
245
|
return objectPrototype.propertyIsEnumerable.call(object, s);
|
|
222
246
|
}));
|
|
@@ -229,8 +253,14 @@ var ownKeys = typeof Reflect !== "undefined" && Reflect.ownKeys ? Reflect.ownKey
|
|
|
229
253
|
/* istanbul ignore next */
|
|
230
254
|
Object.getOwnPropertyNames;
|
|
231
255
|
function stringifyKey(key) {
|
|
232
|
-
if (typeof key === "string")
|
|
233
|
-
|
|
256
|
+
if (typeof key === "string") {
|
|
257
|
+
return key;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if (typeof key === "symbol") {
|
|
261
|
+
return key.toString();
|
|
262
|
+
}
|
|
263
|
+
|
|
234
264
|
return new String(key).toString();
|
|
235
265
|
}
|
|
236
266
|
function toPrimitive(value) {
|
|
@@ -518,7 +548,10 @@ function shallowComparer(a, b) {
|
|
|
518
548
|
}
|
|
519
549
|
|
|
520
550
|
function defaultComparer(a, b) {
|
|
521
|
-
if (Object.is)
|
|
551
|
+
if (Object.is) {
|
|
552
|
+
return Object.is(a, b);
|
|
553
|
+
}
|
|
554
|
+
|
|
522
555
|
return a === b ? a !== 0 || 1 / a === 1 / b : a !== a && b !== b;
|
|
523
556
|
}
|
|
524
557
|
|
|
@@ -531,20 +564,34 @@ var comparer = {
|
|
|
531
564
|
|
|
532
565
|
function deepEnhancer(v, _, name) {
|
|
533
566
|
// it is an observable already, done
|
|
534
|
-
if (isObservable(v))
|
|
567
|
+
if (isObservable(v)) {
|
|
568
|
+
return v;
|
|
569
|
+
} // something that can be converted and mutated?
|
|
535
570
|
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
}
|
|
571
|
+
|
|
572
|
+
if (Array.isArray(v)) {
|
|
573
|
+
return observable.array(v, {
|
|
574
|
+
name: name
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
if (isPlainObject(v)) {
|
|
579
|
+
return observable.object(v, undefined, {
|
|
580
|
+
name: name
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
if (isES6Map(v)) {
|
|
585
|
+
return observable.map(v, {
|
|
586
|
+
name: name
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
if (isES6Set(v)) {
|
|
591
|
+
return observable.set(v, {
|
|
592
|
+
name: name
|
|
593
|
+
});
|
|
594
|
+
}
|
|
548
595
|
|
|
549
596
|
if (typeof v === "function" && !isAction(v) && !isFlow(v)) {
|
|
550
597
|
if (isGenerator(v)) {
|
|
@@ -557,33 +604,59 @@ function deepEnhancer(v, _, name) {
|
|
|
557
604
|
return v;
|
|
558
605
|
}
|
|
559
606
|
function shallowEnhancer(v, _, name) {
|
|
560
|
-
if (v === undefined || v === null)
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
607
|
+
if (v === undefined || v === null) {
|
|
608
|
+
return v;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
if (isObservableObject(v) || isObservableArray(v) || isObservableMap(v) || isObservableSet(v)) {
|
|
612
|
+
return v;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
if (Array.isArray(v)) {
|
|
616
|
+
return observable.array(v, {
|
|
617
|
+
name: name,
|
|
618
|
+
deep: false
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
if (isPlainObject(v)) {
|
|
623
|
+
return observable.object(v, undefined, {
|
|
624
|
+
name: name,
|
|
625
|
+
deep: false
|
|
626
|
+
});
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
if (isES6Map(v)) {
|
|
630
|
+
return observable.map(v, {
|
|
631
|
+
name: name,
|
|
632
|
+
deep: false
|
|
633
|
+
});
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
if (isES6Set(v)) {
|
|
637
|
+
return observable.set(v, {
|
|
638
|
+
name: name,
|
|
639
|
+
deep: false
|
|
640
|
+
});
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
{
|
|
644
|
+
die("The shallow modifier / decorator can only used in combination with arrays, objects, maps and sets");
|
|
645
|
+
}
|
|
579
646
|
}
|
|
580
647
|
function referenceEnhancer(newValue) {
|
|
581
648
|
// never turn into an observable
|
|
582
649
|
return newValue;
|
|
583
650
|
}
|
|
584
651
|
function refStructEnhancer(v, oldValue) {
|
|
585
|
-
if ( isObservable(v))
|
|
586
|
-
|
|
652
|
+
if ( isObservable(v)) {
|
|
653
|
+
die("observable.struct should not be used with observable values");
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
if (deepEqual(v, oldValue)) {
|
|
657
|
+
return oldValue;
|
|
658
|
+
}
|
|
659
|
+
|
|
587
660
|
return v;
|
|
588
661
|
}
|
|
589
662
|
|
|
@@ -731,10 +804,12 @@ function make_$2(adm, key, descriptor, source) {
|
|
|
731
804
|
// bound - must annotate protos to support super.flow()
|
|
732
805
|
|
|
733
806
|
|
|
734
|
-
if ((_this$options_ = this.options_) != null && _this$options_.bound && !isFlow(adm.target_[key])) {
|
|
735
|
-
if (this.extend_(adm, key, descriptor, false) === null)
|
|
736
|
-
|
|
737
|
-
|
|
807
|
+
if ((_this$options_ = this.options_) != null && _this$options_.bound && (!hasProp(adm.target_, key) || !isFlow(adm.target_[key]))) {
|
|
808
|
+
if (this.extend_(adm, key, descriptor, false) === null) {
|
|
809
|
+
return 0
|
|
810
|
+
/* Cancel */
|
|
811
|
+
;
|
|
812
|
+
}
|
|
738
813
|
}
|
|
739
814
|
|
|
740
815
|
if (isFlow(descriptor.value)) {
|
|
@@ -775,16 +850,23 @@ safeDescriptors) {
|
|
|
775
850
|
}
|
|
776
851
|
|
|
777
852
|
assertFlowDescriptor(adm, annotation, key, descriptor);
|
|
778
|
-
var value = descriptor.value;
|
|
853
|
+
var value = descriptor.value; // In case of flow.bound, the descriptor can be from already annotated prototype
|
|
854
|
+
|
|
855
|
+
if (!isFlow(value)) {
|
|
856
|
+
value = flow(value);
|
|
857
|
+
}
|
|
779
858
|
|
|
780
859
|
if (bound) {
|
|
781
860
|
var _adm$proxy_;
|
|
782
861
|
|
|
783
|
-
|
|
862
|
+
// We do not keep original function around, so we bind the existing flow
|
|
863
|
+
value = value.bind((_adm$proxy_ = adm.proxy_) != null ? _adm$proxy_ : adm.target_); // This is normally set by `flow`, but `bind` returns new function...
|
|
864
|
+
|
|
865
|
+
value.isMobXFlow = true;
|
|
784
866
|
}
|
|
785
867
|
|
|
786
868
|
return {
|
|
787
|
-
value:
|
|
869
|
+
value: value,
|
|
788
870
|
// Non-configurable for classes
|
|
789
871
|
// prevents accidental field redefinition in subclass
|
|
790
872
|
configurable: safeDescriptors ? adm.isPlainObject_ : true,
|
|
@@ -1018,17 +1100,35 @@ function createObservable(v, arg2, arg3) {
|
|
|
1018
1100
|
} // already observable - ignore
|
|
1019
1101
|
|
|
1020
1102
|
|
|
1021
|
-
if (isObservable(v))
|
|
1103
|
+
if (isObservable(v)) {
|
|
1104
|
+
return v;
|
|
1105
|
+
} // plain object
|
|
1022
1106
|
|
|
1023
|
-
if (isPlainObject(v)) return observable.object(v, arg2, arg3); // Array
|
|
1024
1107
|
|
|
1025
|
-
if (
|
|
1108
|
+
if (isPlainObject(v)) {
|
|
1109
|
+
return observable.object(v, arg2, arg3);
|
|
1110
|
+
} // Array
|
|
1026
1111
|
|
|
1027
|
-
if (isES6Map(v)) return observable.map(v, arg2); // Set
|
|
1028
1112
|
|
|
1029
|
-
if (
|
|
1113
|
+
if (Array.isArray(v)) {
|
|
1114
|
+
return observable.array(v, arg2);
|
|
1115
|
+
} // Map
|
|
1116
|
+
|
|
1117
|
+
|
|
1118
|
+
if (isES6Map(v)) {
|
|
1119
|
+
return observable.map(v, arg2);
|
|
1120
|
+
} // Set
|
|
1121
|
+
|
|
1122
|
+
|
|
1123
|
+
if (isES6Set(v)) {
|
|
1124
|
+
return observable.set(v, arg2);
|
|
1125
|
+
} // other object - ignore
|
|
1126
|
+
|
|
1127
|
+
|
|
1128
|
+
if (typeof v === "object" && v !== null) {
|
|
1129
|
+
return v;
|
|
1130
|
+
} // anything else
|
|
1030
1131
|
|
|
1031
|
-
if (typeof v === "object" && v !== null) return v; // anything else
|
|
1032
1132
|
|
|
1033
1133
|
return observable.box(v, arg2);
|
|
1034
1134
|
}
|
|
@@ -1086,8 +1186,13 @@ var computed = function computed(arg1, arg2) {
|
|
|
1086
1186
|
|
|
1087
1187
|
|
|
1088
1188
|
{
|
|
1089
|
-
if (!isFunction(arg1))
|
|
1090
|
-
|
|
1189
|
+
if (!isFunction(arg1)) {
|
|
1190
|
+
die("First argument to `computed` should be an expression.");
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
if (isFunction(arg2)) {
|
|
1194
|
+
die("A setter as second argument is no longer supported, use `{ set: fn }` option instead");
|
|
1195
|
+
}
|
|
1091
1196
|
}
|
|
1092
1197
|
|
|
1093
1198
|
var opts = isPlainObject(arg2) ? arg2 : {};
|
|
@@ -1119,8 +1224,13 @@ function createAction(actionName, fn, autoAction, ref) {
|
|
|
1119
1224
|
}
|
|
1120
1225
|
|
|
1121
1226
|
{
|
|
1122
|
-
if (!isFunction(fn))
|
|
1123
|
-
|
|
1227
|
+
if (!isFunction(fn)) {
|
|
1228
|
+
die("`action` can only be invoked on functions");
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1231
|
+
if (typeof actionName !== "string" || !actionName) {
|
|
1232
|
+
die("actions should have valid names, got: '" + actionName + "'");
|
|
1233
|
+
}
|
|
1124
1234
|
}
|
|
1125
1235
|
|
|
1126
1236
|
function res() {
|
|
@@ -1202,7 +1312,10 @@ function _endAction(runInfo) {
|
|
|
1202
1312
|
allowStateChangesEnd(runInfo.prevAllowStateChanges_);
|
|
1203
1313
|
allowStateReadsEnd(runInfo.prevAllowStateReads_);
|
|
1204
1314
|
endBatch();
|
|
1205
|
-
|
|
1315
|
+
|
|
1316
|
+
if (runInfo.runAsAction_) {
|
|
1317
|
+
untrackedEnd(runInfo.prevDerivation_);
|
|
1318
|
+
}
|
|
1206
1319
|
|
|
1207
1320
|
if ( runInfo.notifySpy_) {
|
|
1208
1321
|
spyReportEnd({
|
|
@@ -1282,7 +1395,10 @@ var ObservableValue = /*#__PURE__*/function (_Atom, _Symbol$toPrimitive2) {
|
|
|
1282
1395
|
var _proto = ObservableValue.prototype;
|
|
1283
1396
|
|
|
1284
1397
|
_proto.dehanceValue = function dehanceValue(value) {
|
|
1285
|
-
if (this.dehancer !== undefined)
|
|
1398
|
+
if (this.dehancer !== undefined) {
|
|
1399
|
+
return this.dehancer(value);
|
|
1400
|
+
}
|
|
1401
|
+
|
|
1286
1402
|
return value;
|
|
1287
1403
|
};
|
|
1288
1404
|
|
|
@@ -1305,7 +1421,10 @@ var ObservableValue = /*#__PURE__*/function (_Atom, _Symbol$toPrimitive2) {
|
|
|
1305
1421
|
}
|
|
1306
1422
|
|
|
1307
1423
|
this.setNewValue_(newValue);
|
|
1308
|
-
|
|
1424
|
+
|
|
1425
|
+
if ( notifySpy) {
|
|
1426
|
+
spyReportEnd();
|
|
1427
|
+
}
|
|
1309
1428
|
}
|
|
1310
1429
|
};
|
|
1311
1430
|
|
|
@@ -1318,7 +1437,11 @@ var ObservableValue = /*#__PURE__*/function (_Atom, _Symbol$toPrimitive2) {
|
|
|
1318
1437
|
type: UPDATE,
|
|
1319
1438
|
newValue: newValue
|
|
1320
1439
|
});
|
|
1321
|
-
|
|
1440
|
+
|
|
1441
|
+
if (!change) {
|
|
1442
|
+
return globalState.UNCHANGED;
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1322
1445
|
newValue = change.newValue;
|
|
1323
1446
|
} // apply modifier
|
|
1324
1447
|
|
|
@@ -1352,14 +1475,17 @@ var ObservableValue = /*#__PURE__*/function (_Atom, _Symbol$toPrimitive2) {
|
|
|
1352
1475
|
};
|
|
1353
1476
|
|
|
1354
1477
|
_proto.observe_ = function observe_(listener, fireImmediately) {
|
|
1355
|
-
if (fireImmediately)
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1478
|
+
if (fireImmediately) {
|
|
1479
|
+
listener({
|
|
1480
|
+
observableKind: "value",
|
|
1481
|
+
debugObjectName: this.name_,
|
|
1482
|
+
object: this,
|
|
1483
|
+
type: UPDATE,
|
|
1484
|
+
newValue: this.value_,
|
|
1485
|
+
oldValue: undefined
|
|
1486
|
+
});
|
|
1487
|
+
}
|
|
1488
|
+
|
|
1363
1489
|
return registerListener(this, listener);
|
|
1364
1490
|
};
|
|
1365
1491
|
|
|
@@ -1454,7 +1580,11 @@ var ComputedValue = /*#__PURE__*/function (_Symbol$toPrimitive2) {
|
|
|
1454
1580
|
this.keepAlive_ = void 0;
|
|
1455
1581
|
this.onBOL = void 0;
|
|
1456
1582
|
this.onBUOL = void 0;
|
|
1457
|
-
|
|
1583
|
+
|
|
1584
|
+
if (!options.get) {
|
|
1585
|
+
die(31);
|
|
1586
|
+
}
|
|
1587
|
+
|
|
1458
1588
|
this.derivation = options.get;
|
|
1459
1589
|
this.name_ = options.name || ( "ComputedValue@" + getNextId() );
|
|
1460
1590
|
|
|
@@ -1496,7 +1626,9 @@ var ComputedValue = /*#__PURE__*/function (_Symbol$toPrimitive2) {
|
|
|
1496
1626
|
;
|
|
1497
1627
|
|
|
1498
1628
|
_proto.get = function get() {
|
|
1499
|
-
if (this.isComputing_)
|
|
1629
|
+
if (this.isComputing_) {
|
|
1630
|
+
die(32, this.name_, this.derivation);
|
|
1631
|
+
}
|
|
1500
1632
|
|
|
1501
1633
|
if (globalState.inBatch === 0 && // !globalState.trackingDerivatpion &&
|
|
1502
1634
|
this.observers_.size === 0 && !this.keepAlive_) {
|
|
@@ -1512,20 +1644,34 @@ var ComputedValue = /*#__PURE__*/function (_Symbol$toPrimitive2) {
|
|
|
1512
1644
|
|
|
1513
1645
|
if (shouldCompute(this)) {
|
|
1514
1646
|
var prevTrackingContext = globalState.trackingContext;
|
|
1515
|
-
|
|
1516
|
-
if (this.
|
|
1647
|
+
|
|
1648
|
+
if (this.keepAlive_ && !prevTrackingContext) {
|
|
1649
|
+
globalState.trackingContext = this;
|
|
1650
|
+
}
|
|
1651
|
+
|
|
1652
|
+
if (this.trackAndCompute()) {
|
|
1653
|
+
propagateChangeConfirmed(this);
|
|
1654
|
+
}
|
|
1655
|
+
|
|
1517
1656
|
globalState.trackingContext = prevTrackingContext;
|
|
1518
1657
|
}
|
|
1519
1658
|
}
|
|
1520
1659
|
|
|
1521
1660
|
var result = this.value_;
|
|
1522
|
-
|
|
1661
|
+
|
|
1662
|
+
if (isCaughtException(result)) {
|
|
1663
|
+
throw result.cause;
|
|
1664
|
+
}
|
|
1665
|
+
|
|
1523
1666
|
return result;
|
|
1524
1667
|
};
|
|
1525
1668
|
|
|
1526
1669
|
_proto.set = function set(value) {
|
|
1527
1670
|
if (this.setter_) {
|
|
1528
|
-
if (this.isRunningSetter_)
|
|
1671
|
+
if (this.isRunningSetter_) {
|
|
1672
|
+
die(33, this.name_);
|
|
1673
|
+
}
|
|
1674
|
+
|
|
1529
1675
|
this.isRunningSetter_ = true;
|
|
1530
1676
|
|
|
1531
1677
|
try {
|
|
@@ -1533,7 +1679,9 @@ var ComputedValue = /*#__PURE__*/function (_Symbol$toPrimitive2) {
|
|
|
1533
1679
|
} finally {
|
|
1534
1680
|
this.isRunningSetter_ = false;
|
|
1535
1681
|
}
|
|
1536
|
-
} else
|
|
1682
|
+
} else {
|
|
1683
|
+
die(34, this.name_);
|
|
1684
|
+
}
|
|
1537
1685
|
};
|
|
1538
1686
|
|
|
1539
1687
|
_proto.trackAndCompute = function trackAndCompute() {
|
|
@@ -1762,7 +1910,9 @@ function checkIfStateModificationsAreAllowed(atom) {
|
|
|
1762
1910
|
|
|
1763
1911
|
var hasObservers = atom.observers_.size > 0; // Should not be possible to change observed state outside strict mode, except during initialization, see #563
|
|
1764
1912
|
|
|
1765
|
-
if (!globalState.allowStateChanges && (hasObservers || globalState.enforceActions === "always"))
|
|
1913
|
+
if (!globalState.allowStateChanges && (hasObservers || globalState.enforceActions === "always")) {
|
|
1914
|
+
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_);
|
|
1915
|
+
}
|
|
1766
1916
|
}
|
|
1767
1917
|
function checkIfStateReadsAreAllowed(observable) {
|
|
1768
1918
|
if ( !globalState.allowStateReads && globalState.observableRequiresReaction) {
|
|
@@ -1807,7 +1957,10 @@ function trackDerivedFunction(derivation, f, context) {
|
|
|
1807
1957
|
}
|
|
1808
1958
|
|
|
1809
1959
|
function warnAboutDerivationWithoutDependencies(derivation) {
|
|
1810
|
-
|
|
1960
|
+
|
|
1961
|
+
if (derivation.observing_.length !== 0) {
|
|
1962
|
+
return;
|
|
1963
|
+
}
|
|
1811
1964
|
|
|
1812
1965
|
if (globalState.reactionRequiresObservable || derivation.requiresObservable_) {
|
|
1813
1966
|
console.warn("[mobx] Derivation '" + derivation.name_ + "' is created/updated without reading any observable value.");
|
|
@@ -1836,7 +1989,11 @@ function bindDependencies(derivation) {
|
|
|
1836
1989
|
|
|
1837
1990
|
if (dep.diffValue_ === 0) {
|
|
1838
1991
|
dep.diffValue_ = 1;
|
|
1839
|
-
|
|
1992
|
+
|
|
1993
|
+
if (i0 !== i) {
|
|
1994
|
+
observing[i0] = dep;
|
|
1995
|
+
}
|
|
1996
|
+
|
|
1840
1997
|
i0++;
|
|
1841
1998
|
} // Upcast is 'safe' here, because if dep is IObservable, `dependenciesState` will be undefined,
|
|
1842
1999
|
// not hitting the condition
|
|
@@ -1928,7 +2085,10 @@ function allowStateReadsEnd(prev) {
|
|
|
1928
2085
|
*/
|
|
1929
2086
|
|
|
1930
2087
|
function changeDependenciesStateTo0(derivation) {
|
|
1931
|
-
if (derivation.dependenciesState_ === IDerivationState_.UP_TO_DATE_)
|
|
2088
|
+
if (derivation.dependenciesState_ === IDerivationState_.UP_TO_DATE_) {
|
|
2089
|
+
return;
|
|
2090
|
+
}
|
|
2091
|
+
|
|
1932
2092
|
derivation.dependenciesState_ = IDerivationState_.UP_TO_DATE_;
|
|
1933
2093
|
var obs = derivation.observing_;
|
|
1934
2094
|
var i = obs.length;
|
|
@@ -1972,8 +2132,14 @@ var canMergeGlobalState = true;
|
|
|
1972
2132
|
var isolateCalled = false;
|
|
1973
2133
|
var globalState = /*#__PURE__*/function () {
|
|
1974
2134
|
var global = /*#__PURE__*/getGlobal();
|
|
1975
|
-
|
|
1976
|
-
if (global.
|
|
2135
|
+
|
|
2136
|
+
if (global.__mobxInstanceCount > 0 && !global.__mobxGlobals) {
|
|
2137
|
+
canMergeGlobalState = false;
|
|
2138
|
+
}
|
|
2139
|
+
|
|
2140
|
+
if (global.__mobxGlobals && global.__mobxGlobals.version !== new MobXGlobals().version) {
|
|
2141
|
+
canMergeGlobalState = false;
|
|
2142
|
+
}
|
|
1977
2143
|
|
|
1978
2144
|
if (!canMergeGlobalState) {
|
|
1979
2145
|
// Because this is a IIFE we need to let isolateCalled a chance to change
|
|
@@ -1986,7 +2152,11 @@ var globalState = /*#__PURE__*/function () {
|
|
|
1986
2152
|
return new MobXGlobals();
|
|
1987
2153
|
} else if (global.__mobxGlobals) {
|
|
1988
2154
|
global.__mobxInstanceCount += 1;
|
|
1989
|
-
|
|
2155
|
+
|
|
2156
|
+
if (!global.__mobxGlobals.UNCHANGED) {
|
|
2157
|
+
global.__mobxGlobals.UNCHANGED = {};
|
|
2158
|
+
} // make merge backward compatible
|
|
2159
|
+
|
|
1990
2160
|
|
|
1991
2161
|
return global.__mobxGlobals;
|
|
1992
2162
|
} else {
|
|
@@ -1995,12 +2165,19 @@ var globalState = /*#__PURE__*/function () {
|
|
|
1995
2165
|
}
|
|
1996
2166
|
}();
|
|
1997
2167
|
function isolateGlobalState() {
|
|
1998
|
-
if (globalState.pendingReactions.length || globalState.inBatch || globalState.isRunningReactions)
|
|
2168
|
+
if (globalState.pendingReactions.length || globalState.inBatch || globalState.isRunningReactions) {
|
|
2169
|
+
die(36);
|
|
2170
|
+
}
|
|
2171
|
+
|
|
1999
2172
|
isolateCalled = true;
|
|
2000
2173
|
|
|
2001
2174
|
if (canMergeGlobalState) {
|
|
2002
2175
|
var global = getGlobal();
|
|
2003
|
-
|
|
2176
|
+
|
|
2177
|
+
if (--global.__mobxInstanceCount === 0) {
|
|
2178
|
+
global.__mobxGlobals = undefined;
|
|
2179
|
+
}
|
|
2180
|
+
|
|
2004
2181
|
globalState = new MobXGlobals();
|
|
2005
2182
|
}
|
|
2006
2183
|
}
|
|
@@ -2016,7 +2193,9 @@ function resetGlobalState() {
|
|
|
2016
2193
|
var defaultGlobals = new MobXGlobals();
|
|
2017
2194
|
|
|
2018
2195
|
for (var key in defaultGlobals) {
|
|
2019
|
-
if (persistentKeys.indexOf(key) === -1)
|
|
2196
|
+
if (persistentKeys.indexOf(key) === -1) {
|
|
2197
|
+
globalState[key] = defaultGlobals[key];
|
|
2198
|
+
}
|
|
2020
2199
|
}
|
|
2021
2200
|
|
|
2022
2201
|
globalState.allowStateChanges = !globalState.enforceActions;
|
|
@@ -2050,8 +2229,12 @@ function addObserver(observable, node) {
|
|
|
2050
2229
|
// invariant(observable._observers.indexOf(node) === -1, "INTERNAL ERROR add already added node");
|
|
2051
2230
|
// invariantObservers(observable);
|
|
2052
2231
|
observable.observers_.add(node);
|
|
2053
|
-
|
|
2232
|
+
|
|
2233
|
+
if (observable.lowestObserverState_ > node.dependenciesState_) {
|
|
2234
|
+
observable.lowestObserverState_ = node.dependenciesState_;
|
|
2235
|
+
} // invariantObservers(observable);
|
|
2054
2236
|
// invariant(observable._observers.indexOf(node) !== -1, "INTERNAL ERROR didn't add node");
|
|
2237
|
+
|
|
2055
2238
|
}
|
|
2056
2239
|
function removeObserver(observable, node) {
|
|
2057
2240
|
// invariant(globalState.inBatch > 0, "INTERNAL ERROR, remove should be called only inside batch");
|
|
@@ -2162,7 +2345,10 @@ function reportObserved(observable) {
|
|
|
2162
2345
|
|
|
2163
2346
|
function propagateChanged(observable) {
|
|
2164
2347
|
// invariantLOS(observable, "changed start");
|
|
2165
|
-
if (observable.lowestObserverState_ === IDerivationState_.STALE_)
|
|
2348
|
+
if (observable.lowestObserverState_ === IDerivationState_.STALE_) {
|
|
2349
|
+
return;
|
|
2350
|
+
}
|
|
2351
|
+
|
|
2166
2352
|
observable.lowestObserverState_ = IDerivationState_.STALE_; // Ideally we use for..of here, but the downcompiled version is really slow...
|
|
2167
2353
|
|
|
2168
2354
|
observable.observers_.forEach(function (d) {
|
|
@@ -2180,7 +2366,10 @@ function propagateChanged(observable) {
|
|
|
2180
2366
|
|
|
2181
2367
|
function propagateChangeConfirmed(observable) {
|
|
2182
2368
|
// invariantLOS(observable, "confirmed start");
|
|
2183
|
-
if (observable.lowestObserverState_ === IDerivationState_.STALE_)
|
|
2369
|
+
if (observable.lowestObserverState_ === IDerivationState_.STALE_) {
|
|
2370
|
+
return;
|
|
2371
|
+
}
|
|
2372
|
+
|
|
2184
2373
|
observable.lowestObserverState_ = IDerivationState_.STALE_;
|
|
2185
2374
|
observable.observers_.forEach(function (d) {
|
|
2186
2375
|
if (d.dependenciesState_ === IDerivationState_.POSSIBLY_STALE_) {
|
|
@@ -2198,7 +2387,10 @@ function propagateChangeConfirmed(observable) {
|
|
|
2198
2387
|
|
|
2199
2388
|
function propagateMaybeChanged(observable) {
|
|
2200
2389
|
// invariantLOS(observable, "maybe start");
|
|
2201
|
-
if (observable.lowestObserverState_ !== IDerivationState_.UP_TO_DATE_)
|
|
2390
|
+
if (observable.lowestObserverState_ !== IDerivationState_.UP_TO_DATE_) {
|
|
2391
|
+
return;
|
|
2392
|
+
}
|
|
2393
|
+
|
|
2202
2394
|
observable.lowestObserverState_ = IDerivationState_.POSSIBLY_STALE_;
|
|
2203
2395
|
observable.observers_.forEach(function (d) {
|
|
2204
2396
|
if (d.dependenciesState_ === IDerivationState_.UP_TO_DATE_) {
|
|
@@ -2226,9 +2418,12 @@ function printDepTree(tree, lines, depth) {
|
|
|
2226
2418
|
}
|
|
2227
2419
|
|
|
2228
2420
|
lines.push("" + "\t".repeat(depth - 1) + tree.name);
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2421
|
+
|
|
2422
|
+
if (tree.dependencies) {
|
|
2423
|
+
tree.dependencies.forEach(function (child) {
|
|
2424
|
+
return printDepTree(child, lines, depth + 1);
|
|
2425
|
+
});
|
|
2426
|
+
}
|
|
2232
2427
|
}
|
|
2233
2428
|
|
|
2234
2429
|
var Reaction = /*#__PURE__*/function () {
|
|
@@ -2346,7 +2541,9 @@ var Reaction = /*#__PURE__*/function () {
|
|
|
2346
2541
|
clearObserving(this);
|
|
2347
2542
|
}
|
|
2348
2543
|
|
|
2349
|
-
if (isCaughtException(result))
|
|
2544
|
+
if (isCaughtException(result)) {
|
|
2545
|
+
this.reportExceptionInDerivation_(result.cause);
|
|
2546
|
+
}
|
|
2350
2547
|
|
|
2351
2548
|
if ( notify) {
|
|
2352
2549
|
spyReportEnd({
|
|
@@ -2365,13 +2562,18 @@ var Reaction = /*#__PURE__*/function () {
|
|
|
2365
2562
|
return;
|
|
2366
2563
|
}
|
|
2367
2564
|
|
|
2368
|
-
if (globalState.disableErrorBoundaries)
|
|
2565
|
+
if (globalState.disableErrorBoundaries) {
|
|
2566
|
+
throw error;
|
|
2567
|
+
}
|
|
2568
|
+
|
|
2369
2569
|
var message = "[mobx] Encountered an uncaught exception that was thrown by a reaction or observer component, in: '" + this + "'" ;
|
|
2370
2570
|
|
|
2371
2571
|
if (!globalState.suppressReactionErrors) {
|
|
2372
2572
|
console.error(message, error);
|
|
2373
2573
|
/** If debugging brought you here, please, read the above message :-). Tnx! */
|
|
2374
|
-
} else
|
|
2574
|
+
} else {
|
|
2575
|
+
console.warn("[mobx] (error in reaction '" + this.name_ + "' suppressed, fix error of causing action below)");
|
|
2576
|
+
} // prettier-ignore
|
|
2375
2577
|
|
|
2376
2578
|
|
|
2377
2579
|
if ( isSpyEnabled()) {
|
|
@@ -2425,7 +2627,10 @@ function onReactionError(handler) {
|
|
|
2425
2627
|
globalState.globalReactionErrorHandlers.push(handler);
|
|
2426
2628
|
return function () {
|
|
2427
2629
|
var idx = globalState.globalReactionErrorHandlers.indexOf(handler);
|
|
2428
|
-
|
|
2630
|
+
|
|
2631
|
+
if (idx >= 0) {
|
|
2632
|
+
globalState.globalReactionErrorHandlers.splice(idx, 1);
|
|
2633
|
+
}
|
|
2429
2634
|
};
|
|
2430
2635
|
}
|
|
2431
2636
|
/**
|
|
@@ -2442,7 +2647,10 @@ var reactionScheduler = function reactionScheduler(f) {
|
|
|
2442
2647
|
|
|
2443
2648
|
function runReactions() {
|
|
2444
2649
|
// Trampolining, if runReactions are already running, new reactions will be picked up
|
|
2445
|
-
if (globalState.inBatch > 0 || globalState.isRunningReactions)
|
|
2650
|
+
if (globalState.inBatch > 0 || globalState.isRunningReactions) {
|
|
2651
|
+
return;
|
|
2652
|
+
}
|
|
2653
|
+
|
|
2446
2654
|
reactionScheduler(runReactionsHelper);
|
|
2447
2655
|
}
|
|
2448
2656
|
|
|
@@ -2485,7 +2693,11 @@ function isSpyEnabled() {
|
|
|
2485
2693
|
}
|
|
2486
2694
|
function spyReport(event) {
|
|
2487
2695
|
|
|
2488
|
-
|
|
2696
|
+
|
|
2697
|
+
if (!globalState.spyListeners.length) {
|
|
2698
|
+
return;
|
|
2699
|
+
}
|
|
2700
|
+
|
|
2489
2701
|
var listeners = globalState.spyListeners;
|
|
2490
2702
|
|
|
2491
2703
|
for (var i = 0, l = listeners.length; i < l; i++) {
|
|
@@ -2505,10 +2717,15 @@ var END_EVENT = {
|
|
|
2505
2717
|
spyReportEnd: true
|
|
2506
2718
|
};
|
|
2507
2719
|
function spyReportEnd(change) {
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2720
|
+
|
|
2721
|
+
if (change) {
|
|
2722
|
+
spyReport(_extends({}, change, {
|
|
2723
|
+
type: "report-end",
|
|
2724
|
+
spyReportEnd: true
|
|
2725
|
+
}));
|
|
2726
|
+
} else {
|
|
2727
|
+
spyReport(END_EVENT);
|
|
2728
|
+
}
|
|
2512
2729
|
}
|
|
2513
2730
|
function spy(listener) {
|
|
2514
2731
|
{
|
|
@@ -2541,9 +2758,15 @@ var autoActionBoundAnnotation = /*#__PURE__*/createActionAnnotation(AUTOACTION_B
|
|
|
2541
2758
|
function createActionFactory(autoAction) {
|
|
2542
2759
|
var res = function action(arg1, arg2) {
|
|
2543
2760
|
// action(fn() {})
|
|
2544
|
-
if (isFunction(arg1))
|
|
2761
|
+
if (isFunction(arg1)) {
|
|
2762
|
+
return createAction(arg1.name || DEFAULT_ACTION_NAME, arg1, autoAction);
|
|
2763
|
+
} // action("name", fn() {})
|
|
2764
|
+
|
|
2765
|
+
|
|
2766
|
+
if (isFunction(arg2)) {
|
|
2767
|
+
return createAction(arg1, arg2, autoAction);
|
|
2768
|
+
} // @action
|
|
2545
2769
|
|
|
2546
|
-
if (isFunction(arg2)) return createAction(arg1, arg2, autoAction); // @action
|
|
2547
2770
|
|
|
2548
2771
|
if (isStringish(arg2)) {
|
|
2549
2772
|
return storeAnnotation(arg1, arg2, autoAction ? autoActionAnnotation : actionAnnotation);
|
|
@@ -2557,7 +2780,9 @@ function createActionFactory(autoAction) {
|
|
|
2557
2780
|
}));
|
|
2558
2781
|
}
|
|
2559
2782
|
|
|
2560
|
-
|
|
2783
|
+
{
|
|
2784
|
+
die("Invalid arguments for `action`");
|
|
2785
|
+
}
|
|
2561
2786
|
};
|
|
2562
2787
|
|
|
2563
2788
|
return res;
|
|
@@ -2591,8 +2816,13 @@ function autorun(view, opts) {
|
|
|
2591
2816
|
}
|
|
2592
2817
|
|
|
2593
2818
|
{
|
|
2594
|
-
if (!isFunction(view))
|
|
2595
|
-
|
|
2819
|
+
if (!isFunction(view)) {
|
|
2820
|
+
die("Autorun expects a function as first argument");
|
|
2821
|
+
}
|
|
2822
|
+
|
|
2823
|
+
if (isAction(view)) {
|
|
2824
|
+
die("Autorun does not accept actions since actions are untrackable");
|
|
2825
|
+
}
|
|
2596
2826
|
}
|
|
2597
2827
|
|
|
2598
2828
|
var name = (_opts$name = (_opts = opts) == null ? void 0 : _opts.name) != null ? _opts$name : view.name || "Autorun@" + getNextId() ;
|
|
@@ -2613,7 +2843,10 @@ function autorun(view, opts) {
|
|
|
2613
2843
|
isScheduled = true;
|
|
2614
2844
|
scheduler(function () {
|
|
2615
2845
|
isScheduled = false;
|
|
2616
|
-
|
|
2846
|
+
|
|
2847
|
+
if (!reaction.isDisposed_) {
|
|
2848
|
+
reaction.track(reactionRunner);
|
|
2849
|
+
}
|
|
2617
2850
|
});
|
|
2618
2851
|
}
|
|
2619
2852
|
}, opts.onError, opts.requiresObservable);
|
|
@@ -2645,8 +2878,13 @@ function reaction(expression, effect, opts) {
|
|
|
2645
2878
|
}
|
|
2646
2879
|
|
|
2647
2880
|
{
|
|
2648
|
-
if (!isFunction(expression) || !isFunction(effect))
|
|
2649
|
-
|
|
2881
|
+
if (!isFunction(expression) || !isFunction(effect)) {
|
|
2882
|
+
die("First and second argument to reaction should be functions");
|
|
2883
|
+
}
|
|
2884
|
+
|
|
2885
|
+
if (!isPlainObject(opts)) {
|
|
2886
|
+
die("Third argument of reactions should be an object");
|
|
2887
|
+
}
|
|
2650
2888
|
}
|
|
2651
2889
|
|
|
2652
2890
|
var name = (_opts$name2 = opts.name) != null ? _opts$name2 : "Reaction@" + getNextId() ;
|
|
@@ -2669,7 +2907,11 @@ function reaction(expression, effect, opts) {
|
|
|
2669
2907
|
|
|
2670
2908
|
function reactionRunner() {
|
|
2671
2909
|
isScheduled = false;
|
|
2672
|
-
|
|
2910
|
+
|
|
2911
|
+
if (r.isDisposed_) {
|
|
2912
|
+
return;
|
|
2913
|
+
}
|
|
2914
|
+
|
|
2673
2915
|
var changed = false;
|
|
2674
2916
|
r.track(function () {
|
|
2675
2917
|
var nextValue = allowStateChanges(false, function () {
|
|
@@ -2679,7 +2921,13 @@ function reaction(expression, effect, opts) {
|
|
|
2679
2921
|
oldValue = value;
|
|
2680
2922
|
value = nextValue;
|
|
2681
2923
|
});
|
|
2682
|
-
|
|
2924
|
+
|
|
2925
|
+
if (firstTime && opts.fireImmediately) {
|
|
2926
|
+
effectAction(value, oldValue, r);
|
|
2927
|
+
} else if (!firstTime && changed) {
|
|
2928
|
+
effectAction(value, oldValue, r);
|
|
2929
|
+
}
|
|
2930
|
+
|
|
2683
2931
|
firstTime = false;
|
|
2684
2932
|
}
|
|
2685
2933
|
|
|
@@ -2746,7 +2994,9 @@ function configure(options) {
|
|
|
2746
2994
|
globalState.useProxies = useProxies === ALWAYS ? true : useProxies === NEVER ? false : typeof Proxy !== "undefined";
|
|
2747
2995
|
}
|
|
2748
2996
|
|
|
2749
|
-
if (useProxies === "ifavailable")
|
|
2997
|
+
if (useProxies === "ifavailable") {
|
|
2998
|
+
globalState.verifyProxies = true;
|
|
2999
|
+
}
|
|
2750
3000
|
|
|
2751
3001
|
if (enforceActions !== undefined) {
|
|
2752
3002
|
var ea = enforceActions === ALWAYS ? ALWAYS : enforceActions === OBSERVED;
|
|
@@ -2754,7 +3004,9 @@ function configure(options) {
|
|
|
2754
3004
|
globalState.allowStateChanges = ea === true || ea === ALWAYS ? false : true;
|
|
2755
3005
|
}
|
|
2756
3006
|
["computedRequiresReaction", "reactionRequiresObservable", "observableRequiresReaction", "disableErrorBoundaries", "safeDescriptors"].forEach(function (key) {
|
|
2757
|
-
if (key in options)
|
|
3007
|
+
if (key in options) {
|
|
3008
|
+
globalState[key] = !!options[key];
|
|
3009
|
+
}
|
|
2758
3010
|
});
|
|
2759
3011
|
globalState.allowStateReads = !globalState.observableRequiresReaction;
|
|
2760
3012
|
|
|
@@ -2769,11 +3021,25 @@ function configure(options) {
|
|
|
2769
3021
|
|
|
2770
3022
|
function extendObservable(target, properties, annotations, options) {
|
|
2771
3023
|
{
|
|
2772
|
-
if (arguments.length > 4)
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
if (
|
|
3024
|
+
if (arguments.length > 4) {
|
|
3025
|
+
die("'extendObservable' expected 2-4 arguments");
|
|
3026
|
+
}
|
|
3027
|
+
|
|
3028
|
+
if (typeof target !== "object") {
|
|
3029
|
+
die("'extendObservable' expects an object as first argument");
|
|
3030
|
+
}
|
|
3031
|
+
|
|
3032
|
+
if (isObservableMap(target)) {
|
|
3033
|
+
die("'extendObservable' should not be used on maps, use map.merge instead");
|
|
3034
|
+
}
|
|
3035
|
+
|
|
3036
|
+
if (!isPlainObject(properties)) {
|
|
3037
|
+
die("'extendObservable' only accepts plain objects as second argument");
|
|
3038
|
+
}
|
|
3039
|
+
|
|
3040
|
+
if (isObservable(properties) || isObservable(annotations)) {
|
|
3041
|
+
die("Extending an object with another observable (object) is not supported");
|
|
3042
|
+
}
|
|
2777
3043
|
} // Pull descriptors first, so we don't have to deal with props added by administration ($mobx)
|
|
2778
3044
|
|
|
2779
3045
|
|
|
@@ -2801,7 +3067,11 @@ function nodeToDependencyTree(node) {
|
|
|
2801
3067
|
var result = {
|
|
2802
3068
|
name: node.name_
|
|
2803
3069
|
};
|
|
2804
|
-
|
|
3070
|
+
|
|
3071
|
+
if (node.observing_ && node.observing_.length > 0) {
|
|
3072
|
+
result.dependencies = unique(node.observing_).map(nodeToDependencyTree);
|
|
3073
|
+
}
|
|
3074
|
+
|
|
2805
3075
|
return result;
|
|
2806
3076
|
}
|
|
2807
3077
|
|
|
@@ -2813,7 +3083,11 @@ function nodeToObserverTree(node) {
|
|
|
2813
3083
|
var result = {
|
|
2814
3084
|
name: node.name_
|
|
2815
3085
|
};
|
|
2816
|
-
|
|
3086
|
+
|
|
3087
|
+
if (hasObservers(node)) {
|
|
3088
|
+
result.observers = Array.from(getObservers(node)).map(nodeToObserverTree);
|
|
3089
|
+
}
|
|
3090
|
+
|
|
2817
3091
|
return result;
|
|
2818
3092
|
}
|
|
2819
3093
|
|
|
@@ -2840,7 +3114,10 @@ var flow = /*#__PURE__*/Object.assign(function flow(arg1, arg2) {
|
|
|
2840
3114
|
} // flow(fn)
|
|
2841
3115
|
|
|
2842
3116
|
|
|
2843
|
-
if ( arguments.length !== 1)
|
|
3117
|
+
if ( arguments.length !== 1) {
|
|
3118
|
+
die("Flow expects single argument with generator function");
|
|
3119
|
+
}
|
|
3120
|
+
|
|
2844
3121
|
var generator = arg1;
|
|
2845
3122
|
var name = generator.name || "<unnamed flow>"; // Implementation based on https://github.com/tj/co/blob/master/index.js
|
|
2846
3123
|
|
|
@@ -2888,7 +3165,10 @@ var flow = /*#__PURE__*/Object.assign(function flow(arg1, arg2) {
|
|
|
2888
3165
|
return;
|
|
2889
3166
|
}
|
|
2890
3167
|
|
|
2891
|
-
if (ret.done)
|
|
3168
|
+
if (ret.done) {
|
|
3169
|
+
return resolve(ret.value);
|
|
3170
|
+
}
|
|
3171
|
+
|
|
2892
3172
|
pendingPromise = Promise.resolve(ret.value);
|
|
2893
3173
|
return pendingPromise.then(onFulfilled, onRejected);
|
|
2894
3174
|
}
|
|
@@ -2897,7 +3177,10 @@ var flow = /*#__PURE__*/Object.assign(function flow(arg1, arg2) {
|
|
|
2897
3177
|
});
|
|
2898
3178
|
promise.cancel = action(name + " - runid: " + runId + " - cancel", function () {
|
|
2899
3179
|
try {
|
|
2900
|
-
if (pendingPromise)
|
|
3180
|
+
if (pendingPromise) {
|
|
3181
|
+
cancelPromise(pendingPromise);
|
|
3182
|
+
} // Finally block can return (or yield) stuff..
|
|
3183
|
+
|
|
2901
3184
|
|
|
2902
3185
|
var _res = gen["return"](undefined); // eat anything that promise would do, it's cancelled!
|
|
2903
3186
|
|
|
@@ -2921,7 +3204,9 @@ var flow = /*#__PURE__*/Object.assign(function flow(arg1, arg2) {
|
|
|
2921
3204
|
flow.bound = /*#__PURE__*/createDecoratorAnnotation(flowBoundAnnotation);
|
|
2922
3205
|
|
|
2923
3206
|
function cancelPromise(promise) {
|
|
2924
|
-
if (isFunction(promise.cancel))
|
|
3207
|
+
if (isFunction(promise.cancel)) {
|
|
3208
|
+
promise.cancel();
|
|
3209
|
+
}
|
|
2925
3210
|
}
|
|
2926
3211
|
|
|
2927
3212
|
function flowResult(result) {
|
|
@@ -2937,13 +3222,19 @@ function interceptReads(thing, propOrHandler, handler) {
|
|
|
2937
3222
|
if (isObservableMap(thing) || isObservableArray(thing) || isObservableValue(thing)) {
|
|
2938
3223
|
target = getAdministration(thing);
|
|
2939
3224
|
} else if (isObservableObject(thing)) {
|
|
2940
|
-
if ( !isStringish(propOrHandler))
|
|
3225
|
+
if ( !isStringish(propOrHandler)) {
|
|
3226
|
+
return die("InterceptReads can only be used with a specific property, not with an object in general");
|
|
3227
|
+
}
|
|
3228
|
+
|
|
2941
3229
|
target = getAdministration(thing, propOrHandler);
|
|
2942
3230
|
} else {
|
|
2943
3231
|
return die("Expected observable map, object or array as first array");
|
|
2944
3232
|
}
|
|
2945
3233
|
|
|
2946
|
-
if ( target.dehancer !== undefined)
|
|
3234
|
+
if ( target.dehancer !== undefined) {
|
|
3235
|
+
return die("An intercept reader was already established");
|
|
3236
|
+
}
|
|
3237
|
+
|
|
2947
3238
|
target.dehancer = typeof propOrHandler === "function" ? propOrHandler : handler;
|
|
2948
3239
|
return function () {
|
|
2949
3240
|
target.dehancer = undefined;
|
|
@@ -2951,7 +3242,11 @@ function interceptReads(thing, propOrHandler, handler) {
|
|
|
2951
3242
|
}
|
|
2952
3243
|
|
|
2953
3244
|
function intercept(thing, propOrHandler, handler) {
|
|
2954
|
-
if (isFunction(handler))
|
|
3245
|
+
if (isFunction(handler)) {
|
|
3246
|
+
return interceptProperty(thing, propOrHandler, handler);
|
|
3247
|
+
} else {
|
|
3248
|
+
return interceptInterceptable(thing, propOrHandler);
|
|
3249
|
+
}
|
|
2955
3250
|
}
|
|
2956
3251
|
|
|
2957
3252
|
function interceptInterceptable(thing, handler) {
|
|
@@ -2967,25 +3262,41 @@ function _isComputed(value, property) {
|
|
|
2967
3262
|
return isComputedValue(value);
|
|
2968
3263
|
}
|
|
2969
3264
|
|
|
2970
|
-
if (isObservableObject(value) === false)
|
|
2971
|
-
|
|
3265
|
+
if (isObservableObject(value) === false) {
|
|
3266
|
+
return false;
|
|
3267
|
+
}
|
|
3268
|
+
|
|
3269
|
+
if (!value[$mobx].values_.has(property)) {
|
|
3270
|
+
return false;
|
|
3271
|
+
}
|
|
3272
|
+
|
|
2972
3273
|
var atom = getAtom(value, property);
|
|
2973
3274
|
return isComputedValue(atom);
|
|
2974
3275
|
}
|
|
2975
3276
|
function isComputed(value) {
|
|
2976
|
-
if ( arguments.length > 1)
|
|
3277
|
+
if ( arguments.length > 1) {
|
|
3278
|
+
return die("isComputed expects only 1 argument. Use isComputedProp to inspect the observability of a property");
|
|
3279
|
+
}
|
|
3280
|
+
|
|
2977
3281
|
return _isComputed(value);
|
|
2978
3282
|
}
|
|
2979
3283
|
function isComputedProp(value, propName) {
|
|
2980
|
-
if ( !isStringish(propName))
|
|
3284
|
+
if ( !isStringish(propName)) {
|
|
3285
|
+
return die("isComputed expected a property name as second argument");
|
|
3286
|
+
}
|
|
3287
|
+
|
|
2981
3288
|
return _isComputed(value, propName);
|
|
2982
3289
|
}
|
|
2983
3290
|
|
|
2984
3291
|
function _isObservable(value, property) {
|
|
2985
|
-
if (!value)
|
|
3292
|
+
if (!value) {
|
|
3293
|
+
return false;
|
|
3294
|
+
}
|
|
2986
3295
|
|
|
2987
3296
|
if (property !== undefined) {
|
|
2988
|
-
if ( (isObservableMap(value) || isObservableArray(value)))
|
|
3297
|
+
if ( (isObservableMap(value) || isObservableArray(value))) {
|
|
3298
|
+
return die("isObservable(object, propertyName) is not supported for arrays and maps. Use map.has or array.length instead.");
|
|
3299
|
+
}
|
|
2989
3300
|
|
|
2990
3301
|
if (isObservableObject(value)) {
|
|
2991
3302
|
return value[$mobx].values_.has(property);
|
|
@@ -2999,11 +3310,17 @@ function _isObservable(value, property) {
|
|
|
2999
3310
|
}
|
|
3000
3311
|
|
|
3001
3312
|
function isObservable(value) {
|
|
3002
|
-
if ( arguments.length !== 1)
|
|
3313
|
+
if ( arguments.length !== 1) {
|
|
3314
|
+
die("isObservable expects only 1 argument. Use isObservableProp to inspect the observability of a property");
|
|
3315
|
+
}
|
|
3316
|
+
|
|
3003
3317
|
return _isObservable(value);
|
|
3004
3318
|
}
|
|
3005
3319
|
function isObservableProp(value, propName) {
|
|
3006
|
-
if ( !isStringish(propName))
|
|
3320
|
+
if ( !isStringish(propName)) {
|
|
3321
|
+
return die("expected a property name as second argument");
|
|
3322
|
+
}
|
|
3323
|
+
|
|
3007
3324
|
return _isObservable(value, propName);
|
|
3008
3325
|
}
|
|
3009
3326
|
|
|
@@ -3095,13 +3412,25 @@ function set(obj, key, value) {
|
|
|
3095
3412
|
} else if (isObservableSet(obj)) {
|
|
3096
3413
|
obj.add(key);
|
|
3097
3414
|
} else if (isObservableArray(obj)) {
|
|
3098
|
-
if (typeof key !== "number")
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3415
|
+
if (typeof key !== "number") {
|
|
3416
|
+
key = parseInt(key, 10);
|
|
3417
|
+
}
|
|
3418
|
+
|
|
3419
|
+
if (key < 0) {
|
|
3420
|
+
die("Invalid index: '" + key + "'");
|
|
3421
|
+
}
|
|
3422
|
+
|
|
3423
|
+
startBatch();
|
|
3424
|
+
|
|
3425
|
+
if (key >= obj.length) {
|
|
3426
|
+
obj.length = key + 1;
|
|
3427
|
+
}
|
|
3428
|
+
|
|
3429
|
+
obj[key] = value;
|
|
3430
|
+
endBatch();
|
|
3431
|
+
} else {
|
|
3432
|
+
die(8);
|
|
3433
|
+
}
|
|
3105
3434
|
}
|
|
3106
3435
|
function remove(obj, key) {
|
|
3107
3436
|
if (isObservableObject(obj)) {
|
|
@@ -3111,7 +3440,10 @@ function remove(obj, key) {
|
|
|
3111
3440
|
} else if (isObservableSet(obj)) {
|
|
3112
3441
|
obj["delete"](key);
|
|
3113
3442
|
} else if (isObservableArray(obj)) {
|
|
3114
|
-
if (typeof key !== "number")
|
|
3443
|
+
if (typeof key !== "number") {
|
|
3444
|
+
key = parseInt(key, 10);
|
|
3445
|
+
}
|
|
3446
|
+
|
|
3115
3447
|
obj.splice(key, 1);
|
|
3116
3448
|
} else {
|
|
3117
3449
|
die(9);
|
|
@@ -3131,7 +3463,9 @@ function has(obj, key) {
|
|
|
3131
3463
|
die(10);
|
|
3132
3464
|
}
|
|
3133
3465
|
function get(obj, key) {
|
|
3134
|
-
if (!has(obj, key))
|
|
3466
|
+
if (!has(obj, key)) {
|
|
3467
|
+
return undefined;
|
|
3468
|
+
}
|
|
3135
3469
|
|
|
3136
3470
|
if (isObservableObject(obj)) {
|
|
3137
3471
|
return obj[$mobx].get_(key);
|
|
@@ -3159,7 +3493,11 @@ function apiOwnKeys(obj) {
|
|
|
3159
3493
|
}
|
|
3160
3494
|
|
|
3161
3495
|
function observe(thing, propOrCb, cbOrFire, fireImmediately) {
|
|
3162
|
-
if (isFunction(cbOrFire))
|
|
3496
|
+
if (isFunction(cbOrFire)) {
|
|
3497
|
+
return observeObservableProperty(thing, propOrCb, cbOrFire, fireImmediately);
|
|
3498
|
+
} else {
|
|
3499
|
+
return observeObservable(thing, propOrCb, cbOrFire);
|
|
3500
|
+
}
|
|
3163
3501
|
}
|
|
3164
3502
|
|
|
3165
3503
|
function observeObservable(thing, listener, fireImmediately) {
|
|
@@ -3176,8 +3514,13 @@ function cache(map, key, value) {
|
|
|
3176
3514
|
}
|
|
3177
3515
|
|
|
3178
3516
|
function toJSHelper(source, __alreadySeen) {
|
|
3179
|
-
if (source == null || typeof source !== "object" || source instanceof Date || !isObservable(source))
|
|
3180
|
-
|
|
3517
|
+
if (source == null || typeof source !== "object" || source instanceof Date || !isObservable(source)) {
|
|
3518
|
+
return source;
|
|
3519
|
+
}
|
|
3520
|
+
|
|
3521
|
+
if (isObservableValue(source) || isComputedValue(source)) {
|
|
3522
|
+
return toJSHelper(source.get(), __alreadySeen);
|
|
3523
|
+
}
|
|
3181
3524
|
|
|
3182
3525
|
if (__alreadySeen.has(source)) {
|
|
3183
3526
|
return __alreadySeen.get(source);
|
|
@@ -3228,18 +3571,25 @@ function toJSHelper(source, __alreadySeen) {
|
|
|
3228
3571
|
|
|
3229
3572
|
|
|
3230
3573
|
function toJS(source, options) {
|
|
3231
|
-
if ( options)
|
|
3574
|
+
if ( options) {
|
|
3575
|
+
die("toJS no longer supports options");
|
|
3576
|
+
}
|
|
3577
|
+
|
|
3232
3578
|
return toJSHelper(source, new Map());
|
|
3233
3579
|
}
|
|
3234
3580
|
|
|
3235
3581
|
function trace() {
|
|
3582
|
+
|
|
3236
3583
|
var enterBreakPoint = false;
|
|
3237
3584
|
|
|
3238
3585
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
3239
3586
|
args[_key] = arguments[_key];
|
|
3240
3587
|
}
|
|
3241
3588
|
|
|
3242
|
-
if (typeof args[args.length - 1] === "boolean")
|
|
3589
|
+
if (typeof args[args.length - 1] === "boolean") {
|
|
3590
|
+
enterBreakPoint = args.pop();
|
|
3591
|
+
}
|
|
3592
|
+
|
|
3243
3593
|
var derivation = getAtomFromArgs(args);
|
|
3244
3594
|
|
|
3245
3595
|
if (!derivation) {
|
|
@@ -3289,7 +3639,10 @@ function transaction(action, thisArg) {
|
|
|
3289
3639
|
}
|
|
3290
3640
|
|
|
3291
3641
|
function when(predicate, arg1, arg2) {
|
|
3292
|
-
if (arguments.length === 1 || arg1 && typeof arg1 === "object")
|
|
3642
|
+
if (arguments.length === 1 || arg1 && typeof arg1 === "object") {
|
|
3643
|
+
return whenPromise(predicate, arg1);
|
|
3644
|
+
}
|
|
3645
|
+
|
|
3293
3646
|
return _when(predicate, arg1, arg2 || {});
|
|
3294
3647
|
}
|
|
3295
3648
|
|
|
@@ -3301,7 +3654,12 @@ function _when(predicate, effect, opts) {
|
|
|
3301
3654
|
timeoutHandle = setTimeout(function () {
|
|
3302
3655
|
if (!disposer[$mobx].isDisposed_) {
|
|
3303
3656
|
disposer();
|
|
3304
|
-
|
|
3657
|
+
|
|
3658
|
+
if (opts.onError) {
|
|
3659
|
+
opts.onError(error);
|
|
3660
|
+
} else {
|
|
3661
|
+
throw error;
|
|
3662
|
+
}
|
|
3305
3663
|
}
|
|
3306
3664
|
}, opts.timeout);
|
|
3307
3665
|
}
|
|
@@ -3315,7 +3673,11 @@ function _when(predicate, effect, opts) {
|
|
|
3315
3673
|
|
|
3316
3674
|
if (cond) {
|
|
3317
3675
|
r.dispose();
|
|
3318
|
-
|
|
3676
|
+
|
|
3677
|
+
if (timeoutHandle) {
|
|
3678
|
+
clearTimeout(timeoutHandle);
|
|
3679
|
+
}
|
|
3680
|
+
|
|
3319
3681
|
effectAction();
|
|
3320
3682
|
}
|
|
3321
3683
|
}, opts);
|
|
@@ -3323,7 +3685,10 @@ function _when(predicate, effect, opts) {
|
|
|
3323
3685
|
}
|
|
3324
3686
|
|
|
3325
3687
|
function whenPromise(predicate, opts) {
|
|
3326
|
-
if ( opts && opts.onError)
|
|
3688
|
+
if ( opts && opts.onError) {
|
|
3689
|
+
return die("the options 'onError' and 'promise' cannot be combined");
|
|
3690
|
+
}
|
|
3691
|
+
|
|
3327
3692
|
var cancel;
|
|
3328
3693
|
var res = new Promise(function (resolve, reject) {
|
|
3329
3694
|
var disposer = _when(predicate, resolve, _extends({}, opts, {
|
|
@@ -3347,7 +3712,10 @@ function getAdm(target) {
|
|
|
3347
3712
|
|
|
3348
3713
|
var objectProxyTraps = {
|
|
3349
3714
|
has: function has(target, name) {
|
|
3350
|
-
if ( globalState.trackingDerivation)
|
|
3715
|
+
if ( globalState.trackingDerivation) {
|
|
3716
|
+
warnAboutProxyRequirement("detect new properties using the 'in' operator. Use 'has' from 'mobx' instead.");
|
|
3717
|
+
}
|
|
3718
|
+
|
|
3351
3719
|
return getAdm(target).has_(name);
|
|
3352
3720
|
},
|
|
3353
3721
|
get: function get(target, name) {
|
|
@@ -3356,7 +3724,9 @@ var objectProxyTraps = {
|
|
|
3356
3724
|
set: function set(target, name, value) {
|
|
3357
3725
|
var _getAdm$set_;
|
|
3358
3726
|
|
|
3359
|
-
if (!isStringish(name))
|
|
3727
|
+
if (!isStringish(name)) {
|
|
3728
|
+
return false;
|
|
3729
|
+
}
|
|
3360
3730
|
|
|
3361
3731
|
if ( !getAdm(target).values_.has(name)) {
|
|
3362
3732
|
warnAboutProxyRequirement("add a new observable property through direct assignment. Use 'set' from 'mobx' instead.");
|
|
@@ -3372,7 +3742,10 @@ var objectProxyTraps = {
|
|
|
3372
3742
|
warnAboutProxyRequirement("delete properties from an observable object. Use 'remove' from 'mobx' instead.");
|
|
3373
3743
|
}
|
|
3374
3744
|
|
|
3375
|
-
if (!isStringish(name))
|
|
3745
|
+
if (!isStringish(name)) {
|
|
3746
|
+
return false;
|
|
3747
|
+
} // null (intercepted) -> true (success)
|
|
3748
|
+
|
|
3376
3749
|
|
|
3377
3750
|
return (_getAdm$delete_ = getAdm(target).delete_(name, true)) != null ? _getAdm$delete_ : true;
|
|
3378
3751
|
},
|
|
@@ -3387,7 +3760,10 @@ var objectProxyTraps = {
|
|
|
3387
3760
|
return (_getAdm$definePropert = getAdm(target).defineProperty_(name, descriptor)) != null ? _getAdm$definePropert : true;
|
|
3388
3761
|
},
|
|
3389
3762
|
ownKeys: function ownKeys(target) {
|
|
3390
|
-
if ( globalState.trackingDerivation)
|
|
3763
|
+
if ( globalState.trackingDerivation) {
|
|
3764
|
+
warnAboutProxyRequirement("iterate keys to detect added / removed properties. Use 'keys' from 'mobx' instead.");
|
|
3765
|
+
}
|
|
3766
|
+
|
|
3391
3767
|
return getAdm(target).ownKeys_();
|
|
3392
3768
|
},
|
|
3393
3769
|
preventExtensions: function preventExtensions(target) {
|
|
@@ -3410,7 +3786,10 @@ function registerInterceptor(interceptable, handler) {
|
|
|
3410
3786
|
interceptors.push(handler);
|
|
3411
3787
|
return once(function () {
|
|
3412
3788
|
var idx = interceptors.indexOf(handler);
|
|
3413
|
-
|
|
3789
|
+
|
|
3790
|
+
if (idx !== -1) {
|
|
3791
|
+
interceptors.splice(idx, 1);
|
|
3792
|
+
}
|
|
3414
3793
|
});
|
|
3415
3794
|
}
|
|
3416
3795
|
function interceptChange(interceptable, change) {
|
|
@@ -3422,8 +3801,14 @@ function interceptChange(interceptable, change) {
|
|
|
3422
3801
|
|
|
3423
3802
|
for (var i = 0, l = interceptors.length; i < l; i++) {
|
|
3424
3803
|
change = interceptors[i](change);
|
|
3425
|
-
|
|
3426
|
-
if (!change)
|
|
3804
|
+
|
|
3805
|
+
if (change && !change.type) {
|
|
3806
|
+
die(14);
|
|
3807
|
+
}
|
|
3808
|
+
|
|
3809
|
+
if (!change) {
|
|
3810
|
+
break;
|
|
3811
|
+
}
|
|
3427
3812
|
}
|
|
3428
3813
|
|
|
3429
3814
|
return change;
|
|
@@ -3440,13 +3825,20 @@ function registerListener(listenable, handler) {
|
|
|
3440
3825
|
listeners.push(handler);
|
|
3441
3826
|
return once(function () {
|
|
3442
3827
|
var idx = listeners.indexOf(handler);
|
|
3443
|
-
|
|
3828
|
+
|
|
3829
|
+
if (idx !== -1) {
|
|
3830
|
+
listeners.splice(idx, 1);
|
|
3831
|
+
}
|
|
3444
3832
|
});
|
|
3445
3833
|
}
|
|
3446
3834
|
function notifyListeners(listenable, change) {
|
|
3447
3835
|
var prevU = untrackedStart();
|
|
3448
3836
|
var listeners = listenable.changeListeners_;
|
|
3449
|
-
|
|
3837
|
+
|
|
3838
|
+
if (!listeners) {
|
|
3839
|
+
return;
|
|
3840
|
+
}
|
|
3841
|
+
|
|
3450
3842
|
listeners = listeners.slice();
|
|
3451
3843
|
|
|
3452
3844
|
for (var i = 0, l = listeners.length; i < l; i++) {
|
|
@@ -3483,8 +3875,13 @@ function makeObservable(target, annotations, options) {
|
|
|
3483
3875
|
var keysSymbol = /*#__PURE__*/Symbol("mobx-keys");
|
|
3484
3876
|
function makeAutoObservable(target, overrides, options) {
|
|
3485
3877
|
{
|
|
3486
|
-
if (!isPlainObject(target) && !isPlainObject(Object.getPrototypeOf(target)))
|
|
3487
|
-
|
|
3878
|
+
if (!isPlainObject(target) && !isPlainObject(Object.getPrototypeOf(target))) {
|
|
3879
|
+
die("'makeAutoObservable' can only be used for classes that don't have a superclass");
|
|
3880
|
+
}
|
|
3881
|
+
|
|
3882
|
+
if (isObservableObject(target)) {
|
|
3883
|
+
die("makeAutoObservable can only be used on objects not already made observable");
|
|
3884
|
+
}
|
|
3488
3885
|
} // Optimization: avoid visiting protos
|
|
3489
3886
|
// Assumes that annotation.make_/.extend_ works the same for plain objects
|
|
3490
3887
|
|
|
@@ -3525,8 +3922,14 @@ var MAX_SPLICE_SIZE = 10000; // See e.g. https://github.com/mobxjs/mobx/issues/8
|
|
|
3525
3922
|
var arrayTraps = {
|
|
3526
3923
|
get: function get(target, name) {
|
|
3527
3924
|
var adm = target[$mobx];
|
|
3528
|
-
|
|
3529
|
-
if (name ===
|
|
3925
|
+
|
|
3926
|
+
if (name === $mobx) {
|
|
3927
|
+
return adm;
|
|
3928
|
+
}
|
|
3929
|
+
|
|
3930
|
+
if (name === "length") {
|
|
3931
|
+
return adm.getArrayLength_();
|
|
3932
|
+
}
|
|
3530
3933
|
|
|
3531
3934
|
if (typeof name === "string" && !isNaN(name)) {
|
|
3532
3935
|
return adm.get_(parseInt(name));
|
|
@@ -3587,12 +3990,18 @@ var ObservableArrayAdministration = /*#__PURE__*/function () {
|
|
|
3587
3990
|
var _proto = ObservableArrayAdministration.prototype;
|
|
3588
3991
|
|
|
3589
3992
|
_proto.dehanceValue_ = function dehanceValue_(value) {
|
|
3590
|
-
if (this.dehancer !== undefined)
|
|
3993
|
+
if (this.dehancer !== undefined) {
|
|
3994
|
+
return this.dehancer(value);
|
|
3995
|
+
}
|
|
3996
|
+
|
|
3591
3997
|
return value;
|
|
3592
3998
|
};
|
|
3593
3999
|
|
|
3594
4000
|
_proto.dehanceValues_ = function dehanceValues_(values) {
|
|
3595
|
-
if (this.dehancer !== undefined && values.length > 0)
|
|
4001
|
+
if (this.dehancer !== undefined && values.length > 0) {
|
|
4002
|
+
return values.map(this.dehancer);
|
|
4003
|
+
}
|
|
4004
|
+
|
|
3596
4005
|
return values;
|
|
3597
4006
|
};
|
|
3598
4007
|
|
|
@@ -3628,9 +4037,15 @@ var ObservableArrayAdministration = /*#__PURE__*/function () {
|
|
|
3628
4037
|
};
|
|
3629
4038
|
|
|
3630
4039
|
_proto.setArrayLength_ = function setArrayLength_(newLength) {
|
|
3631
|
-
if (typeof newLength !== "number" || isNaN(newLength) || newLength < 0)
|
|
4040
|
+
if (typeof newLength !== "number" || isNaN(newLength) || newLength < 0) {
|
|
4041
|
+
die("Out of range: " + newLength);
|
|
4042
|
+
}
|
|
4043
|
+
|
|
3632
4044
|
var currentLength = this.values_.length;
|
|
3633
|
-
|
|
4045
|
+
|
|
4046
|
+
if (newLength === currentLength) {
|
|
4047
|
+
return;
|
|
4048
|
+
} else if (newLength > currentLength) {
|
|
3634
4049
|
var newItems = new Array(newLength - currentLength);
|
|
3635
4050
|
|
|
3636
4051
|
for (var i = 0; i < newLength - currentLength; i++) {
|
|
@@ -3639,13 +4054,21 @@ var ObservableArrayAdministration = /*#__PURE__*/function () {
|
|
|
3639
4054
|
|
|
3640
4055
|
|
|
3641
4056
|
this.spliceWithArray_(currentLength, 0, newItems);
|
|
3642
|
-
} else
|
|
4057
|
+
} else {
|
|
4058
|
+
this.spliceWithArray_(newLength, currentLength - newLength);
|
|
4059
|
+
}
|
|
3643
4060
|
};
|
|
3644
4061
|
|
|
3645
4062
|
_proto.updateArrayLength_ = function updateArrayLength_(oldLength, delta) {
|
|
3646
|
-
if (oldLength !== this.lastKnownLength_)
|
|
4063
|
+
if (oldLength !== this.lastKnownLength_) {
|
|
4064
|
+
die(16);
|
|
4065
|
+
}
|
|
4066
|
+
|
|
3647
4067
|
this.lastKnownLength_ += delta;
|
|
3648
|
-
|
|
4068
|
+
|
|
4069
|
+
if (this.legacyMode_ && delta > 0) {
|
|
4070
|
+
reserveArrayBuffer(oldLength + delta + 1);
|
|
4071
|
+
}
|
|
3649
4072
|
};
|
|
3650
4073
|
|
|
3651
4074
|
_proto.spliceWithArray_ = function spliceWithArray_(index, deleteCount, newItems) {
|
|
@@ -3653,9 +4076,26 @@ var ObservableArrayAdministration = /*#__PURE__*/function () {
|
|
|
3653
4076
|
|
|
3654
4077
|
checkIfStateModificationsAreAllowed(this.atom_);
|
|
3655
4078
|
var length = this.values_.length;
|
|
3656
|
-
|
|
3657
|
-
if (
|
|
3658
|
-
|
|
4079
|
+
|
|
4080
|
+
if (index === undefined) {
|
|
4081
|
+
index = 0;
|
|
4082
|
+
} else if (index > length) {
|
|
4083
|
+
index = length;
|
|
4084
|
+
} else if (index < 0) {
|
|
4085
|
+
index = Math.max(0, length + index);
|
|
4086
|
+
}
|
|
4087
|
+
|
|
4088
|
+
if (arguments.length === 1) {
|
|
4089
|
+
deleteCount = length - index;
|
|
4090
|
+
} else if (deleteCount === undefined || deleteCount === null) {
|
|
4091
|
+
deleteCount = 0;
|
|
4092
|
+
} else {
|
|
4093
|
+
deleteCount = Math.max(0, Math.min(deleteCount, length - index));
|
|
4094
|
+
}
|
|
4095
|
+
|
|
4096
|
+
if (newItems === undefined) {
|
|
4097
|
+
newItems = EMPTY_ARRAY;
|
|
4098
|
+
}
|
|
3659
4099
|
|
|
3660
4100
|
if (hasInterceptors(this)) {
|
|
3661
4101
|
var change = interceptChange(this, {
|
|
@@ -3665,7 +4105,11 @@ var ObservableArrayAdministration = /*#__PURE__*/function () {
|
|
|
3665
4105
|
removedCount: deleteCount,
|
|
3666
4106
|
added: newItems
|
|
3667
4107
|
});
|
|
3668
|
-
|
|
4108
|
+
|
|
4109
|
+
if (!change) {
|
|
4110
|
+
return EMPTY_ARRAY;
|
|
4111
|
+
}
|
|
4112
|
+
|
|
3669
4113
|
deleteCount = change.removedCount;
|
|
3670
4114
|
newItems = change.added;
|
|
3671
4115
|
}
|
|
@@ -3680,7 +4124,11 @@ var ObservableArrayAdministration = /*#__PURE__*/function () {
|
|
|
3680
4124
|
}
|
|
3681
4125
|
|
|
3682
4126
|
var res = this.spliceItemsIntoValues_(index, deleteCount, newItems);
|
|
3683
|
-
|
|
4127
|
+
|
|
4128
|
+
if (deleteCount !== 0 || newItems.length !== 0) {
|
|
4129
|
+
this.notifyArraySplice_(index, newItems, res);
|
|
4130
|
+
}
|
|
4131
|
+
|
|
3684
4132
|
return this.dehanceValues_(res);
|
|
3685
4133
|
};
|
|
3686
4134
|
|
|
@@ -3723,10 +4171,19 @@ var ObservableArrayAdministration = /*#__PURE__*/function () {
|
|
|
3723
4171
|
} : 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
|
|
3724
4172
|
// cause any runtime overhead in development mode without NODE_ENV set, unless spying is enabled
|
|
3725
4173
|
|
|
3726
|
-
if ( notifySpy)
|
|
4174
|
+
if ( notifySpy) {
|
|
4175
|
+
spyReportStart(change);
|
|
4176
|
+
}
|
|
4177
|
+
|
|
3727
4178
|
this.atom_.reportChanged();
|
|
3728
|
-
|
|
3729
|
-
if (
|
|
4179
|
+
|
|
4180
|
+
if (notify) {
|
|
4181
|
+
notifyListeners(this, change);
|
|
4182
|
+
}
|
|
4183
|
+
|
|
4184
|
+
if ( notifySpy) {
|
|
4185
|
+
spyReportEnd();
|
|
4186
|
+
}
|
|
3730
4187
|
};
|
|
3731
4188
|
|
|
3732
4189
|
_proto.notifyArraySplice_ = function notifyArraySplice_(index, added, removed) {
|
|
@@ -3743,11 +4200,20 @@ var ObservableArrayAdministration = /*#__PURE__*/function () {
|
|
|
3743
4200
|
removedCount: removed.length,
|
|
3744
4201
|
addedCount: added.length
|
|
3745
4202
|
} : null;
|
|
3746
|
-
|
|
4203
|
+
|
|
4204
|
+
if ( notifySpy) {
|
|
4205
|
+
spyReportStart(change);
|
|
4206
|
+
}
|
|
4207
|
+
|
|
3747
4208
|
this.atom_.reportChanged(); // conform: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/observe
|
|
3748
4209
|
|
|
3749
|
-
if (notify)
|
|
3750
|
-
|
|
4210
|
+
if (notify) {
|
|
4211
|
+
notifyListeners(this, change);
|
|
4212
|
+
}
|
|
4213
|
+
|
|
4214
|
+
if ( notifySpy) {
|
|
4215
|
+
spyReportEnd();
|
|
4216
|
+
}
|
|
3751
4217
|
};
|
|
3752
4218
|
|
|
3753
4219
|
_proto.get_ = function get_(index) {
|
|
@@ -3774,7 +4240,11 @@ var ObservableArrayAdministration = /*#__PURE__*/function () {
|
|
|
3774
4240
|
index: index,
|
|
3775
4241
|
newValue: newValue
|
|
3776
4242
|
});
|
|
3777
|
-
|
|
4243
|
+
|
|
4244
|
+
if (!change) {
|
|
4245
|
+
return;
|
|
4246
|
+
}
|
|
4247
|
+
|
|
3778
4248
|
newValue = change.newValue;
|
|
3779
4249
|
}
|
|
3780
4250
|
|
|
@@ -4015,6 +4485,8 @@ _Symbol$toStringTag = Symbol.toStringTag;
|
|
|
4015
4485
|
var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTag2) {
|
|
4016
4486
|
// hasMap, not hashMap >-).
|
|
4017
4487
|
function ObservableMap(initialData, enhancer_, name_) {
|
|
4488
|
+
var _this = this;
|
|
4489
|
+
|
|
4018
4490
|
if (enhancer_ === void 0) {
|
|
4019
4491
|
enhancer_ = deepEnhancer;
|
|
4020
4492
|
}
|
|
@@ -4042,7 +4514,9 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4042
4514
|
this.keysAtom_ = createAtom( this.name_ + ".keys()" );
|
|
4043
4515
|
this.data_ = new Map();
|
|
4044
4516
|
this.hasMap_ = new Map();
|
|
4045
|
-
|
|
4517
|
+
allowStateChanges(true, function () {
|
|
4518
|
+
_this.merge(initialData);
|
|
4519
|
+
});
|
|
4046
4520
|
}
|
|
4047
4521
|
|
|
4048
4522
|
var _proto = ObservableMap.prototype;
|
|
@@ -4052,16 +4526,19 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4052
4526
|
};
|
|
4053
4527
|
|
|
4054
4528
|
_proto.has = function has(key) {
|
|
4055
|
-
var
|
|
4529
|
+
var _this2 = this;
|
|
4530
|
+
|
|
4531
|
+
if (!globalState.trackingDerivation) {
|
|
4532
|
+
return this.has_(key);
|
|
4533
|
+
}
|
|
4056
4534
|
|
|
4057
|
-
if (!globalState.trackingDerivation) return this.has_(key);
|
|
4058
4535
|
var entry = this.hasMap_.get(key);
|
|
4059
4536
|
|
|
4060
4537
|
if (!entry) {
|
|
4061
4538
|
var newEntry = entry = new ObservableValue(this.has_(key), referenceEnhancer, this.name_ + "." + stringifyKey(key) + "?" , false);
|
|
4062
4539
|
this.hasMap_.set(key, newEntry);
|
|
4063
4540
|
onBecomeUnobserved(newEntry, function () {
|
|
4064
|
-
return
|
|
4541
|
+
return _this2.hasMap_["delete"](key);
|
|
4065
4542
|
});
|
|
4066
4543
|
}
|
|
4067
4544
|
|
|
@@ -4078,7 +4555,11 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4078
4555
|
newValue: value,
|
|
4079
4556
|
name: key
|
|
4080
4557
|
});
|
|
4081
|
-
|
|
4558
|
+
|
|
4559
|
+
if (!change) {
|
|
4560
|
+
return this;
|
|
4561
|
+
}
|
|
4562
|
+
|
|
4082
4563
|
value = change.newValue;
|
|
4083
4564
|
}
|
|
4084
4565
|
|
|
@@ -4092,7 +4573,7 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4092
4573
|
};
|
|
4093
4574
|
|
|
4094
4575
|
_proto["delete"] = function _delete(key) {
|
|
4095
|
-
var
|
|
4576
|
+
var _this3 = this;
|
|
4096
4577
|
|
|
4097
4578
|
checkIfStateModificationsAreAllowed(this.keysAtom_);
|
|
4098
4579
|
|
|
@@ -4102,7 +4583,10 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4102
4583
|
object: this,
|
|
4103
4584
|
name: key
|
|
4104
4585
|
});
|
|
4105
|
-
|
|
4586
|
+
|
|
4587
|
+
if (!change) {
|
|
4588
|
+
return false;
|
|
4589
|
+
}
|
|
4106
4590
|
}
|
|
4107
4591
|
|
|
4108
4592
|
if (this.has_(key)) {
|
|
@@ -4118,23 +4602,33 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4118
4602
|
name: key
|
|
4119
4603
|
} : null;
|
|
4120
4604
|
|
|
4121
|
-
if ( notifySpy)
|
|
4605
|
+
if ( notifySpy) {
|
|
4606
|
+
spyReportStart(_change);
|
|
4607
|
+
} // TODO fix type
|
|
4608
|
+
|
|
4122
4609
|
|
|
4123
4610
|
transaction(function () {
|
|
4124
|
-
var
|
|
4611
|
+
var _this3$hasMap_$get;
|
|
4125
4612
|
|
|
4126
|
-
|
|
4613
|
+
_this3.keysAtom_.reportChanged();
|
|
4127
4614
|
|
|
4128
|
-
(
|
|
4615
|
+
(_this3$hasMap_$get = _this3.hasMap_.get(key)) == null ? void 0 : _this3$hasMap_$get.setNewValue_(false);
|
|
4129
4616
|
|
|
4130
|
-
var observable =
|
|
4617
|
+
var observable = _this3.data_.get(key);
|
|
4131
4618
|
|
|
4132
4619
|
observable.setNewValue_(undefined);
|
|
4133
4620
|
|
|
4134
|
-
|
|
4621
|
+
_this3.data_["delete"](key);
|
|
4135
4622
|
});
|
|
4136
|
-
|
|
4137
|
-
if (
|
|
4623
|
+
|
|
4624
|
+
if (notify) {
|
|
4625
|
+
notifyListeners(this, _change);
|
|
4626
|
+
}
|
|
4627
|
+
|
|
4628
|
+
if ( notifySpy) {
|
|
4629
|
+
spyReportEnd();
|
|
4630
|
+
}
|
|
4631
|
+
|
|
4138
4632
|
return true;
|
|
4139
4633
|
}
|
|
4140
4634
|
|
|
@@ -4157,30 +4651,40 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4157
4651
|
name: key,
|
|
4158
4652
|
newValue: newValue
|
|
4159
4653
|
} : null;
|
|
4160
|
-
|
|
4654
|
+
|
|
4655
|
+
if ( notifySpy) {
|
|
4656
|
+
spyReportStart(change);
|
|
4657
|
+
} // TODO fix type
|
|
4658
|
+
|
|
4161
4659
|
|
|
4162
4660
|
observable.setNewValue_(newValue);
|
|
4163
|
-
|
|
4164
|
-
if (
|
|
4661
|
+
|
|
4662
|
+
if (notify) {
|
|
4663
|
+
notifyListeners(this, change);
|
|
4664
|
+
}
|
|
4665
|
+
|
|
4666
|
+
if ( notifySpy) {
|
|
4667
|
+
spyReportEnd();
|
|
4668
|
+
}
|
|
4165
4669
|
}
|
|
4166
4670
|
};
|
|
4167
4671
|
|
|
4168
4672
|
_proto.addValue_ = function addValue_(key, newValue) {
|
|
4169
|
-
var
|
|
4673
|
+
var _this4 = this;
|
|
4170
4674
|
|
|
4171
4675
|
checkIfStateModificationsAreAllowed(this.keysAtom_);
|
|
4172
4676
|
transaction(function () {
|
|
4173
|
-
var
|
|
4677
|
+
var _this4$hasMap_$get;
|
|
4174
4678
|
|
|
4175
|
-
var observable = new ObservableValue(newValue,
|
|
4679
|
+
var observable = new ObservableValue(newValue, _this4.enhancer_, _this4.name_ + "." + stringifyKey(key) , false);
|
|
4176
4680
|
|
|
4177
|
-
|
|
4681
|
+
_this4.data_.set(key, observable);
|
|
4178
4682
|
|
|
4179
4683
|
newValue = observable.value_; // value might have been changed
|
|
4180
4684
|
|
|
4181
|
-
(
|
|
4685
|
+
(_this4$hasMap_$get = _this4.hasMap_.get(key)) == null ? void 0 : _this4$hasMap_$get.setNewValue_(true);
|
|
4182
4686
|
|
|
4183
|
-
|
|
4687
|
+
_this4.keysAtom_.reportChanged();
|
|
4184
4688
|
});
|
|
4185
4689
|
var notifySpy = isSpyEnabled();
|
|
4186
4690
|
var notify = hasListeners(this);
|
|
@@ -4192,14 +4696,26 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4192
4696
|
name: key,
|
|
4193
4697
|
newValue: newValue
|
|
4194
4698
|
} : null;
|
|
4195
|
-
if ( notifySpy) spyReportStart(change); // TODO fix type
|
|
4196
4699
|
|
|
4197
|
-
if (
|
|
4198
|
-
|
|
4700
|
+
if ( notifySpy) {
|
|
4701
|
+
spyReportStart(change);
|
|
4702
|
+
} // TODO fix type
|
|
4703
|
+
|
|
4704
|
+
|
|
4705
|
+
if (notify) {
|
|
4706
|
+
notifyListeners(this, change);
|
|
4707
|
+
}
|
|
4708
|
+
|
|
4709
|
+
if ( notifySpy) {
|
|
4710
|
+
spyReportEnd();
|
|
4711
|
+
}
|
|
4199
4712
|
};
|
|
4200
4713
|
|
|
4201
4714
|
_proto.get = function get(key) {
|
|
4202
|
-
if (this.has(key))
|
|
4715
|
+
if (this.has(key)) {
|
|
4716
|
+
return this.dehanceValue_(this.data_.get(key).get());
|
|
4717
|
+
}
|
|
4718
|
+
|
|
4203
4719
|
return this.dehanceValue_(undefined);
|
|
4204
4720
|
};
|
|
4205
4721
|
|
|
@@ -4266,45 +4782,54 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4266
4782
|
;
|
|
4267
4783
|
|
|
4268
4784
|
_proto.merge = function merge(other) {
|
|
4269
|
-
var
|
|
4785
|
+
var _this5 = this;
|
|
4270
4786
|
|
|
4271
4787
|
if (isObservableMap(other)) {
|
|
4272
4788
|
other = new Map(other);
|
|
4273
4789
|
}
|
|
4274
4790
|
|
|
4275
4791
|
transaction(function () {
|
|
4276
|
-
if (isPlainObject(other))
|
|
4277
|
-
|
|
4278
|
-
|
|
4279
|
-
|
|
4280
|
-
|
|
4281
|
-
|
|
4282
|
-
|
|
4283
|
-
|
|
4792
|
+
if (isPlainObject(other)) {
|
|
4793
|
+
getPlainObjectKeys(other).forEach(function (key) {
|
|
4794
|
+
return _this5.set(key, other[key]);
|
|
4795
|
+
});
|
|
4796
|
+
} else if (Array.isArray(other)) {
|
|
4797
|
+
other.forEach(function (_ref) {
|
|
4798
|
+
var key = _ref[0],
|
|
4799
|
+
value = _ref[1];
|
|
4800
|
+
return _this5.set(key, value);
|
|
4801
|
+
});
|
|
4802
|
+
} else if (isES6Map(other)) {
|
|
4803
|
+
if (other.constructor !== Map) {
|
|
4804
|
+
die(19, other);
|
|
4805
|
+
}
|
|
4806
|
+
|
|
4284
4807
|
other.forEach(function (value, key) {
|
|
4285
|
-
return
|
|
4808
|
+
return _this5.set(key, value);
|
|
4286
4809
|
});
|
|
4287
|
-
} else if (other !== null && other !== undefined)
|
|
4810
|
+
} else if (other !== null && other !== undefined) {
|
|
4811
|
+
die(20, other);
|
|
4812
|
+
}
|
|
4288
4813
|
});
|
|
4289
4814
|
return this;
|
|
4290
4815
|
};
|
|
4291
4816
|
|
|
4292
4817
|
_proto.clear = function clear() {
|
|
4293
|
-
var
|
|
4818
|
+
var _this6 = this;
|
|
4294
4819
|
|
|
4295
4820
|
transaction(function () {
|
|
4296
4821
|
untracked(function () {
|
|
4297
|
-
for (var _iterator2 = _createForOfIteratorHelperLoose(
|
|
4822
|
+
for (var _iterator2 = _createForOfIteratorHelperLoose(_this6.keys()), _step2; !(_step2 = _iterator2()).done;) {
|
|
4298
4823
|
var key = _step2.value;
|
|
4299
4824
|
|
|
4300
|
-
|
|
4825
|
+
_this6["delete"](key);
|
|
4301
4826
|
}
|
|
4302
4827
|
});
|
|
4303
4828
|
});
|
|
4304
4829
|
};
|
|
4305
4830
|
|
|
4306
4831
|
_proto.replace = function replace(values) {
|
|
4307
|
-
var
|
|
4832
|
+
var _this7 = this;
|
|
4308
4833
|
|
|
4309
4834
|
// Implementation requirements:
|
|
4310
4835
|
// - respect ordering of replacement map
|
|
@@ -4321,13 +4846,13 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4321
4846
|
// if the key deletion is prevented by interceptor
|
|
4322
4847
|
// add entry at the beginning of the result map
|
|
4323
4848
|
|
|
4324
|
-
for (var _iterator3 = _createForOfIteratorHelperLoose(
|
|
4849
|
+
for (var _iterator3 = _createForOfIteratorHelperLoose(_this7.data_.keys()), _step3; !(_step3 = _iterator3()).done;) {
|
|
4325
4850
|
var key = _step3.value;
|
|
4326
4851
|
|
|
4327
4852
|
// Concurrently iterating/deleting keys
|
|
4328
4853
|
// iterator should handle this correctly
|
|
4329
4854
|
if (!replacementMap.has(key)) {
|
|
4330
|
-
var deleted =
|
|
4855
|
+
var deleted = _this7["delete"](key); // Was the key removed?
|
|
4331
4856
|
|
|
4332
4857
|
|
|
4333
4858
|
if (deleted) {
|
|
@@ -4335,7 +4860,7 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4335
4860
|
keysReportChangedCalled = true;
|
|
4336
4861
|
} else {
|
|
4337
4862
|
// Delete prevented by interceptor
|
|
4338
|
-
var value =
|
|
4863
|
+
var value = _this7.data_.get(key);
|
|
4339
4864
|
|
|
4340
4865
|
orderedData.set(key, value);
|
|
4341
4866
|
}
|
|
@@ -4349,17 +4874,17 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4349
4874
|
_value = _step4$value[1];
|
|
4350
4875
|
|
|
4351
4876
|
// We will want to know whether a new key is added
|
|
4352
|
-
var keyExisted =
|
|
4877
|
+
var keyExisted = _this7.data_.has(_key); // Add or update value
|
|
4353
4878
|
|
|
4354
4879
|
|
|
4355
|
-
|
|
4880
|
+
_this7.set(_key, _value); // The addition could have been prevent by interceptor
|
|
4356
4881
|
|
|
4357
4882
|
|
|
4358
|
-
if (
|
|
4883
|
+
if (_this7.data_.has(_key)) {
|
|
4359
4884
|
// The update could have been prevented by interceptor
|
|
4360
4885
|
// and also we want to preserve existing values
|
|
4361
4886
|
// so use value from _data map (instead of replacement map)
|
|
4362
|
-
var _value2 =
|
|
4887
|
+
var _value2 = _this7.data_.get(_key);
|
|
4363
4888
|
|
|
4364
4889
|
orderedData.set(_key, _value2); // Was a new key added?
|
|
4365
4890
|
|
|
@@ -4372,11 +4897,11 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4372
4897
|
|
|
4373
4898
|
|
|
4374
4899
|
if (!keysReportChangedCalled) {
|
|
4375
|
-
if (
|
|
4900
|
+
if (_this7.data_.size !== orderedData.size) {
|
|
4376
4901
|
// If size differs, keys are definitely modified
|
|
4377
|
-
|
|
4902
|
+
_this7.keysAtom_.reportChanged();
|
|
4378
4903
|
} else {
|
|
4379
|
-
var iter1 =
|
|
4904
|
+
var iter1 = _this7.data_.keys();
|
|
4380
4905
|
|
|
4381
4906
|
var iter2 = orderedData.keys();
|
|
4382
4907
|
var next1 = iter1.next();
|
|
@@ -4384,7 +4909,7 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4384
4909
|
|
|
4385
4910
|
while (!next1.done) {
|
|
4386
4911
|
if (next1.value !== next2.value) {
|
|
4387
|
-
|
|
4912
|
+
_this7.keysAtom_.reportChanged();
|
|
4388
4913
|
|
|
4389
4914
|
break;
|
|
4390
4915
|
}
|
|
@@ -4396,7 +4921,7 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4396
4921
|
} // Use correctly ordered map
|
|
4397
4922
|
|
|
4398
4923
|
|
|
4399
|
-
|
|
4924
|
+
_this7.data_ = orderedData;
|
|
4400
4925
|
});
|
|
4401
4926
|
return this;
|
|
4402
4927
|
};
|
|
@@ -4415,7 +4940,10 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4415
4940
|
* for callback details
|
|
4416
4941
|
*/
|
|
4417
4942
|
_proto.observe_ = function observe_(listener, fireImmediately) {
|
|
4418
|
-
if ( fireImmediately === true)
|
|
4943
|
+
if ( fireImmediately === true) {
|
|
4944
|
+
die("`observe` doesn't support fireImmediately=true in combination with maps.");
|
|
4945
|
+
}
|
|
4946
|
+
|
|
4419
4947
|
return registerListener(this, listener);
|
|
4420
4948
|
};
|
|
4421
4949
|
|
|
@@ -4540,8 +5068,12 @@ var ObservableSet = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4540
5068
|
object: this,
|
|
4541
5069
|
newValue: value
|
|
4542
5070
|
});
|
|
4543
|
-
|
|
5071
|
+
|
|
5072
|
+
if (!change) {
|
|
5073
|
+
return this;
|
|
5074
|
+
} // ideally, value = change.value would be done here, so that values can be
|
|
4544
5075
|
// changed by interceptor. Same applies for other Set and Map api's.
|
|
5076
|
+
|
|
4545
5077
|
}
|
|
4546
5078
|
|
|
4547
5079
|
if (!this.has(value)) {
|
|
@@ -4561,9 +5093,17 @@ var ObservableSet = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4561
5093
|
newValue: value
|
|
4562
5094
|
} : null;
|
|
4563
5095
|
|
|
4564
|
-
if (notifySpy && "development" !== "production")
|
|
4565
|
-
|
|
4566
|
-
|
|
5096
|
+
if (notifySpy && "development" !== "production") {
|
|
5097
|
+
spyReportStart(_change);
|
|
5098
|
+
}
|
|
5099
|
+
|
|
5100
|
+
if (notify) {
|
|
5101
|
+
notifyListeners(this, _change);
|
|
5102
|
+
}
|
|
5103
|
+
|
|
5104
|
+
if (notifySpy && "development" !== "production") {
|
|
5105
|
+
spyReportEnd();
|
|
5106
|
+
}
|
|
4567
5107
|
}
|
|
4568
5108
|
|
|
4569
5109
|
return this;
|
|
@@ -4578,7 +5118,10 @@ var ObservableSet = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4578
5118
|
object: this,
|
|
4579
5119
|
oldValue: value
|
|
4580
5120
|
});
|
|
4581
|
-
|
|
5121
|
+
|
|
5122
|
+
if (!change) {
|
|
5123
|
+
return false;
|
|
5124
|
+
}
|
|
4582
5125
|
}
|
|
4583
5126
|
|
|
4584
5127
|
if (this.has(value)) {
|
|
@@ -4593,14 +5136,24 @@ var ObservableSet = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4593
5136
|
oldValue: value
|
|
4594
5137
|
} : null;
|
|
4595
5138
|
|
|
4596
|
-
if (notifySpy && "development" !== "production")
|
|
5139
|
+
if (notifySpy && "development" !== "production") {
|
|
5140
|
+
spyReportStart(_change2);
|
|
5141
|
+
}
|
|
5142
|
+
|
|
4597
5143
|
transaction(function () {
|
|
4598
5144
|
_this3.atom_.reportChanged();
|
|
4599
5145
|
|
|
4600
5146
|
_this3.data_["delete"](value);
|
|
4601
5147
|
});
|
|
4602
|
-
|
|
4603
|
-
if (
|
|
5148
|
+
|
|
5149
|
+
if (notify) {
|
|
5150
|
+
notifyListeners(this, _change2);
|
|
5151
|
+
}
|
|
5152
|
+
|
|
5153
|
+
if (notifySpy && "development" !== "production") {
|
|
5154
|
+
spyReportEnd();
|
|
5155
|
+
}
|
|
5156
|
+
|
|
4604
5157
|
return true;
|
|
4605
5158
|
}
|
|
4606
5159
|
|
|
@@ -4680,7 +5233,10 @@ var ObservableSet = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4680
5233
|
|
|
4681
5234
|
_proto.observe_ = function observe_(listener, fireImmediately) {
|
|
4682
5235
|
// ... 'fireImmediately' could also be true?
|
|
4683
|
-
if ( fireImmediately === true)
|
|
5236
|
+
if ( fireImmediately === true) {
|
|
5237
|
+
die("`observe` doesn't support fireImmediately=true in combination with sets.");
|
|
5238
|
+
}
|
|
5239
|
+
|
|
4684
5240
|
return registerListener(this, listener);
|
|
4685
5241
|
};
|
|
4686
5242
|
|
|
@@ -4782,7 +5338,11 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
4782
5338
|
name: key,
|
|
4783
5339
|
newValue: newValue
|
|
4784
5340
|
});
|
|
4785
|
-
|
|
5341
|
+
|
|
5342
|
+
if (!change) {
|
|
5343
|
+
return null;
|
|
5344
|
+
}
|
|
5345
|
+
|
|
4786
5346
|
newValue = change.newValue;
|
|
4787
5347
|
}
|
|
4788
5348
|
|
|
@@ -4802,10 +5362,18 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
4802
5362
|
newValue: newValue
|
|
4803
5363
|
} : null;
|
|
4804
5364
|
|
|
4805
|
-
if ( notifySpy)
|
|
5365
|
+
if ( notifySpy) {
|
|
5366
|
+
spyReportStart(_change);
|
|
5367
|
+
}
|
|
4806
5368
|
observable.setNewValue_(newValue);
|
|
4807
|
-
|
|
4808
|
-
if (
|
|
5369
|
+
|
|
5370
|
+
if (notify) {
|
|
5371
|
+
notifyListeners(this, _change);
|
|
5372
|
+
}
|
|
5373
|
+
|
|
5374
|
+
if ( notifySpy) {
|
|
5375
|
+
spyReportEnd();
|
|
5376
|
+
}
|
|
4809
5377
|
}
|
|
4810
5378
|
|
|
4811
5379
|
return true;
|
|
@@ -4914,12 +5482,18 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
4914
5482
|
|
|
4915
5483
|
if (descriptor) {
|
|
4916
5484
|
var outcome = annotation.make_(this, key, descriptor, source);
|
|
5485
|
+
|
|
4917
5486
|
if (outcome === 0
|
|
4918
5487
|
/* Cancel */
|
|
4919
|
-
)
|
|
5488
|
+
) {
|
|
5489
|
+
return;
|
|
5490
|
+
}
|
|
5491
|
+
|
|
4920
5492
|
if (outcome === 1
|
|
4921
5493
|
/* Break */
|
|
4922
|
-
)
|
|
5494
|
+
) {
|
|
5495
|
+
break;
|
|
5496
|
+
}
|
|
4923
5497
|
}
|
|
4924
5498
|
|
|
4925
5499
|
source = Object.getPrototypeOf(source);
|
|
@@ -4989,7 +5563,11 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
4989
5563
|
type: ADD,
|
|
4990
5564
|
newValue: descriptor.value
|
|
4991
5565
|
});
|
|
4992
|
-
|
|
5566
|
+
|
|
5567
|
+
if (!change) {
|
|
5568
|
+
return null;
|
|
5569
|
+
}
|
|
5570
|
+
|
|
4993
5571
|
var newValue = change.newValue;
|
|
4994
5572
|
|
|
4995
5573
|
if (descriptor.value !== newValue) {
|
|
@@ -5041,7 +5619,11 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
5041
5619
|
type: ADD,
|
|
5042
5620
|
newValue: value
|
|
5043
5621
|
});
|
|
5044
|
-
|
|
5622
|
+
|
|
5623
|
+
if (!change) {
|
|
5624
|
+
return null;
|
|
5625
|
+
}
|
|
5626
|
+
|
|
5045
5627
|
value = change.newValue;
|
|
5046
5628
|
}
|
|
5047
5629
|
|
|
@@ -5096,7 +5678,10 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
5096
5678
|
type: ADD,
|
|
5097
5679
|
newValue: undefined
|
|
5098
5680
|
});
|
|
5099
|
-
|
|
5681
|
+
|
|
5682
|
+
if (!change) {
|
|
5683
|
+
return null;
|
|
5684
|
+
}
|
|
5100
5685
|
}
|
|
5101
5686
|
|
|
5102
5687
|
options.name || (options.name = "development" !== "production" ? this.name_ + "." + key.toString() : "ObservableObject.key");
|
|
@@ -5152,7 +5737,9 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
5152
5737
|
type: REMOVE
|
|
5153
5738
|
}); // Cancelled
|
|
5154
5739
|
|
|
5155
|
-
if (!change)
|
|
5740
|
+
if (!change) {
|
|
5741
|
+
return null;
|
|
5742
|
+
}
|
|
5156
5743
|
} // Delete
|
|
5157
5744
|
|
|
5158
5745
|
|
|
@@ -5213,9 +5800,18 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
5213
5800
|
oldValue: value,
|
|
5214
5801
|
name: key
|
|
5215
5802
|
};
|
|
5216
|
-
|
|
5217
|
-
if (
|
|
5218
|
-
|
|
5803
|
+
|
|
5804
|
+
if ("development" !== "production" && notifySpy) {
|
|
5805
|
+
spyReportStart(_change2);
|
|
5806
|
+
}
|
|
5807
|
+
|
|
5808
|
+
if (notify) {
|
|
5809
|
+
notifyListeners(this, _change2);
|
|
5810
|
+
}
|
|
5811
|
+
|
|
5812
|
+
if ("development" !== "production" && notifySpy) {
|
|
5813
|
+
spyReportEnd();
|
|
5814
|
+
}
|
|
5219
5815
|
}
|
|
5220
5816
|
} finally {
|
|
5221
5817
|
endBatch();
|
|
@@ -5231,7 +5827,10 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
5231
5827
|
;
|
|
5232
5828
|
|
|
5233
5829
|
_proto.observe_ = function observe_(callback, fireImmediately) {
|
|
5234
|
-
if ( fireImmediately === true)
|
|
5830
|
+
if ( fireImmediately === true) {
|
|
5831
|
+
die("`observe` doesn't support the fire immediately property for observable objects.");
|
|
5832
|
+
}
|
|
5833
|
+
|
|
5235
5834
|
return registerListener(this, callback);
|
|
5236
5835
|
};
|
|
5237
5836
|
|
|
@@ -5254,9 +5853,18 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
5254
5853
|
name: key,
|
|
5255
5854
|
newValue: value
|
|
5256
5855
|
} : null;
|
|
5257
|
-
|
|
5258
|
-
if (
|
|
5259
|
-
|
|
5856
|
+
|
|
5857
|
+
if ( notifySpy) {
|
|
5858
|
+
spyReportStart(change);
|
|
5859
|
+
}
|
|
5860
|
+
|
|
5861
|
+
if (notify) {
|
|
5862
|
+
notifyListeners(this, change);
|
|
5863
|
+
}
|
|
5864
|
+
|
|
5865
|
+
if ( notifySpy) {
|
|
5866
|
+
spyReportEnd();
|
|
5867
|
+
}
|
|
5260
5868
|
}
|
|
5261
5869
|
|
|
5262
5870
|
(_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
|
|
@@ -5297,7 +5905,10 @@ function asObservableObject(target, options) {
|
|
|
5297
5905
|
return target;
|
|
5298
5906
|
}
|
|
5299
5907
|
|
|
5300
|
-
if ( !Object.isExtensible(target))
|
|
5908
|
+
if ( !Object.isExtensible(target)) {
|
|
5909
|
+
die("Cannot make the designated object observable; it is not extensible");
|
|
5910
|
+
}
|
|
5911
|
+
|
|
5301
5912
|
var name = (_options$name = options == null ? void 0 : options.name) != null ? _options$name : (isPlainObject(target) ? "ObservableObject" : target.constructor.name) + "@" + getNextId() ;
|
|
5302
5913
|
var adm = new ObservableObjectAdministration(target, new Map(), String(name), getAnnotationFromOptions(options));
|
|
5303
5914
|
addHiddenProp(target, $mobx, adm);
|
|
@@ -5454,7 +6065,6 @@ var LegacyObservableArray = /*#__PURE__*/function (_StubArray, _Symbol$toStringT
|
|
|
5454
6065
|
var nextIndex = 0;
|
|
5455
6066
|
return makeIterable({
|
|
5456
6067
|
next: function next() {
|
|
5457
|
-
// @ts-ignore
|
|
5458
6068
|
return nextIndex < self.length ? {
|
|
5459
6069
|
value: self[nextIndex++],
|
|
5460
6070
|
done: false
|
|
@@ -5487,7 +6097,10 @@ var LegacyObservableArray = /*#__PURE__*/function (_StubArray, _Symbol$toStringT
|
|
|
5487
6097
|
Object.entries(arrayExtensions).forEach(function (_ref) {
|
|
5488
6098
|
var prop = _ref[0],
|
|
5489
6099
|
fn = _ref[1];
|
|
5490
|
-
|
|
6100
|
+
|
|
6101
|
+
if (prop !== "concat") {
|
|
6102
|
+
addHiddenProp(LegacyObservableArray.prototype, prop, fn);
|
|
6103
|
+
}
|
|
5491
6104
|
});
|
|
5492
6105
|
|
|
5493
6106
|
function createArrayEntryDescriptor(index) {
|
|
@@ -5524,7 +6137,10 @@ function createLegacyArray(initialValues, enhancer, name) {
|
|
|
5524
6137
|
function getAtom(thing, property) {
|
|
5525
6138
|
if (typeof thing === "object" && thing !== null) {
|
|
5526
6139
|
if (isObservableArray(thing)) {
|
|
5527
|
-
if (property !== undefined)
|
|
6140
|
+
if (property !== undefined) {
|
|
6141
|
+
die(23);
|
|
6142
|
+
}
|
|
6143
|
+
|
|
5528
6144
|
return thing[$mobx].atom_;
|
|
5529
6145
|
}
|
|
5530
6146
|
|
|
@@ -5533,18 +6149,31 @@ function getAtom(thing, property) {
|
|
|
5533
6149
|
}
|
|
5534
6150
|
|
|
5535
6151
|
if (isObservableMap(thing)) {
|
|
5536
|
-
if (property === undefined)
|
|
6152
|
+
if (property === undefined) {
|
|
6153
|
+
return thing.keysAtom_;
|
|
6154
|
+
}
|
|
6155
|
+
|
|
5537
6156
|
var observable = thing.data_.get(property) || thing.hasMap_.get(property);
|
|
5538
|
-
|
|
6157
|
+
|
|
6158
|
+
if (!observable) {
|
|
6159
|
+
die(25, property, getDebugName(thing));
|
|
6160
|
+
}
|
|
6161
|
+
|
|
5539
6162
|
return observable;
|
|
5540
6163
|
}
|
|
5541
6164
|
|
|
6165
|
+
|
|
5542
6166
|
if (isObservableObject(thing)) {
|
|
5543
|
-
if (!property)
|
|
6167
|
+
if (!property) {
|
|
6168
|
+
return die(26);
|
|
6169
|
+
}
|
|
5544
6170
|
|
|
5545
6171
|
var _observable = thing[$mobx].values_.get(property);
|
|
5546
6172
|
|
|
5547
|
-
if (!_observable)
|
|
6173
|
+
if (!_observable) {
|
|
6174
|
+
die(27, property, getDebugName(thing));
|
|
6175
|
+
}
|
|
6176
|
+
|
|
5548
6177
|
return _observable;
|
|
5549
6178
|
}
|
|
5550
6179
|
|
|
@@ -5561,11 +6190,26 @@ function getAtom(thing, property) {
|
|
|
5561
6190
|
die(28);
|
|
5562
6191
|
}
|
|
5563
6192
|
function getAdministration(thing, property) {
|
|
5564
|
-
if (!thing)
|
|
5565
|
-
|
|
5566
|
-
|
|
5567
|
-
|
|
5568
|
-
if (
|
|
6193
|
+
if (!thing) {
|
|
6194
|
+
die(29);
|
|
6195
|
+
}
|
|
6196
|
+
|
|
6197
|
+
if (property !== undefined) {
|
|
6198
|
+
return getAdministration(getAtom(thing, property));
|
|
6199
|
+
}
|
|
6200
|
+
|
|
6201
|
+
if (isAtom(thing) || isComputedValue(thing) || isReaction(thing)) {
|
|
6202
|
+
return thing;
|
|
6203
|
+
}
|
|
6204
|
+
|
|
6205
|
+
if (isObservableMap(thing) || isObservableSet(thing)) {
|
|
6206
|
+
return thing;
|
|
6207
|
+
}
|
|
6208
|
+
|
|
6209
|
+
if (thing[$mobx]) {
|
|
6210
|
+
return thing[$mobx];
|
|
6211
|
+
}
|
|
6212
|
+
|
|
5569
6213
|
die(24, thing);
|
|
5570
6214
|
}
|
|
5571
6215
|
function getDebugName(thing, property) {
|
|
@@ -5598,17 +6242,33 @@ function deepEqual(a, b, depth) {
|
|
|
5598
6242
|
function eq(a, b, depth, aStack, bStack) {
|
|
5599
6243
|
// Identical objects are equal. `0 === -0`, but they aren't identical.
|
|
5600
6244
|
// See the [Harmony `egal` proposal](http://wiki.ecmascript.org/doku.php?id=harmony:egal).
|
|
5601
|
-
if (a === b)
|
|
6245
|
+
if (a === b) {
|
|
6246
|
+
return a !== 0 || 1 / a === 1 / b;
|
|
6247
|
+
} // `null` or `undefined` only equal to itself (strict comparison).
|
|
5602
6248
|
|
|
5603
|
-
if (a == null || b == null) return false; // `NaN`s are equivalent, but non-reflexive.
|
|
5604
6249
|
|
|
5605
|
-
if (a
|
|
6250
|
+
if (a == null || b == null) {
|
|
6251
|
+
return false;
|
|
6252
|
+
} // `NaN`s are equivalent, but non-reflexive.
|
|
6253
|
+
|
|
6254
|
+
|
|
6255
|
+
if (a !== a) {
|
|
6256
|
+
return b !== b;
|
|
6257
|
+
} // Exhaust primitive checks
|
|
6258
|
+
|
|
5606
6259
|
|
|
5607
6260
|
var type = typeof a;
|
|
5608
|
-
|
|
6261
|
+
|
|
6262
|
+
if (type !== "function" && type !== "object" && typeof b != "object") {
|
|
6263
|
+
return false;
|
|
6264
|
+
} // Compare `[[Class]]` names.
|
|
6265
|
+
|
|
5609
6266
|
|
|
5610
6267
|
var className = toString.call(a);
|
|
5611
|
-
|
|
6268
|
+
|
|
6269
|
+
if (className !== toString.call(b)) {
|
|
6270
|
+
return false;
|
|
6271
|
+
}
|
|
5612
6272
|
|
|
5613
6273
|
switch (className) {
|
|
5614
6274
|
// Strings, numbers, regular expressions, dates, and booleans are compared by value.
|
|
@@ -5622,7 +6282,10 @@ function eq(a, b, depth, aStack, bStack) {
|
|
|
5622
6282
|
case "[object Number]":
|
|
5623
6283
|
// `NaN`s are equivalent, but non-reflexive.
|
|
5624
6284
|
// Object(NaN) is equivalent to NaN.
|
|
5625
|
-
if (+a !== +a)
|
|
6285
|
+
if (+a !== +a) {
|
|
6286
|
+
return +b !== +b;
|
|
6287
|
+
} // An `egal` comparison is performed for other numeric values.
|
|
6288
|
+
|
|
5626
6289
|
|
|
5627
6290
|
return +a === 0 ? 1 / +a === 1 / b : +a === +b;
|
|
5628
6291
|
|
|
@@ -5653,9 +6316,12 @@ function eq(a, b, depth, aStack, bStack) {
|
|
|
5653
6316
|
var areArrays = className === "[object Array]";
|
|
5654
6317
|
|
|
5655
6318
|
if (!areArrays) {
|
|
5656
|
-
if (typeof a != "object" || typeof b != "object")
|
|
6319
|
+
if (typeof a != "object" || typeof b != "object") {
|
|
6320
|
+
return false;
|
|
6321
|
+
} // Objects with different constructors are not equivalent, but `Object`s or `Array`s
|
|
5657
6322
|
// from different frames are.
|
|
5658
6323
|
|
|
6324
|
+
|
|
5659
6325
|
var aCtor = a.constructor,
|
|
5660
6326
|
bCtor = b.constructor;
|
|
5661
6327
|
|
|
@@ -5681,7 +6347,9 @@ function eq(a, b, depth, aStack, bStack) {
|
|
|
5681
6347
|
while (length--) {
|
|
5682
6348
|
// Linear search. Performance is inversely proportional to the number of
|
|
5683
6349
|
// unique nested structures.
|
|
5684
|
-
if (aStack[length] === a)
|
|
6350
|
+
if (aStack[length] === a) {
|
|
6351
|
+
return bStack[length] === b;
|
|
6352
|
+
}
|
|
5685
6353
|
} // Add the first object to the stack of traversed objects.
|
|
5686
6354
|
|
|
5687
6355
|
|
|
@@ -5691,10 +6359,16 @@ function eq(a, b, depth, aStack, bStack) {
|
|
|
5691
6359
|
if (areArrays) {
|
|
5692
6360
|
// Compare array lengths to determine if a deep comparison is necessary.
|
|
5693
6361
|
length = a.length;
|
|
5694
|
-
|
|
6362
|
+
|
|
6363
|
+
if (length !== b.length) {
|
|
6364
|
+
return false;
|
|
6365
|
+
} // Deep compare the contents, ignoring non-numeric properties.
|
|
6366
|
+
|
|
5695
6367
|
|
|
5696
6368
|
while (length--) {
|
|
5697
|
-
if (!eq(a[length], b[length], depth - 1, aStack, bStack))
|
|
6369
|
+
if (!eq(a[length], b[length], depth - 1, aStack, bStack)) {
|
|
6370
|
+
return false;
|
|
6371
|
+
}
|
|
5698
6372
|
}
|
|
5699
6373
|
} else {
|
|
5700
6374
|
// Deep compare objects.
|
|
@@ -5702,12 +6376,17 @@ function eq(a, b, depth, aStack, bStack) {
|
|
|
5702
6376
|
var key;
|
|
5703
6377
|
length = keys.length; // Ensure that both objects contain the same number of properties before comparing deep equality.
|
|
5704
6378
|
|
|
5705
|
-
if (Object.keys(b).length !== length)
|
|
6379
|
+
if (Object.keys(b).length !== length) {
|
|
6380
|
+
return false;
|
|
6381
|
+
}
|
|
5706
6382
|
|
|
5707
6383
|
while (length--) {
|
|
5708
6384
|
// Deep compare each member
|
|
5709
6385
|
key = keys[length];
|
|
5710
|
-
|
|
6386
|
+
|
|
6387
|
+
if (!(hasProp(b, key) && eq(a[key], b[key], depth - 1, aStack, bStack))) {
|
|
6388
|
+
return false;
|
|
6389
|
+
}
|
|
5711
6390
|
}
|
|
5712
6391
|
} // Remove the first object from the stack of traversed objects.
|
|
5713
6392
|
|
|
@@ -5718,9 +6397,18 @@ function eq(a, b, depth, aStack, bStack) {
|
|
|
5718
6397
|
}
|
|
5719
6398
|
|
|
5720
6399
|
function unwrap(a) {
|
|
5721
|
-
if (isObservableArray(a))
|
|
5722
|
-
|
|
5723
|
-
|
|
6400
|
+
if (isObservableArray(a)) {
|
|
6401
|
+
return a.slice();
|
|
6402
|
+
}
|
|
6403
|
+
|
|
6404
|
+
if (isES6Map(a) || isObservableMap(a)) {
|
|
6405
|
+
return Array.from(a.entries());
|
|
6406
|
+
}
|
|
6407
|
+
|
|
6408
|
+
if (isES6Set(a) || isObservableSet(a)) {
|
|
6409
|
+
return Array.from(a.entries());
|
|
6410
|
+
}
|
|
6411
|
+
|
|
5724
6412
|
return a;
|
|
5725
6413
|
}
|
|
5726
6414
|
|