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