mobx 6.3.13 → 6.4.2
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 +22 -0
- package/README.md +1 -0
- package/dist/api/intercept.d.ts +1 -1
- package/dist/api/observe.d.ts +1 -1
- package/dist/core/reaction.d.ts +2 -2
- package/dist/errors.d.ts +2 -2
- package/dist/mobx.cjs.development.js +941 -268
- 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 +941 -268
- package/dist/mobx.esm.development.js.map +1 -1
- package/dist/mobx.esm.js +960 -275
- 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 +941 -268
- 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 +30 -10
- package/src/core/globalstate.ts +18 -7
- package/src/core/observable.ts +14 -5
- package/src/core/reaction.ts +16 -7
- 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 +3 -1
- 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 +60 -24
- 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
|
|
|
@@ -738,9 +811,11 @@
|
|
|
738
811
|
|
|
739
812
|
|
|
740
813
|
if ((_this$options_ = this.options_) != null && _this$options_.bound && (!hasProp(adm.target_, key) || !isFlow(adm.target_[key]))) {
|
|
741
|
-
if (this.extend_(adm, key, descriptor, false) === null)
|
|
742
|
-
|
|
743
|
-
|
|
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)) {
|
|
@@ -1031,17 +1106,35 @@
|
|
|
1031
1106
|
} // already observable - ignore
|
|
1032
1107
|
|
|
1033
1108
|
|
|
1034
|
-
if (isObservable(v))
|
|
1109
|
+
if (isObservable(v)) {
|
|
1110
|
+
return v;
|
|
1111
|
+
} // plain object
|
|
1112
|
+
|
|
1113
|
+
|
|
1114
|
+
if (isPlainObject(v)) {
|
|
1115
|
+
return observable.object(v, arg2, arg3);
|
|
1116
|
+
} // Array
|
|
1117
|
+
|
|
1118
|
+
|
|
1119
|
+
if (Array.isArray(v)) {
|
|
1120
|
+
return observable.array(v, arg2);
|
|
1121
|
+
} // Map
|
|
1122
|
+
|
|
1035
1123
|
|
|
1036
|
-
if (
|
|
1124
|
+
if (isES6Map(v)) {
|
|
1125
|
+
return observable.map(v, arg2);
|
|
1126
|
+
} // Set
|
|
1037
1127
|
|
|
1038
|
-
if (Array.isArray(v)) return observable.array(v, arg2); // Map
|
|
1039
1128
|
|
|
1040
|
-
if (
|
|
1129
|
+
if (isES6Set(v)) {
|
|
1130
|
+
return observable.set(v, arg2);
|
|
1131
|
+
} // other object - ignore
|
|
1041
1132
|
|
|
1042
|
-
if (isES6Set(v)) return observable.set(v, arg2); // other object - ignore
|
|
1043
1133
|
|
|
1044
|
-
if (typeof v === "object" && v !== null)
|
|
1134
|
+
if (typeof v === "object" && v !== null) {
|
|
1135
|
+
return v;
|
|
1136
|
+
} // anything else
|
|
1137
|
+
|
|
1045
1138
|
|
|
1046
1139
|
return observable.box(v, arg2);
|
|
1047
1140
|
}
|
|
@@ -1099,8 +1192,13 @@
|
|
|
1099
1192
|
|
|
1100
1193
|
|
|
1101
1194
|
{
|
|
1102
|
-
if (!isFunction(arg1))
|
|
1103
|
-
|
|
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
|
+
}
|
|
1104
1202
|
}
|
|
1105
1203
|
|
|
1106
1204
|
var opts = isPlainObject(arg2) ? arg2 : {};
|
|
@@ -1132,8 +1230,13 @@
|
|
|
1132
1230
|
}
|
|
1133
1231
|
|
|
1134
1232
|
{
|
|
1135
|
-
if (!isFunction(fn))
|
|
1136
|
-
|
|
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
|
+
}
|
|
1137
1240
|
}
|
|
1138
1241
|
|
|
1139
1242
|
function res() {
|
|
@@ -1215,7 +1318,10 @@
|
|
|
1215
1318
|
allowStateChangesEnd(runInfo.prevAllowStateChanges_);
|
|
1216
1319
|
allowStateReadsEnd(runInfo.prevAllowStateReads_);
|
|
1217
1320
|
endBatch();
|
|
1218
|
-
|
|
1321
|
+
|
|
1322
|
+
if (runInfo.runAsAction_) {
|
|
1323
|
+
untrackedEnd(runInfo.prevDerivation_);
|
|
1324
|
+
}
|
|
1219
1325
|
|
|
1220
1326
|
if ( runInfo.notifySpy_) {
|
|
1221
1327
|
spyReportEnd({
|
|
@@ -1295,7 +1401,10 @@
|
|
|
1295
1401
|
var _proto = ObservableValue.prototype;
|
|
1296
1402
|
|
|
1297
1403
|
_proto.dehanceValue = function dehanceValue(value) {
|
|
1298
|
-
if (this.dehancer !== undefined)
|
|
1404
|
+
if (this.dehancer !== undefined) {
|
|
1405
|
+
return this.dehancer(value);
|
|
1406
|
+
}
|
|
1407
|
+
|
|
1299
1408
|
return value;
|
|
1300
1409
|
};
|
|
1301
1410
|
|
|
@@ -1318,7 +1427,10 @@
|
|
|
1318
1427
|
}
|
|
1319
1428
|
|
|
1320
1429
|
this.setNewValue_(newValue);
|
|
1321
|
-
|
|
1430
|
+
|
|
1431
|
+
if ( notifySpy) {
|
|
1432
|
+
spyReportEnd();
|
|
1433
|
+
}
|
|
1322
1434
|
}
|
|
1323
1435
|
};
|
|
1324
1436
|
|
|
@@ -1331,7 +1443,11 @@
|
|
|
1331
1443
|
type: UPDATE,
|
|
1332
1444
|
newValue: newValue
|
|
1333
1445
|
});
|
|
1334
|
-
|
|
1446
|
+
|
|
1447
|
+
if (!change) {
|
|
1448
|
+
return globalState.UNCHANGED;
|
|
1449
|
+
}
|
|
1450
|
+
|
|
1335
1451
|
newValue = change.newValue;
|
|
1336
1452
|
} // apply modifier
|
|
1337
1453
|
|
|
@@ -1365,14 +1481,17 @@
|
|
|
1365
1481
|
};
|
|
1366
1482
|
|
|
1367
1483
|
_proto.observe_ = function observe_(listener, fireImmediately) {
|
|
1368
|
-
if (fireImmediately)
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
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
|
+
|
|
1376
1495
|
return registerListener(this, listener);
|
|
1377
1496
|
};
|
|
1378
1497
|
|
|
@@ -1467,7 +1586,11 @@
|
|
|
1467
1586
|
this.keepAlive_ = void 0;
|
|
1468
1587
|
this.onBOL = void 0;
|
|
1469
1588
|
this.onBUOL = void 0;
|
|
1470
|
-
|
|
1589
|
+
|
|
1590
|
+
if (!options.get) {
|
|
1591
|
+
die(31);
|
|
1592
|
+
}
|
|
1593
|
+
|
|
1471
1594
|
this.derivation = options.get;
|
|
1472
1595
|
this.name_ = options.name || ( "ComputedValue@" + getNextId() );
|
|
1473
1596
|
|
|
@@ -1509,7 +1632,9 @@
|
|
|
1509
1632
|
;
|
|
1510
1633
|
|
|
1511
1634
|
_proto.get = function get() {
|
|
1512
|
-
if (this.isComputing_)
|
|
1635
|
+
if (this.isComputing_) {
|
|
1636
|
+
die(32, this.name_, this.derivation);
|
|
1637
|
+
}
|
|
1513
1638
|
|
|
1514
1639
|
if (globalState.inBatch === 0 && // !globalState.trackingDerivatpion &&
|
|
1515
1640
|
this.observers_.size === 0 && !this.keepAlive_) {
|
|
@@ -1525,20 +1650,34 @@
|
|
|
1525
1650
|
|
|
1526
1651
|
if (shouldCompute(this)) {
|
|
1527
1652
|
var prevTrackingContext = globalState.trackingContext;
|
|
1528
|
-
|
|
1529
|
-
if (this.
|
|
1653
|
+
|
|
1654
|
+
if (this.keepAlive_ && !prevTrackingContext) {
|
|
1655
|
+
globalState.trackingContext = this;
|
|
1656
|
+
}
|
|
1657
|
+
|
|
1658
|
+
if (this.trackAndCompute()) {
|
|
1659
|
+
propagateChangeConfirmed(this);
|
|
1660
|
+
}
|
|
1661
|
+
|
|
1530
1662
|
globalState.trackingContext = prevTrackingContext;
|
|
1531
1663
|
}
|
|
1532
1664
|
}
|
|
1533
1665
|
|
|
1534
1666
|
var result = this.value_;
|
|
1535
|
-
|
|
1667
|
+
|
|
1668
|
+
if (isCaughtException(result)) {
|
|
1669
|
+
throw result.cause;
|
|
1670
|
+
}
|
|
1671
|
+
|
|
1536
1672
|
return result;
|
|
1537
1673
|
};
|
|
1538
1674
|
|
|
1539
1675
|
_proto.set = function set(value) {
|
|
1540
1676
|
if (this.setter_) {
|
|
1541
|
-
if (this.isRunningSetter_)
|
|
1677
|
+
if (this.isRunningSetter_) {
|
|
1678
|
+
die(33, this.name_);
|
|
1679
|
+
}
|
|
1680
|
+
|
|
1542
1681
|
this.isRunningSetter_ = true;
|
|
1543
1682
|
|
|
1544
1683
|
try {
|
|
@@ -1546,7 +1685,9 @@
|
|
|
1546
1685
|
} finally {
|
|
1547
1686
|
this.isRunningSetter_ = false;
|
|
1548
1687
|
}
|
|
1549
|
-
} else
|
|
1688
|
+
} else {
|
|
1689
|
+
die(34, this.name_);
|
|
1690
|
+
}
|
|
1550
1691
|
};
|
|
1551
1692
|
|
|
1552
1693
|
_proto.trackAndCompute = function trackAndCompute() {
|
|
@@ -1775,7 +1916,9 @@
|
|
|
1775
1916
|
|
|
1776
1917
|
var hasObservers = atom.observers_.size > 0; // Should not be possible to change observed state outside strict mode, except during initialization, see #563
|
|
1777
1918
|
|
|
1778
|
-
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
|
+
}
|
|
1779
1922
|
}
|
|
1780
1923
|
function checkIfStateReadsAreAllowed(observable) {
|
|
1781
1924
|
if ( !globalState.allowStateReads && globalState.observableRequiresReaction) {
|
|
@@ -1820,9 +1963,12 @@
|
|
|
1820
1963
|
}
|
|
1821
1964
|
|
|
1822
1965
|
function warnAboutDerivationWithoutDependencies(derivation) {
|
|
1823
|
-
if (derivation.observing_.length !== 0) return;
|
|
1824
1966
|
|
|
1825
|
-
if (
|
|
1967
|
+
if (derivation.observing_.length !== 0) {
|
|
1968
|
+
return;
|
|
1969
|
+
}
|
|
1970
|
+
|
|
1971
|
+
if (typeof derivation.requiresObservable_ === "boolean" ? derivation.requiresObservable_ : globalState.reactionRequiresObservable) {
|
|
1826
1972
|
console.warn("[mobx] Derivation '" + derivation.name_ + "' is created/updated without reading any observable value.");
|
|
1827
1973
|
}
|
|
1828
1974
|
}
|
|
@@ -1849,7 +1995,11 @@
|
|
|
1849
1995
|
|
|
1850
1996
|
if (dep.diffValue_ === 0) {
|
|
1851
1997
|
dep.diffValue_ = 1;
|
|
1852
|
-
|
|
1998
|
+
|
|
1999
|
+
if (i0 !== i) {
|
|
2000
|
+
observing[i0] = dep;
|
|
2001
|
+
}
|
|
2002
|
+
|
|
1853
2003
|
i0++;
|
|
1854
2004
|
} // Upcast is 'safe' here, because if dep is IObservable, `dependenciesState` will be undefined,
|
|
1855
2005
|
// not hitting the condition
|
|
@@ -1941,7 +2091,10 @@
|
|
|
1941
2091
|
*/
|
|
1942
2092
|
|
|
1943
2093
|
function changeDependenciesStateTo0(derivation) {
|
|
1944
|
-
if (derivation.dependenciesState_ === IDerivationState_.UP_TO_DATE_)
|
|
2094
|
+
if (derivation.dependenciesState_ === IDerivationState_.UP_TO_DATE_) {
|
|
2095
|
+
return;
|
|
2096
|
+
}
|
|
2097
|
+
|
|
1945
2098
|
derivation.dependenciesState_ = IDerivationState_.UP_TO_DATE_;
|
|
1946
2099
|
var obs = derivation.observing_;
|
|
1947
2100
|
var i = obs.length;
|
|
@@ -1985,8 +2138,14 @@
|
|
|
1985
2138
|
var isolateCalled = false;
|
|
1986
2139
|
var globalState = /*#__PURE__*/function () {
|
|
1987
2140
|
var global = /*#__PURE__*/getGlobal();
|
|
1988
|
-
|
|
1989
|
-
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
|
+
}
|
|
1990
2149
|
|
|
1991
2150
|
if (!canMergeGlobalState) {
|
|
1992
2151
|
// Because this is a IIFE we need to let isolateCalled a chance to change
|
|
@@ -1999,7 +2158,11 @@
|
|
|
1999
2158
|
return new MobXGlobals();
|
|
2000
2159
|
} else if (global.__mobxGlobals) {
|
|
2001
2160
|
global.__mobxInstanceCount += 1;
|
|
2002
|
-
|
|
2161
|
+
|
|
2162
|
+
if (!global.__mobxGlobals.UNCHANGED) {
|
|
2163
|
+
global.__mobxGlobals.UNCHANGED = {};
|
|
2164
|
+
} // make merge backward compatible
|
|
2165
|
+
|
|
2003
2166
|
|
|
2004
2167
|
return global.__mobxGlobals;
|
|
2005
2168
|
} else {
|
|
@@ -2008,12 +2171,19 @@
|
|
|
2008
2171
|
}
|
|
2009
2172
|
}();
|
|
2010
2173
|
function isolateGlobalState() {
|
|
2011
|
-
if (globalState.pendingReactions.length || globalState.inBatch || globalState.isRunningReactions)
|
|
2174
|
+
if (globalState.pendingReactions.length || globalState.inBatch || globalState.isRunningReactions) {
|
|
2175
|
+
die(36);
|
|
2176
|
+
}
|
|
2177
|
+
|
|
2012
2178
|
isolateCalled = true;
|
|
2013
2179
|
|
|
2014
2180
|
if (canMergeGlobalState) {
|
|
2015
2181
|
var global = getGlobal();
|
|
2016
|
-
|
|
2182
|
+
|
|
2183
|
+
if (--global.__mobxInstanceCount === 0) {
|
|
2184
|
+
global.__mobxGlobals = undefined;
|
|
2185
|
+
}
|
|
2186
|
+
|
|
2017
2187
|
globalState = new MobXGlobals();
|
|
2018
2188
|
}
|
|
2019
2189
|
}
|
|
@@ -2029,7 +2199,9 @@
|
|
|
2029
2199
|
var defaultGlobals = new MobXGlobals();
|
|
2030
2200
|
|
|
2031
2201
|
for (var key in defaultGlobals) {
|
|
2032
|
-
if (persistentKeys.indexOf(key) === -1)
|
|
2202
|
+
if (persistentKeys.indexOf(key) === -1) {
|
|
2203
|
+
globalState[key] = defaultGlobals[key];
|
|
2204
|
+
}
|
|
2033
2205
|
}
|
|
2034
2206
|
|
|
2035
2207
|
globalState.allowStateChanges = !globalState.enforceActions;
|
|
@@ -2063,8 +2235,12 @@
|
|
|
2063
2235
|
// invariant(observable._observers.indexOf(node) === -1, "INTERNAL ERROR add already added node");
|
|
2064
2236
|
// invariantObservers(observable);
|
|
2065
2237
|
observable.observers_.add(node);
|
|
2066
|
-
|
|
2238
|
+
|
|
2239
|
+
if (observable.lowestObserverState_ > node.dependenciesState_) {
|
|
2240
|
+
observable.lowestObserverState_ = node.dependenciesState_;
|
|
2241
|
+
} // invariantObservers(observable);
|
|
2067
2242
|
// invariant(observable._observers.indexOf(node) !== -1, "INTERNAL ERROR didn't add node");
|
|
2243
|
+
|
|
2068
2244
|
}
|
|
2069
2245
|
function removeObserver(observable, node) {
|
|
2070
2246
|
// invariant(globalState.inBatch > 0, "INTERNAL ERROR, remove should be called only inside batch");
|
|
@@ -2175,7 +2351,10 @@
|
|
|
2175
2351
|
|
|
2176
2352
|
function propagateChanged(observable) {
|
|
2177
2353
|
// invariantLOS(observable, "changed start");
|
|
2178
|
-
if (observable.lowestObserverState_ === IDerivationState_.STALE_)
|
|
2354
|
+
if (observable.lowestObserverState_ === IDerivationState_.STALE_) {
|
|
2355
|
+
return;
|
|
2356
|
+
}
|
|
2357
|
+
|
|
2179
2358
|
observable.lowestObserverState_ = IDerivationState_.STALE_; // Ideally we use for..of here, but the downcompiled version is really slow...
|
|
2180
2359
|
|
|
2181
2360
|
observable.observers_.forEach(function (d) {
|
|
@@ -2193,7 +2372,10 @@
|
|
|
2193
2372
|
|
|
2194
2373
|
function propagateChangeConfirmed(observable) {
|
|
2195
2374
|
// invariantLOS(observable, "confirmed start");
|
|
2196
|
-
if (observable.lowestObserverState_ === IDerivationState_.STALE_)
|
|
2375
|
+
if (observable.lowestObserverState_ === IDerivationState_.STALE_) {
|
|
2376
|
+
return;
|
|
2377
|
+
}
|
|
2378
|
+
|
|
2197
2379
|
observable.lowestObserverState_ = IDerivationState_.STALE_;
|
|
2198
2380
|
observable.observers_.forEach(function (d) {
|
|
2199
2381
|
if (d.dependenciesState_ === IDerivationState_.POSSIBLY_STALE_) {
|
|
@@ -2211,7 +2393,10 @@
|
|
|
2211
2393
|
|
|
2212
2394
|
function propagateMaybeChanged(observable) {
|
|
2213
2395
|
// invariantLOS(observable, "maybe start");
|
|
2214
|
-
if (observable.lowestObserverState_ !== IDerivationState_.UP_TO_DATE_)
|
|
2396
|
+
if (observable.lowestObserverState_ !== IDerivationState_.UP_TO_DATE_) {
|
|
2397
|
+
return;
|
|
2398
|
+
}
|
|
2399
|
+
|
|
2215
2400
|
observable.lowestObserverState_ = IDerivationState_.POSSIBLY_STALE_;
|
|
2216
2401
|
observable.observers_.forEach(function (d) {
|
|
2217
2402
|
if (d.dependenciesState_ === IDerivationState_.UP_TO_DATE_) {
|
|
@@ -2239,9 +2424,12 @@
|
|
|
2239
2424
|
}
|
|
2240
2425
|
|
|
2241
2426
|
lines.push("" + "\t".repeat(depth - 1) + tree.name);
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2427
|
+
|
|
2428
|
+
if (tree.dependencies) {
|
|
2429
|
+
tree.dependencies.forEach(function (child) {
|
|
2430
|
+
return printDepTree(child, lines, depth + 1);
|
|
2431
|
+
});
|
|
2432
|
+
}
|
|
2245
2433
|
}
|
|
2246
2434
|
|
|
2247
2435
|
var Reaction = /*#__PURE__*/function () {
|
|
@@ -2251,10 +2439,6 @@
|
|
|
2251
2439
|
name_ = "Reaction@" + getNextId() ;
|
|
2252
2440
|
}
|
|
2253
2441
|
|
|
2254
|
-
if (requiresObservable_ === void 0) {
|
|
2255
|
-
requiresObservable_ = false;
|
|
2256
|
-
}
|
|
2257
|
-
|
|
2258
2442
|
this.name_ = void 0;
|
|
2259
2443
|
this.onInvalidate_ = void 0;
|
|
2260
2444
|
this.errorHandler_ = void 0;
|
|
@@ -2359,7 +2543,9 @@
|
|
|
2359
2543
|
clearObserving(this);
|
|
2360
2544
|
}
|
|
2361
2545
|
|
|
2362
|
-
if (isCaughtException(result))
|
|
2546
|
+
if (isCaughtException(result)) {
|
|
2547
|
+
this.reportExceptionInDerivation_(result.cause);
|
|
2548
|
+
}
|
|
2363
2549
|
|
|
2364
2550
|
if ( notify) {
|
|
2365
2551
|
spyReportEnd({
|
|
@@ -2378,13 +2564,18 @@
|
|
|
2378
2564
|
return;
|
|
2379
2565
|
}
|
|
2380
2566
|
|
|
2381
|
-
if (globalState.disableErrorBoundaries)
|
|
2567
|
+
if (globalState.disableErrorBoundaries) {
|
|
2568
|
+
throw error;
|
|
2569
|
+
}
|
|
2570
|
+
|
|
2382
2571
|
var message = "[mobx] Encountered an uncaught exception that was thrown by a reaction or observer component, in: '" + this + "'" ;
|
|
2383
2572
|
|
|
2384
2573
|
if (!globalState.suppressReactionErrors) {
|
|
2385
2574
|
console.error(message, error);
|
|
2386
2575
|
/** If debugging brought you here, please, read the above message :-). Tnx! */
|
|
2387
|
-
} else
|
|
2576
|
+
} else {
|
|
2577
|
+
console.warn("[mobx] (error in reaction '" + this.name_ + "' suppressed, fix error of causing action below)");
|
|
2578
|
+
} // prettier-ignore
|
|
2388
2579
|
|
|
2389
2580
|
|
|
2390
2581
|
if ( isSpyEnabled()) {
|
|
@@ -2438,7 +2629,10 @@
|
|
|
2438
2629
|
globalState.globalReactionErrorHandlers.push(handler);
|
|
2439
2630
|
return function () {
|
|
2440
2631
|
var idx = globalState.globalReactionErrorHandlers.indexOf(handler);
|
|
2441
|
-
|
|
2632
|
+
|
|
2633
|
+
if (idx >= 0) {
|
|
2634
|
+
globalState.globalReactionErrorHandlers.splice(idx, 1);
|
|
2635
|
+
}
|
|
2442
2636
|
};
|
|
2443
2637
|
}
|
|
2444
2638
|
/**
|
|
@@ -2455,7 +2649,10 @@
|
|
|
2455
2649
|
|
|
2456
2650
|
function runReactions() {
|
|
2457
2651
|
// Trampolining, if runReactions are already running, new reactions will be picked up
|
|
2458
|
-
if (globalState.inBatch > 0 || globalState.isRunningReactions)
|
|
2652
|
+
if (globalState.inBatch > 0 || globalState.isRunningReactions) {
|
|
2653
|
+
return;
|
|
2654
|
+
}
|
|
2655
|
+
|
|
2459
2656
|
reactionScheduler(runReactionsHelper);
|
|
2460
2657
|
}
|
|
2461
2658
|
|
|
@@ -2498,7 +2695,11 @@
|
|
|
2498
2695
|
}
|
|
2499
2696
|
function spyReport(event) {
|
|
2500
2697
|
|
|
2501
|
-
|
|
2698
|
+
|
|
2699
|
+
if (!globalState.spyListeners.length) {
|
|
2700
|
+
return;
|
|
2701
|
+
}
|
|
2702
|
+
|
|
2502
2703
|
var listeners = globalState.spyListeners;
|
|
2503
2704
|
|
|
2504
2705
|
for (var i = 0, l = listeners.length; i < l; i++) {
|
|
@@ -2518,10 +2719,15 @@
|
|
|
2518
2719
|
spyReportEnd: true
|
|
2519
2720
|
};
|
|
2520
2721
|
function spyReportEnd(change) {
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2722
|
+
|
|
2723
|
+
if (change) {
|
|
2724
|
+
spyReport(_extends({}, change, {
|
|
2725
|
+
type: "report-end",
|
|
2726
|
+
spyReportEnd: true
|
|
2727
|
+
}));
|
|
2728
|
+
} else {
|
|
2729
|
+
spyReport(END_EVENT);
|
|
2730
|
+
}
|
|
2525
2731
|
}
|
|
2526
2732
|
function spy(listener) {
|
|
2527
2733
|
{
|
|
@@ -2554,9 +2760,15 @@
|
|
|
2554
2760
|
function createActionFactory(autoAction) {
|
|
2555
2761
|
var res = function action(arg1, arg2) {
|
|
2556
2762
|
// action(fn() {})
|
|
2557
|
-
if (isFunction(arg1))
|
|
2763
|
+
if (isFunction(arg1)) {
|
|
2764
|
+
return createAction(arg1.name || DEFAULT_ACTION_NAME, arg1, autoAction);
|
|
2765
|
+
} // action("name", fn() {})
|
|
2766
|
+
|
|
2767
|
+
|
|
2768
|
+
if (isFunction(arg2)) {
|
|
2769
|
+
return createAction(arg1, arg2, autoAction);
|
|
2770
|
+
} // @action
|
|
2558
2771
|
|
|
2559
|
-
if (isFunction(arg2)) return createAction(arg1, arg2, autoAction); // @action
|
|
2560
2772
|
|
|
2561
2773
|
if (isStringish(arg2)) {
|
|
2562
2774
|
return storeAnnotation(arg1, arg2, autoAction ? autoActionAnnotation : actionAnnotation);
|
|
@@ -2570,7 +2782,9 @@
|
|
|
2570
2782
|
}));
|
|
2571
2783
|
}
|
|
2572
2784
|
|
|
2573
|
-
|
|
2785
|
+
{
|
|
2786
|
+
die("Invalid arguments for `action`");
|
|
2787
|
+
}
|
|
2574
2788
|
};
|
|
2575
2789
|
|
|
2576
2790
|
return res;
|
|
@@ -2604,8 +2818,13 @@
|
|
|
2604
2818
|
}
|
|
2605
2819
|
|
|
2606
2820
|
{
|
|
2607
|
-
if (!isFunction(view))
|
|
2608
|
-
|
|
2821
|
+
if (!isFunction(view)) {
|
|
2822
|
+
die("Autorun expects a function as first argument");
|
|
2823
|
+
}
|
|
2824
|
+
|
|
2825
|
+
if (isAction(view)) {
|
|
2826
|
+
die("Autorun does not accept actions since actions are untrackable");
|
|
2827
|
+
}
|
|
2609
2828
|
}
|
|
2610
2829
|
|
|
2611
2830
|
var name = (_opts$name = (_opts = opts) == null ? void 0 : _opts.name) != null ? _opts$name : view.name || "Autorun@" + getNextId() ;
|
|
@@ -2626,7 +2845,10 @@
|
|
|
2626
2845
|
isScheduled = true;
|
|
2627
2846
|
scheduler(function () {
|
|
2628
2847
|
isScheduled = false;
|
|
2629
|
-
|
|
2848
|
+
|
|
2849
|
+
if (!reaction.isDisposed_) {
|
|
2850
|
+
reaction.track(reactionRunner);
|
|
2851
|
+
}
|
|
2630
2852
|
});
|
|
2631
2853
|
}
|
|
2632
2854
|
}, opts.onError, opts.requiresObservable);
|
|
@@ -2658,8 +2880,13 @@
|
|
|
2658
2880
|
}
|
|
2659
2881
|
|
|
2660
2882
|
{
|
|
2661
|
-
if (!isFunction(expression) || !isFunction(effect))
|
|
2662
|
-
|
|
2883
|
+
if (!isFunction(expression) || !isFunction(effect)) {
|
|
2884
|
+
die("First and second argument to reaction should be functions");
|
|
2885
|
+
}
|
|
2886
|
+
|
|
2887
|
+
if (!isPlainObject(opts)) {
|
|
2888
|
+
die("Third argument of reactions should be an object");
|
|
2889
|
+
}
|
|
2663
2890
|
}
|
|
2664
2891
|
|
|
2665
2892
|
var name = (_opts$name2 = opts.name) != null ? _opts$name2 : "Reaction@" + getNextId() ;
|
|
@@ -2682,7 +2909,11 @@
|
|
|
2682
2909
|
|
|
2683
2910
|
function reactionRunner() {
|
|
2684
2911
|
isScheduled = false;
|
|
2685
|
-
|
|
2912
|
+
|
|
2913
|
+
if (r.isDisposed_) {
|
|
2914
|
+
return;
|
|
2915
|
+
}
|
|
2916
|
+
|
|
2686
2917
|
var changed = false;
|
|
2687
2918
|
r.track(function () {
|
|
2688
2919
|
var nextValue = allowStateChanges(false, function () {
|
|
@@ -2692,7 +2923,13 @@
|
|
|
2692
2923
|
oldValue = value;
|
|
2693
2924
|
value = nextValue;
|
|
2694
2925
|
});
|
|
2695
|
-
|
|
2926
|
+
|
|
2927
|
+
if (firstTime && opts.fireImmediately) {
|
|
2928
|
+
effectAction(value, oldValue, r);
|
|
2929
|
+
} else if (!firstTime && changed) {
|
|
2930
|
+
effectAction(value, oldValue, r);
|
|
2931
|
+
}
|
|
2932
|
+
|
|
2696
2933
|
firstTime = false;
|
|
2697
2934
|
}
|
|
2698
2935
|
|
|
@@ -2759,7 +2996,9 @@
|
|
|
2759
2996
|
globalState.useProxies = useProxies === ALWAYS ? true : useProxies === NEVER ? false : typeof Proxy !== "undefined";
|
|
2760
2997
|
}
|
|
2761
2998
|
|
|
2762
|
-
if (useProxies === "ifavailable")
|
|
2999
|
+
if (useProxies === "ifavailable") {
|
|
3000
|
+
globalState.verifyProxies = true;
|
|
3001
|
+
}
|
|
2763
3002
|
|
|
2764
3003
|
if (enforceActions !== undefined) {
|
|
2765
3004
|
var ea = enforceActions === ALWAYS ? ALWAYS : enforceActions === OBSERVED;
|
|
@@ -2767,7 +3006,9 @@
|
|
|
2767
3006
|
globalState.allowStateChanges = ea === true || ea === ALWAYS ? false : true;
|
|
2768
3007
|
}
|
|
2769
3008
|
["computedRequiresReaction", "reactionRequiresObservable", "observableRequiresReaction", "disableErrorBoundaries", "safeDescriptors"].forEach(function (key) {
|
|
2770
|
-
if (key in options)
|
|
3009
|
+
if (key in options) {
|
|
3010
|
+
globalState[key] = !!options[key];
|
|
3011
|
+
}
|
|
2771
3012
|
});
|
|
2772
3013
|
globalState.allowStateReads = !globalState.observableRequiresReaction;
|
|
2773
3014
|
|
|
@@ -2782,11 +3023,25 @@
|
|
|
2782
3023
|
|
|
2783
3024
|
function extendObservable(target, properties, annotations, options) {
|
|
2784
3025
|
{
|
|
2785
|
-
if (arguments.length > 4)
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
if (
|
|
3026
|
+
if (arguments.length > 4) {
|
|
3027
|
+
die("'extendObservable' expected 2-4 arguments");
|
|
3028
|
+
}
|
|
3029
|
+
|
|
3030
|
+
if (typeof target !== "object") {
|
|
3031
|
+
die("'extendObservable' expects an object as first argument");
|
|
3032
|
+
}
|
|
3033
|
+
|
|
3034
|
+
if (isObservableMap(target)) {
|
|
3035
|
+
die("'extendObservable' should not be used on maps, use map.merge instead");
|
|
3036
|
+
}
|
|
3037
|
+
|
|
3038
|
+
if (!isPlainObject(properties)) {
|
|
3039
|
+
die("'extendObservable' only accepts plain objects as second argument");
|
|
3040
|
+
}
|
|
3041
|
+
|
|
3042
|
+
if (isObservable(properties) || isObservable(annotations)) {
|
|
3043
|
+
die("Extending an object with another observable (object) is not supported");
|
|
3044
|
+
}
|
|
2790
3045
|
} // Pull descriptors first, so we don't have to deal with props added by administration ($mobx)
|
|
2791
3046
|
|
|
2792
3047
|
|
|
@@ -2814,7 +3069,11 @@
|
|
|
2814
3069
|
var result = {
|
|
2815
3070
|
name: node.name_
|
|
2816
3071
|
};
|
|
2817
|
-
|
|
3072
|
+
|
|
3073
|
+
if (node.observing_ && node.observing_.length > 0) {
|
|
3074
|
+
result.dependencies = unique(node.observing_).map(nodeToDependencyTree);
|
|
3075
|
+
}
|
|
3076
|
+
|
|
2818
3077
|
return result;
|
|
2819
3078
|
}
|
|
2820
3079
|
|
|
@@ -2826,7 +3085,11 @@
|
|
|
2826
3085
|
var result = {
|
|
2827
3086
|
name: node.name_
|
|
2828
3087
|
};
|
|
2829
|
-
|
|
3088
|
+
|
|
3089
|
+
if (hasObservers(node)) {
|
|
3090
|
+
result.observers = Array.from(getObservers(node)).map(nodeToObserverTree);
|
|
3091
|
+
}
|
|
3092
|
+
|
|
2830
3093
|
return result;
|
|
2831
3094
|
}
|
|
2832
3095
|
|
|
@@ -2853,7 +3116,10 @@
|
|
|
2853
3116
|
} // flow(fn)
|
|
2854
3117
|
|
|
2855
3118
|
|
|
2856
|
-
if ( arguments.length !== 1)
|
|
3119
|
+
if ( arguments.length !== 1) {
|
|
3120
|
+
die("Flow expects single argument with generator function");
|
|
3121
|
+
}
|
|
3122
|
+
|
|
2857
3123
|
var generator = arg1;
|
|
2858
3124
|
var name = generator.name || "<unnamed flow>"; // Implementation based on https://github.com/tj/co/blob/master/index.js
|
|
2859
3125
|
|
|
@@ -2901,7 +3167,10 @@
|
|
|
2901
3167
|
return;
|
|
2902
3168
|
}
|
|
2903
3169
|
|
|
2904
|
-
if (ret.done)
|
|
3170
|
+
if (ret.done) {
|
|
3171
|
+
return resolve(ret.value);
|
|
3172
|
+
}
|
|
3173
|
+
|
|
2905
3174
|
pendingPromise = Promise.resolve(ret.value);
|
|
2906
3175
|
return pendingPromise.then(onFulfilled, onRejected);
|
|
2907
3176
|
}
|
|
@@ -2910,7 +3179,10 @@
|
|
|
2910
3179
|
});
|
|
2911
3180
|
promise.cancel = action(name + " - runid: " + runId + " - cancel", function () {
|
|
2912
3181
|
try {
|
|
2913
|
-
if (pendingPromise)
|
|
3182
|
+
if (pendingPromise) {
|
|
3183
|
+
cancelPromise(pendingPromise);
|
|
3184
|
+
} // Finally block can return (or yield) stuff..
|
|
3185
|
+
|
|
2914
3186
|
|
|
2915
3187
|
var _res = gen["return"](undefined); // eat anything that promise would do, it's cancelled!
|
|
2916
3188
|
|
|
@@ -2934,7 +3206,9 @@
|
|
|
2934
3206
|
flow.bound = /*#__PURE__*/createDecoratorAnnotation(flowBoundAnnotation);
|
|
2935
3207
|
|
|
2936
3208
|
function cancelPromise(promise) {
|
|
2937
|
-
if (isFunction(promise.cancel))
|
|
3209
|
+
if (isFunction(promise.cancel)) {
|
|
3210
|
+
promise.cancel();
|
|
3211
|
+
}
|
|
2938
3212
|
}
|
|
2939
3213
|
|
|
2940
3214
|
function flowResult(result) {
|
|
@@ -2950,13 +3224,19 @@
|
|
|
2950
3224
|
if (isObservableMap(thing) || isObservableArray(thing) || isObservableValue(thing)) {
|
|
2951
3225
|
target = getAdministration(thing);
|
|
2952
3226
|
} else if (isObservableObject(thing)) {
|
|
2953
|
-
if ( !isStringish(propOrHandler))
|
|
3227
|
+
if ( !isStringish(propOrHandler)) {
|
|
3228
|
+
return die("InterceptReads can only be used with a specific property, not with an object in general");
|
|
3229
|
+
}
|
|
3230
|
+
|
|
2954
3231
|
target = getAdministration(thing, propOrHandler);
|
|
2955
3232
|
} else {
|
|
2956
3233
|
return die("Expected observable map, object or array as first array");
|
|
2957
3234
|
}
|
|
2958
3235
|
|
|
2959
|
-
if ( target.dehancer !== undefined)
|
|
3236
|
+
if ( target.dehancer !== undefined) {
|
|
3237
|
+
return die("An intercept reader was already established");
|
|
3238
|
+
}
|
|
3239
|
+
|
|
2960
3240
|
target.dehancer = typeof propOrHandler === "function" ? propOrHandler : handler;
|
|
2961
3241
|
return function () {
|
|
2962
3242
|
target.dehancer = undefined;
|
|
@@ -2964,7 +3244,11 @@
|
|
|
2964
3244
|
}
|
|
2965
3245
|
|
|
2966
3246
|
function intercept(thing, propOrHandler, handler) {
|
|
2967
|
-
if (isFunction(handler))
|
|
3247
|
+
if (isFunction(handler)) {
|
|
3248
|
+
return interceptProperty(thing, propOrHandler, handler);
|
|
3249
|
+
} else {
|
|
3250
|
+
return interceptInterceptable(thing, propOrHandler);
|
|
3251
|
+
}
|
|
2968
3252
|
}
|
|
2969
3253
|
|
|
2970
3254
|
function interceptInterceptable(thing, handler) {
|
|
@@ -2980,25 +3264,41 @@
|
|
|
2980
3264
|
return isComputedValue(value);
|
|
2981
3265
|
}
|
|
2982
3266
|
|
|
2983
|
-
if (isObservableObject(value) === false)
|
|
2984
|
-
|
|
3267
|
+
if (isObservableObject(value) === false) {
|
|
3268
|
+
return false;
|
|
3269
|
+
}
|
|
3270
|
+
|
|
3271
|
+
if (!value[$mobx].values_.has(property)) {
|
|
3272
|
+
return false;
|
|
3273
|
+
}
|
|
3274
|
+
|
|
2985
3275
|
var atom = getAtom(value, property);
|
|
2986
3276
|
return isComputedValue(atom);
|
|
2987
3277
|
}
|
|
2988
3278
|
function isComputed(value) {
|
|
2989
|
-
if ( arguments.length > 1)
|
|
3279
|
+
if ( arguments.length > 1) {
|
|
3280
|
+
return die("isComputed expects only 1 argument. Use isComputedProp to inspect the observability of a property");
|
|
3281
|
+
}
|
|
3282
|
+
|
|
2990
3283
|
return _isComputed(value);
|
|
2991
3284
|
}
|
|
2992
3285
|
function isComputedProp(value, propName) {
|
|
2993
|
-
if ( !isStringish(propName))
|
|
3286
|
+
if ( !isStringish(propName)) {
|
|
3287
|
+
return die("isComputed expected a property name as second argument");
|
|
3288
|
+
}
|
|
3289
|
+
|
|
2994
3290
|
return _isComputed(value, propName);
|
|
2995
3291
|
}
|
|
2996
3292
|
|
|
2997
3293
|
function _isObservable(value, property) {
|
|
2998
|
-
if (!value)
|
|
3294
|
+
if (!value) {
|
|
3295
|
+
return false;
|
|
3296
|
+
}
|
|
2999
3297
|
|
|
3000
3298
|
if (property !== undefined) {
|
|
3001
|
-
if ( (isObservableMap(value) || isObservableArray(value)))
|
|
3299
|
+
if ( (isObservableMap(value) || isObservableArray(value))) {
|
|
3300
|
+
return die("isObservable(object, propertyName) is not supported for arrays and maps. Use map.has or array.length instead.");
|
|
3301
|
+
}
|
|
3002
3302
|
|
|
3003
3303
|
if (isObservableObject(value)) {
|
|
3004
3304
|
return value[$mobx].values_.has(property);
|
|
@@ -3012,11 +3312,17 @@
|
|
|
3012
3312
|
}
|
|
3013
3313
|
|
|
3014
3314
|
function isObservable(value) {
|
|
3015
|
-
if ( arguments.length !== 1)
|
|
3315
|
+
if ( arguments.length !== 1) {
|
|
3316
|
+
die("isObservable expects only 1 argument. Use isObservableProp to inspect the observability of a property");
|
|
3317
|
+
}
|
|
3318
|
+
|
|
3016
3319
|
return _isObservable(value);
|
|
3017
3320
|
}
|
|
3018
3321
|
function isObservableProp(value, propName) {
|
|
3019
|
-
if ( !isStringish(propName))
|
|
3322
|
+
if ( !isStringish(propName)) {
|
|
3323
|
+
return die("expected a property name as second argument");
|
|
3324
|
+
}
|
|
3325
|
+
|
|
3020
3326
|
return _isObservable(value, propName);
|
|
3021
3327
|
}
|
|
3022
3328
|
|
|
@@ -3108,13 +3414,25 @@
|
|
|
3108
3414
|
} else if (isObservableSet(obj)) {
|
|
3109
3415
|
obj.add(key);
|
|
3110
3416
|
} else if (isObservableArray(obj)) {
|
|
3111
|
-
if (typeof key !== "number")
|
|
3112
|
-
|
|
3417
|
+
if (typeof key !== "number") {
|
|
3418
|
+
key = parseInt(key, 10);
|
|
3419
|
+
}
|
|
3420
|
+
|
|
3421
|
+
if (key < 0) {
|
|
3422
|
+
die("Invalid index: '" + key + "'");
|
|
3423
|
+
}
|
|
3424
|
+
|
|
3113
3425
|
startBatch();
|
|
3114
|
-
|
|
3426
|
+
|
|
3427
|
+
if (key >= obj.length) {
|
|
3428
|
+
obj.length = key + 1;
|
|
3429
|
+
}
|
|
3430
|
+
|
|
3115
3431
|
obj[key] = value;
|
|
3116
3432
|
endBatch();
|
|
3117
|
-
} else
|
|
3433
|
+
} else {
|
|
3434
|
+
die(8);
|
|
3435
|
+
}
|
|
3118
3436
|
}
|
|
3119
3437
|
function remove(obj, key) {
|
|
3120
3438
|
if (isObservableObject(obj)) {
|
|
@@ -3124,7 +3442,10 @@
|
|
|
3124
3442
|
} else if (isObservableSet(obj)) {
|
|
3125
3443
|
obj["delete"](key);
|
|
3126
3444
|
} else if (isObservableArray(obj)) {
|
|
3127
|
-
if (typeof key !== "number")
|
|
3445
|
+
if (typeof key !== "number") {
|
|
3446
|
+
key = parseInt(key, 10);
|
|
3447
|
+
}
|
|
3448
|
+
|
|
3128
3449
|
obj.splice(key, 1);
|
|
3129
3450
|
} else {
|
|
3130
3451
|
die(9);
|
|
@@ -3144,7 +3465,9 @@
|
|
|
3144
3465
|
die(10);
|
|
3145
3466
|
}
|
|
3146
3467
|
function get(obj, key) {
|
|
3147
|
-
if (!has(obj, key))
|
|
3468
|
+
if (!has(obj, key)) {
|
|
3469
|
+
return undefined;
|
|
3470
|
+
}
|
|
3148
3471
|
|
|
3149
3472
|
if (isObservableObject(obj)) {
|
|
3150
3473
|
return obj[$mobx].get_(key);
|
|
@@ -3172,7 +3495,11 @@
|
|
|
3172
3495
|
}
|
|
3173
3496
|
|
|
3174
3497
|
function observe(thing, propOrCb, cbOrFire, fireImmediately) {
|
|
3175
|
-
if (isFunction(cbOrFire))
|
|
3498
|
+
if (isFunction(cbOrFire)) {
|
|
3499
|
+
return observeObservableProperty(thing, propOrCb, cbOrFire, fireImmediately);
|
|
3500
|
+
} else {
|
|
3501
|
+
return observeObservable(thing, propOrCb, cbOrFire);
|
|
3502
|
+
}
|
|
3176
3503
|
}
|
|
3177
3504
|
|
|
3178
3505
|
function observeObservable(thing, listener, fireImmediately) {
|
|
@@ -3189,8 +3516,13 @@
|
|
|
3189
3516
|
}
|
|
3190
3517
|
|
|
3191
3518
|
function toJSHelper(source, __alreadySeen) {
|
|
3192
|
-
if (source == null || typeof source !== "object" || source instanceof Date || !isObservable(source))
|
|
3193
|
-
|
|
3519
|
+
if (source == null || typeof source !== "object" || source instanceof Date || !isObservable(source)) {
|
|
3520
|
+
return source;
|
|
3521
|
+
}
|
|
3522
|
+
|
|
3523
|
+
if (isObservableValue(source) || isComputedValue(source)) {
|
|
3524
|
+
return toJSHelper(source.get(), __alreadySeen);
|
|
3525
|
+
}
|
|
3194
3526
|
|
|
3195
3527
|
if (__alreadySeen.has(source)) {
|
|
3196
3528
|
return __alreadySeen.get(source);
|
|
@@ -3241,18 +3573,25 @@
|
|
|
3241
3573
|
|
|
3242
3574
|
|
|
3243
3575
|
function toJS(source, options) {
|
|
3244
|
-
if ( options)
|
|
3576
|
+
if ( options) {
|
|
3577
|
+
die("toJS no longer supports options");
|
|
3578
|
+
}
|
|
3579
|
+
|
|
3245
3580
|
return toJSHelper(source, new Map());
|
|
3246
3581
|
}
|
|
3247
3582
|
|
|
3248
3583
|
function trace() {
|
|
3584
|
+
|
|
3249
3585
|
var enterBreakPoint = false;
|
|
3250
3586
|
|
|
3251
3587
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
3252
3588
|
args[_key] = arguments[_key];
|
|
3253
3589
|
}
|
|
3254
3590
|
|
|
3255
|
-
if (typeof args[args.length - 1] === "boolean")
|
|
3591
|
+
if (typeof args[args.length - 1] === "boolean") {
|
|
3592
|
+
enterBreakPoint = args.pop();
|
|
3593
|
+
}
|
|
3594
|
+
|
|
3256
3595
|
var derivation = getAtomFromArgs(args);
|
|
3257
3596
|
|
|
3258
3597
|
if (!derivation) {
|
|
@@ -3302,7 +3641,10 @@
|
|
|
3302
3641
|
}
|
|
3303
3642
|
|
|
3304
3643
|
function when(predicate, arg1, arg2) {
|
|
3305
|
-
if (arguments.length === 1 || arg1 && typeof arg1 === "object")
|
|
3644
|
+
if (arguments.length === 1 || arg1 && typeof arg1 === "object") {
|
|
3645
|
+
return whenPromise(predicate, arg1);
|
|
3646
|
+
}
|
|
3647
|
+
|
|
3306
3648
|
return _when(predicate, arg1, arg2 || {});
|
|
3307
3649
|
}
|
|
3308
3650
|
|
|
@@ -3314,7 +3656,12 @@
|
|
|
3314
3656
|
timeoutHandle = setTimeout(function () {
|
|
3315
3657
|
if (!disposer[$mobx].isDisposed_) {
|
|
3316
3658
|
disposer();
|
|
3317
|
-
|
|
3659
|
+
|
|
3660
|
+
if (opts.onError) {
|
|
3661
|
+
opts.onError(error);
|
|
3662
|
+
} else {
|
|
3663
|
+
throw error;
|
|
3664
|
+
}
|
|
3318
3665
|
}
|
|
3319
3666
|
}, opts.timeout);
|
|
3320
3667
|
}
|
|
@@ -3328,7 +3675,11 @@
|
|
|
3328
3675
|
|
|
3329
3676
|
if (cond) {
|
|
3330
3677
|
r.dispose();
|
|
3331
|
-
|
|
3678
|
+
|
|
3679
|
+
if (timeoutHandle) {
|
|
3680
|
+
clearTimeout(timeoutHandle);
|
|
3681
|
+
}
|
|
3682
|
+
|
|
3332
3683
|
effectAction();
|
|
3333
3684
|
}
|
|
3334
3685
|
}, opts);
|
|
@@ -3336,7 +3687,10 @@
|
|
|
3336
3687
|
}
|
|
3337
3688
|
|
|
3338
3689
|
function whenPromise(predicate, opts) {
|
|
3339
|
-
if ( opts && opts.onError)
|
|
3690
|
+
if ( opts && opts.onError) {
|
|
3691
|
+
return die("the options 'onError' and 'promise' cannot be combined");
|
|
3692
|
+
}
|
|
3693
|
+
|
|
3340
3694
|
var cancel;
|
|
3341
3695
|
var res = new Promise(function (resolve, reject) {
|
|
3342
3696
|
var disposer = _when(predicate, resolve, _extends({}, opts, {
|
|
@@ -3360,7 +3714,10 @@
|
|
|
3360
3714
|
|
|
3361
3715
|
var objectProxyTraps = {
|
|
3362
3716
|
has: function has(target, name) {
|
|
3363
|
-
if ( globalState.trackingDerivation)
|
|
3717
|
+
if ( globalState.trackingDerivation) {
|
|
3718
|
+
warnAboutProxyRequirement("detect new properties using the 'in' operator. Use 'has' from 'mobx' instead.");
|
|
3719
|
+
}
|
|
3720
|
+
|
|
3364
3721
|
return getAdm(target).has_(name);
|
|
3365
3722
|
},
|
|
3366
3723
|
get: function get(target, name) {
|
|
@@ -3369,7 +3726,9 @@
|
|
|
3369
3726
|
set: function set(target, name, value) {
|
|
3370
3727
|
var _getAdm$set_;
|
|
3371
3728
|
|
|
3372
|
-
if (!isStringish(name))
|
|
3729
|
+
if (!isStringish(name)) {
|
|
3730
|
+
return false;
|
|
3731
|
+
}
|
|
3373
3732
|
|
|
3374
3733
|
if ( !getAdm(target).values_.has(name)) {
|
|
3375
3734
|
warnAboutProxyRequirement("add a new observable property through direct assignment. Use 'set' from 'mobx' instead.");
|
|
@@ -3385,7 +3744,10 @@
|
|
|
3385
3744
|
warnAboutProxyRequirement("delete properties from an observable object. Use 'remove' from 'mobx' instead.");
|
|
3386
3745
|
}
|
|
3387
3746
|
|
|
3388
|
-
if (!isStringish(name))
|
|
3747
|
+
if (!isStringish(name)) {
|
|
3748
|
+
return false;
|
|
3749
|
+
} // null (intercepted) -> true (success)
|
|
3750
|
+
|
|
3389
3751
|
|
|
3390
3752
|
return (_getAdm$delete_ = getAdm(target).delete_(name, true)) != null ? _getAdm$delete_ : true;
|
|
3391
3753
|
},
|
|
@@ -3400,7 +3762,10 @@
|
|
|
3400
3762
|
return (_getAdm$definePropert = getAdm(target).defineProperty_(name, descriptor)) != null ? _getAdm$definePropert : true;
|
|
3401
3763
|
},
|
|
3402
3764
|
ownKeys: function ownKeys(target) {
|
|
3403
|
-
if ( globalState.trackingDerivation)
|
|
3765
|
+
if ( globalState.trackingDerivation) {
|
|
3766
|
+
warnAboutProxyRequirement("iterate keys to detect added / removed properties. Use 'keys' from 'mobx' instead.");
|
|
3767
|
+
}
|
|
3768
|
+
|
|
3404
3769
|
return getAdm(target).ownKeys_();
|
|
3405
3770
|
},
|
|
3406
3771
|
preventExtensions: function preventExtensions(target) {
|
|
@@ -3423,7 +3788,10 @@
|
|
|
3423
3788
|
interceptors.push(handler);
|
|
3424
3789
|
return once(function () {
|
|
3425
3790
|
var idx = interceptors.indexOf(handler);
|
|
3426
|
-
|
|
3791
|
+
|
|
3792
|
+
if (idx !== -1) {
|
|
3793
|
+
interceptors.splice(idx, 1);
|
|
3794
|
+
}
|
|
3427
3795
|
});
|
|
3428
3796
|
}
|
|
3429
3797
|
function interceptChange(interceptable, change) {
|
|
@@ -3435,8 +3803,14 @@
|
|
|
3435
3803
|
|
|
3436
3804
|
for (var i = 0, l = interceptors.length; i < l; i++) {
|
|
3437
3805
|
change = interceptors[i](change);
|
|
3438
|
-
|
|
3439
|
-
if (!change)
|
|
3806
|
+
|
|
3807
|
+
if (change && !change.type) {
|
|
3808
|
+
die(14);
|
|
3809
|
+
}
|
|
3810
|
+
|
|
3811
|
+
if (!change) {
|
|
3812
|
+
break;
|
|
3813
|
+
}
|
|
3440
3814
|
}
|
|
3441
3815
|
|
|
3442
3816
|
return change;
|
|
@@ -3453,13 +3827,20 @@
|
|
|
3453
3827
|
listeners.push(handler);
|
|
3454
3828
|
return once(function () {
|
|
3455
3829
|
var idx = listeners.indexOf(handler);
|
|
3456
|
-
|
|
3830
|
+
|
|
3831
|
+
if (idx !== -1) {
|
|
3832
|
+
listeners.splice(idx, 1);
|
|
3833
|
+
}
|
|
3457
3834
|
});
|
|
3458
3835
|
}
|
|
3459
3836
|
function notifyListeners(listenable, change) {
|
|
3460
3837
|
var prevU = untrackedStart();
|
|
3461
3838
|
var listeners = listenable.changeListeners_;
|
|
3462
|
-
|
|
3839
|
+
|
|
3840
|
+
if (!listeners) {
|
|
3841
|
+
return;
|
|
3842
|
+
}
|
|
3843
|
+
|
|
3463
3844
|
listeners = listeners.slice();
|
|
3464
3845
|
|
|
3465
3846
|
for (var i = 0, l = listeners.length; i < l; i++) {
|
|
@@ -3496,8 +3877,13 @@
|
|
|
3496
3877
|
var keysSymbol = /*#__PURE__*/Symbol("mobx-keys");
|
|
3497
3878
|
function makeAutoObservable(target, overrides, options) {
|
|
3498
3879
|
{
|
|
3499
|
-
if (!isPlainObject(target) && !isPlainObject(Object.getPrototypeOf(target)))
|
|
3500
|
-
|
|
3880
|
+
if (!isPlainObject(target) && !isPlainObject(Object.getPrototypeOf(target))) {
|
|
3881
|
+
die("'makeAutoObservable' can only be used for classes that don't have a superclass");
|
|
3882
|
+
}
|
|
3883
|
+
|
|
3884
|
+
if (isObservableObject(target)) {
|
|
3885
|
+
die("makeAutoObservable can only be used on objects not already made observable");
|
|
3886
|
+
}
|
|
3501
3887
|
} // Optimization: avoid visiting protos
|
|
3502
3888
|
// Assumes that annotation.make_/.extend_ works the same for plain objects
|
|
3503
3889
|
|
|
@@ -3538,8 +3924,14 @@
|
|
|
3538
3924
|
var arrayTraps = {
|
|
3539
3925
|
get: function get(target, name) {
|
|
3540
3926
|
var adm = target[$mobx];
|
|
3541
|
-
|
|
3542
|
-
if (name ===
|
|
3927
|
+
|
|
3928
|
+
if (name === $mobx) {
|
|
3929
|
+
return adm;
|
|
3930
|
+
}
|
|
3931
|
+
|
|
3932
|
+
if (name === "length") {
|
|
3933
|
+
return adm.getArrayLength_();
|
|
3934
|
+
}
|
|
3543
3935
|
|
|
3544
3936
|
if (typeof name === "string" && !isNaN(name)) {
|
|
3545
3937
|
return adm.get_(parseInt(name));
|
|
@@ -3600,12 +3992,18 @@
|
|
|
3600
3992
|
var _proto = ObservableArrayAdministration.prototype;
|
|
3601
3993
|
|
|
3602
3994
|
_proto.dehanceValue_ = function dehanceValue_(value) {
|
|
3603
|
-
if (this.dehancer !== undefined)
|
|
3995
|
+
if (this.dehancer !== undefined) {
|
|
3996
|
+
return this.dehancer(value);
|
|
3997
|
+
}
|
|
3998
|
+
|
|
3604
3999
|
return value;
|
|
3605
4000
|
};
|
|
3606
4001
|
|
|
3607
4002
|
_proto.dehanceValues_ = function dehanceValues_(values) {
|
|
3608
|
-
if (this.dehancer !== undefined && values.length > 0)
|
|
4003
|
+
if (this.dehancer !== undefined && values.length > 0) {
|
|
4004
|
+
return values.map(this.dehancer);
|
|
4005
|
+
}
|
|
4006
|
+
|
|
3609
4007
|
return values;
|
|
3610
4008
|
};
|
|
3611
4009
|
|
|
@@ -3641,9 +4039,15 @@
|
|
|
3641
4039
|
};
|
|
3642
4040
|
|
|
3643
4041
|
_proto.setArrayLength_ = function setArrayLength_(newLength) {
|
|
3644
|
-
if (typeof newLength !== "number" || isNaN(newLength) || newLength < 0)
|
|
4042
|
+
if (typeof newLength !== "number" || isNaN(newLength) || newLength < 0) {
|
|
4043
|
+
die("Out of range: " + newLength);
|
|
4044
|
+
}
|
|
4045
|
+
|
|
3645
4046
|
var currentLength = this.values_.length;
|
|
3646
|
-
|
|
4047
|
+
|
|
4048
|
+
if (newLength === currentLength) {
|
|
4049
|
+
return;
|
|
4050
|
+
} else if (newLength > currentLength) {
|
|
3647
4051
|
var newItems = new Array(newLength - currentLength);
|
|
3648
4052
|
|
|
3649
4053
|
for (var i = 0; i < newLength - currentLength; i++) {
|
|
@@ -3652,13 +4056,21 @@
|
|
|
3652
4056
|
|
|
3653
4057
|
|
|
3654
4058
|
this.spliceWithArray_(currentLength, 0, newItems);
|
|
3655
|
-
} else
|
|
4059
|
+
} else {
|
|
4060
|
+
this.spliceWithArray_(newLength, currentLength - newLength);
|
|
4061
|
+
}
|
|
3656
4062
|
};
|
|
3657
4063
|
|
|
3658
4064
|
_proto.updateArrayLength_ = function updateArrayLength_(oldLength, delta) {
|
|
3659
|
-
if (oldLength !== this.lastKnownLength_)
|
|
4065
|
+
if (oldLength !== this.lastKnownLength_) {
|
|
4066
|
+
die(16);
|
|
4067
|
+
}
|
|
4068
|
+
|
|
3660
4069
|
this.lastKnownLength_ += delta;
|
|
3661
|
-
|
|
4070
|
+
|
|
4071
|
+
if (this.legacyMode_ && delta > 0) {
|
|
4072
|
+
reserveArrayBuffer(oldLength + delta + 1);
|
|
4073
|
+
}
|
|
3662
4074
|
};
|
|
3663
4075
|
|
|
3664
4076
|
_proto.spliceWithArray_ = function spliceWithArray_(index, deleteCount, newItems) {
|
|
@@ -3666,9 +4078,26 @@
|
|
|
3666
4078
|
|
|
3667
4079
|
checkIfStateModificationsAreAllowed(this.atom_);
|
|
3668
4080
|
var length = this.values_.length;
|
|
3669
|
-
|
|
3670
|
-
if (
|
|
3671
|
-
|
|
4081
|
+
|
|
4082
|
+
if (index === undefined) {
|
|
4083
|
+
index = 0;
|
|
4084
|
+
} else if (index > length) {
|
|
4085
|
+
index = length;
|
|
4086
|
+
} else if (index < 0) {
|
|
4087
|
+
index = Math.max(0, length + index);
|
|
4088
|
+
}
|
|
4089
|
+
|
|
4090
|
+
if (arguments.length === 1) {
|
|
4091
|
+
deleteCount = length - index;
|
|
4092
|
+
} else if (deleteCount === undefined || deleteCount === null) {
|
|
4093
|
+
deleteCount = 0;
|
|
4094
|
+
} else {
|
|
4095
|
+
deleteCount = Math.max(0, Math.min(deleteCount, length - index));
|
|
4096
|
+
}
|
|
4097
|
+
|
|
4098
|
+
if (newItems === undefined) {
|
|
4099
|
+
newItems = EMPTY_ARRAY;
|
|
4100
|
+
}
|
|
3672
4101
|
|
|
3673
4102
|
if (hasInterceptors(this)) {
|
|
3674
4103
|
var change = interceptChange(this, {
|
|
@@ -3678,7 +4107,11 @@
|
|
|
3678
4107
|
removedCount: deleteCount,
|
|
3679
4108
|
added: newItems
|
|
3680
4109
|
});
|
|
3681
|
-
|
|
4110
|
+
|
|
4111
|
+
if (!change) {
|
|
4112
|
+
return EMPTY_ARRAY;
|
|
4113
|
+
}
|
|
4114
|
+
|
|
3682
4115
|
deleteCount = change.removedCount;
|
|
3683
4116
|
newItems = change.added;
|
|
3684
4117
|
}
|
|
@@ -3693,7 +4126,11 @@
|
|
|
3693
4126
|
}
|
|
3694
4127
|
|
|
3695
4128
|
var res = this.spliceItemsIntoValues_(index, deleteCount, newItems);
|
|
3696
|
-
|
|
4129
|
+
|
|
4130
|
+
if (deleteCount !== 0 || newItems.length !== 0) {
|
|
4131
|
+
this.notifyArraySplice_(index, newItems, res);
|
|
4132
|
+
}
|
|
4133
|
+
|
|
3697
4134
|
return this.dehanceValues_(res);
|
|
3698
4135
|
};
|
|
3699
4136
|
|
|
@@ -3736,10 +4173,19 @@
|
|
|
3736
4173
|
} : 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
|
|
3737
4174
|
// cause any runtime overhead in development mode without NODE_ENV set, unless spying is enabled
|
|
3738
4175
|
|
|
3739
|
-
if ( notifySpy)
|
|
4176
|
+
if ( notifySpy) {
|
|
4177
|
+
spyReportStart(change);
|
|
4178
|
+
}
|
|
4179
|
+
|
|
3740
4180
|
this.atom_.reportChanged();
|
|
3741
|
-
|
|
3742
|
-
if (
|
|
4181
|
+
|
|
4182
|
+
if (notify) {
|
|
4183
|
+
notifyListeners(this, change);
|
|
4184
|
+
}
|
|
4185
|
+
|
|
4186
|
+
if ( notifySpy) {
|
|
4187
|
+
spyReportEnd();
|
|
4188
|
+
}
|
|
3743
4189
|
};
|
|
3744
4190
|
|
|
3745
4191
|
_proto.notifyArraySplice_ = function notifyArraySplice_(index, added, removed) {
|
|
@@ -3756,11 +4202,20 @@
|
|
|
3756
4202
|
removedCount: removed.length,
|
|
3757
4203
|
addedCount: added.length
|
|
3758
4204
|
} : null;
|
|
3759
|
-
|
|
4205
|
+
|
|
4206
|
+
if ( notifySpy) {
|
|
4207
|
+
spyReportStart(change);
|
|
4208
|
+
}
|
|
4209
|
+
|
|
3760
4210
|
this.atom_.reportChanged(); // conform: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/observe
|
|
3761
4211
|
|
|
3762
|
-
if (notify)
|
|
3763
|
-
|
|
4212
|
+
if (notify) {
|
|
4213
|
+
notifyListeners(this, change);
|
|
4214
|
+
}
|
|
4215
|
+
|
|
4216
|
+
if ( notifySpy) {
|
|
4217
|
+
spyReportEnd();
|
|
4218
|
+
}
|
|
3764
4219
|
};
|
|
3765
4220
|
|
|
3766
4221
|
_proto.get_ = function get_(index) {
|
|
@@ -3787,7 +4242,11 @@
|
|
|
3787
4242
|
index: index,
|
|
3788
4243
|
newValue: newValue
|
|
3789
4244
|
});
|
|
3790
|
-
|
|
4245
|
+
|
|
4246
|
+
if (!change) {
|
|
4247
|
+
return;
|
|
4248
|
+
}
|
|
4249
|
+
|
|
3791
4250
|
newValue = change.newValue;
|
|
3792
4251
|
}
|
|
3793
4252
|
|
|
@@ -4071,7 +4530,10 @@
|
|
|
4071
4530
|
_proto.has = function has(key) {
|
|
4072
4531
|
var _this2 = this;
|
|
4073
4532
|
|
|
4074
|
-
if (!globalState.trackingDerivation)
|
|
4533
|
+
if (!globalState.trackingDerivation) {
|
|
4534
|
+
return this.has_(key);
|
|
4535
|
+
}
|
|
4536
|
+
|
|
4075
4537
|
var entry = this.hasMap_.get(key);
|
|
4076
4538
|
|
|
4077
4539
|
if (!entry) {
|
|
@@ -4095,7 +4557,11 @@
|
|
|
4095
4557
|
newValue: value,
|
|
4096
4558
|
name: key
|
|
4097
4559
|
});
|
|
4098
|
-
|
|
4560
|
+
|
|
4561
|
+
if (!change) {
|
|
4562
|
+
return this;
|
|
4563
|
+
}
|
|
4564
|
+
|
|
4099
4565
|
value = change.newValue;
|
|
4100
4566
|
}
|
|
4101
4567
|
|
|
@@ -4119,7 +4585,10 @@
|
|
|
4119
4585
|
object: this,
|
|
4120
4586
|
name: key
|
|
4121
4587
|
});
|
|
4122
|
-
|
|
4588
|
+
|
|
4589
|
+
if (!change) {
|
|
4590
|
+
return false;
|
|
4591
|
+
}
|
|
4123
4592
|
}
|
|
4124
4593
|
|
|
4125
4594
|
if (this.has_(key)) {
|
|
@@ -4135,7 +4604,10 @@
|
|
|
4135
4604
|
name: key
|
|
4136
4605
|
} : null;
|
|
4137
4606
|
|
|
4138
|
-
if ( notifySpy)
|
|
4607
|
+
if ( notifySpy) {
|
|
4608
|
+
spyReportStart(_change);
|
|
4609
|
+
} // TODO fix type
|
|
4610
|
+
|
|
4139
4611
|
|
|
4140
4612
|
transaction(function () {
|
|
4141
4613
|
var _this3$hasMap_$get;
|
|
@@ -4150,8 +4622,15 @@
|
|
|
4150
4622
|
|
|
4151
4623
|
_this3.data_["delete"](key);
|
|
4152
4624
|
});
|
|
4153
|
-
|
|
4154
|
-
if (
|
|
4625
|
+
|
|
4626
|
+
if (notify) {
|
|
4627
|
+
notifyListeners(this, _change);
|
|
4628
|
+
}
|
|
4629
|
+
|
|
4630
|
+
if ( notifySpy) {
|
|
4631
|
+
spyReportEnd();
|
|
4632
|
+
}
|
|
4633
|
+
|
|
4155
4634
|
return true;
|
|
4156
4635
|
}
|
|
4157
4636
|
|
|
@@ -4174,11 +4653,21 @@
|
|
|
4174
4653
|
name: key,
|
|
4175
4654
|
newValue: newValue
|
|
4176
4655
|
} : null;
|
|
4177
|
-
|
|
4656
|
+
|
|
4657
|
+
if ( notifySpy) {
|
|
4658
|
+
spyReportStart(change);
|
|
4659
|
+
} // TODO fix type
|
|
4660
|
+
|
|
4178
4661
|
|
|
4179
4662
|
observable.setNewValue_(newValue);
|
|
4180
|
-
|
|
4181
|
-
if (
|
|
4663
|
+
|
|
4664
|
+
if (notify) {
|
|
4665
|
+
notifyListeners(this, change);
|
|
4666
|
+
}
|
|
4667
|
+
|
|
4668
|
+
if ( notifySpy) {
|
|
4669
|
+
spyReportEnd();
|
|
4670
|
+
}
|
|
4182
4671
|
}
|
|
4183
4672
|
};
|
|
4184
4673
|
|
|
@@ -4209,14 +4698,26 @@
|
|
|
4209
4698
|
name: key,
|
|
4210
4699
|
newValue: newValue
|
|
4211
4700
|
} : null;
|
|
4212
|
-
if ( notifySpy) spyReportStart(change); // TODO fix type
|
|
4213
4701
|
|
|
4214
|
-
if (
|
|
4215
|
-
|
|
4702
|
+
if ( notifySpy) {
|
|
4703
|
+
spyReportStart(change);
|
|
4704
|
+
} // TODO fix type
|
|
4705
|
+
|
|
4706
|
+
|
|
4707
|
+
if (notify) {
|
|
4708
|
+
notifyListeners(this, change);
|
|
4709
|
+
}
|
|
4710
|
+
|
|
4711
|
+
if ( notifySpy) {
|
|
4712
|
+
spyReportEnd();
|
|
4713
|
+
}
|
|
4216
4714
|
};
|
|
4217
4715
|
|
|
4218
4716
|
_proto.get = function get(key) {
|
|
4219
|
-
if (this.has(key))
|
|
4717
|
+
if (this.has(key)) {
|
|
4718
|
+
return this.dehanceValue_(this.data_.get(key).get());
|
|
4719
|
+
}
|
|
4720
|
+
|
|
4220
4721
|
return this.dehanceValue_(undefined);
|
|
4221
4722
|
};
|
|
4222
4723
|
|
|
@@ -4290,18 +4791,27 @@
|
|
|
4290
4791
|
}
|
|
4291
4792
|
|
|
4292
4793
|
transaction(function () {
|
|
4293
|
-
if (isPlainObject(other))
|
|
4294
|
-
|
|
4295
|
-
|
|
4296
|
-
|
|
4297
|
-
|
|
4298
|
-
|
|
4299
|
-
|
|
4300
|
-
|
|
4794
|
+
if (isPlainObject(other)) {
|
|
4795
|
+
getPlainObjectKeys(other).forEach(function (key) {
|
|
4796
|
+
return _this5.set(key, other[key]);
|
|
4797
|
+
});
|
|
4798
|
+
} else if (Array.isArray(other)) {
|
|
4799
|
+
other.forEach(function (_ref) {
|
|
4800
|
+
var key = _ref[0],
|
|
4801
|
+
value = _ref[1];
|
|
4802
|
+
return _this5.set(key, value);
|
|
4803
|
+
});
|
|
4804
|
+
} else if (isES6Map(other)) {
|
|
4805
|
+
if (other.constructor !== Map) {
|
|
4806
|
+
die(19, other);
|
|
4807
|
+
}
|
|
4808
|
+
|
|
4301
4809
|
other.forEach(function (value, key) {
|
|
4302
4810
|
return _this5.set(key, value);
|
|
4303
4811
|
});
|
|
4304
|
-
} else if (other !== null && other !== undefined)
|
|
4812
|
+
} else if (other !== null && other !== undefined) {
|
|
4813
|
+
die(20, other);
|
|
4814
|
+
}
|
|
4305
4815
|
});
|
|
4306
4816
|
return this;
|
|
4307
4817
|
};
|
|
@@ -4432,7 +4942,10 @@
|
|
|
4432
4942
|
* for callback details
|
|
4433
4943
|
*/
|
|
4434
4944
|
_proto.observe_ = function observe_(listener, fireImmediately) {
|
|
4435
|
-
if ( fireImmediately === true)
|
|
4945
|
+
if ( fireImmediately === true) {
|
|
4946
|
+
die("`observe` doesn't support fireImmediately=true in combination with maps.");
|
|
4947
|
+
}
|
|
4948
|
+
|
|
4436
4949
|
return registerListener(this, listener);
|
|
4437
4950
|
};
|
|
4438
4951
|
|
|
@@ -4557,8 +5070,12 @@
|
|
|
4557
5070
|
object: this,
|
|
4558
5071
|
newValue: value
|
|
4559
5072
|
});
|
|
4560
|
-
|
|
5073
|
+
|
|
5074
|
+
if (!change) {
|
|
5075
|
+
return this;
|
|
5076
|
+
} // ideally, value = change.value would be done here, so that values can be
|
|
4561
5077
|
// changed by interceptor. Same applies for other Set and Map api's.
|
|
5078
|
+
|
|
4562
5079
|
}
|
|
4563
5080
|
|
|
4564
5081
|
if (!this.has(value)) {
|
|
@@ -4578,9 +5095,17 @@
|
|
|
4578
5095
|
newValue: value
|
|
4579
5096
|
} : null;
|
|
4580
5097
|
|
|
4581
|
-
if (notifySpy && "development" !== "production")
|
|
4582
|
-
|
|
4583
|
-
|
|
5098
|
+
if (notifySpy && "development" !== "production") {
|
|
5099
|
+
spyReportStart(_change);
|
|
5100
|
+
}
|
|
5101
|
+
|
|
5102
|
+
if (notify) {
|
|
5103
|
+
notifyListeners(this, _change);
|
|
5104
|
+
}
|
|
5105
|
+
|
|
5106
|
+
if (notifySpy && "development" !== "production") {
|
|
5107
|
+
spyReportEnd();
|
|
5108
|
+
}
|
|
4584
5109
|
}
|
|
4585
5110
|
|
|
4586
5111
|
return this;
|
|
@@ -4595,7 +5120,10 @@
|
|
|
4595
5120
|
object: this,
|
|
4596
5121
|
oldValue: value
|
|
4597
5122
|
});
|
|
4598
|
-
|
|
5123
|
+
|
|
5124
|
+
if (!change) {
|
|
5125
|
+
return false;
|
|
5126
|
+
}
|
|
4599
5127
|
}
|
|
4600
5128
|
|
|
4601
5129
|
if (this.has(value)) {
|
|
@@ -4610,14 +5138,24 @@
|
|
|
4610
5138
|
oldValue: value
|
|
4611
5139
|
} : null;
|
|
4612
5140
|
|
|
4613
|
-
if (notifySpy && "development" !== "production")
|
|
5141
|
+
if (notifySpy && "development" !== "production") {
|
|
5142
|
+
spyReportStart(_change2);
|
|
5143
|
+
}
|
|
5144
|
+
|
|
4614
5145
|
transaction(function () {
|
|
4615
5146
|
_this3.atom_.reportChanged();
|
|
4616
5147
|
|
|
4617
5148
|
_this3.data_["delete"](value);
|
|
4618
5149
|
});
|
|
4619
|
-
|
|
4620
|
-
if (
|
|
5150
|
+
|
|
5151
|
+
if (notify) {
|
|
5152
|
+
notifyListeners(this, _change2);
|
|
5153
|
+
}
|
|
5154
|
+
|
|
5155
|
+
if (notifySpy && "development" !== "production") {
|
|
5156
|
+
spyReportEnd();
|
|
5157
|
+
}
|
|
5158
|
+
|
|
4621
5159
|
return true;
|
|
4622
5160
|
}
|
|
4623
5161
|
|
|
@@ -4697,7 +5235,10 @@
|
|
|
4697
5235
|
|
|
4698
5236
|
_proto.observe_ = function observe_(listener, fireImmediately) {
|
|
4699
5237
|
// ... 'fireImmediately' could also be true?
|
|
4700
|
-
if ( fireImmediately === true)
|
|
5238
|
+
if ( fireImmediately === true) {
|
|
5239
|
+
die("`observe` doesn't support fireImmediately=true in combination with sets.");
|
|
5240
|
+
}
|
|
5241
|
+
|
|
4701
5242
|
return registerListener(this, listener);
|
|
4702
5243
|
};
|
|
4703
5244
|
|
|
@@ -4799,7 +5340,11 @@
|
|
|
4799
5340
|
name: key,
|
|
4800
5341
|
newValue: newValue
|
|
4801
5342
|
});
|
|
4802
|
-
|
|
5343
|
+
|
|
5344
|
+
if (!change) {
|
|
5345
|
+
return null;
|
|
5346
|
+
}
|
|
5347
|
+
|
|
4803
5348
|
newValue = change.newValue;
|
|
4804
5349
|
}
|
|
4805
5350
|
|
|
@@ -4819,10 +5364,18 @@
|
|
|
4819
5364
|
newValue: newValue
|
|
4820
5365
|
} : null;
|
|
4821
5366
|
|
|
4822
|
-
if ( notifySpy)
|
|
5367
|
+
if ( notifySpy) {
|
|
5368
|
+
spyReportStart(_change);
|
|
5369
|
+
}
|
|
4823
5370
|
observable.setNewValue_(newValue);
|
|
4824
|
-
|
|
4825
|
-
if (
|
|
5371
|
+
|
|
5372
|
+
if (notify) {
|
|
5373
|
+
notifyListeners(this, _change);
|
|
5374
|
+
}
|
|
5375
|
+
|
|
5376
|
+
if ( notifySpy) {
|
|
5377
|
+
spyReportEnd();
|
|
5378
|
+
}
|
|
4826
5379
|
}
|
|
4827
5380
|
|
|
4828
5381
|
return true;
|
|
@@ -4931,12 +5484,18 @@
|
|
|
4931
5484
|
|
|
4932
5485
|
if (descriptor) {
|
|
4933
5486
|
var outcome = annotation.make_(this, key, descriptor, source);
|
|
5487
|
+
|
|
4934
5488
|
if (outcome === 0
|
|
4935
5489
|
/* Cancel */
|
|
4936
|
-
)
|
|
5490
|
+
) {
|
|
5491
|
+
return;
|
|
5492
|
+
}
|
|
5493
|
+
|
|
4937
5494
|
if (outcome === 1
|
|
4938
5495
|
/* Break */
|
|
4939
|
-
)
|
|
5496
|
+
) {
|
|
5497
|
+
break;
|
|
5498
|
+
}
|
|
4940
5499
|
}
|
|
4941
5500
|
|
|
4942
5501
|
source = Object.getPrototypeOf(source);
|
|
@@ -5006,7 +5565,11 @@
|
|
|
5006
5565
|
type: ADD,
|
|
5007
5566
|
newValue: descriptor.value
|
|
5008
5567
|
});
|
|
5009
|
-
|
|
5568
|
+
|
|
5569
|
+
if (!change) {
|
|
5570
|
+
return null;
|
|
5571
|
+
}
|
|
5572
|
+
|
|
5010
5573
|
var newValue = change.newValue;
|
|
5011
5574
|
|
|
5012
5575
|
if (descriptor.value !== newValue) {
|
|
@@ -5058,7 +5621,11 @@
|
|
|
5058
5621
|
type: ADD,
|
|
5059
5622
|
newValue: value
|
|
5060
5623
|
});
|
|
5061
|
-
|
|
5624
|
+
|
|
5625
|
+
if (!change) {
|
|
5626
|
+
return null;
|
|
5627
|
+
}
|
|
5628
|
+
|
|
5062
5629
|
value = change.newValue;
|
|
5063
5630
|
}
|
|
5064
5631
|
|
|
@@ -5113,7 +5680,10 @@
|
|
|
5113
5680
|
type: ADD,
|
|
5114
5681
|
newValue: undefined
|
|
5115
5682
|
});
|
|
5116
|
-
|
|
5683
|
+
|
|
5684
|
+
if (!change) {
|
|
5685
|
+
return null;
|
|
5686
|
+
}
|
|
5117
5687
|
}
|
|
5118
5688
|
|
|
5119
5689
|
options.name || (options.name = "development" !== "production" ? this.name_ + "." + key.toString() : "ObservableObject.key");
|
|
@@ -5169,7 +5739,9 @@
|
|
|
5169
5739
|
type: REMOVE
|
|
5170
5740
|
}); // Cancelled
|
|
5171
5741
|
|
|
5172
|
-
if (!change)
|
|
5742
|
+
if (!change) {
|
|
5743
|
+
return null;
|
|
5744
|
+
}
|
|
5173
5745
|
} // Delete
|
|
5174
5746
|
|
|
5175
5747
|
|
|
@@ -5230,9 +5802,18 @@
|
|
|
5230
5802
|
oldValue: value,
|
|
5231
5803
|
name: key
|
|
5232
5804
|
};
|
|
5233
|
-
|
|
5234
|
-
if (
|
|
5235
|
-
|
|
5805
|
+
|
|
5806
|
+
if ("development" !== "production" && notifySpy) {
|
|
5807
|
+
spyReportStart(_change2);
|
|
5808
|
+
}
|
|
5809
|
+
|
|
5810
|
+
if (notify) {
|
|
5811
|
+
notifyListeners(this, _change2);
|
|
5812
|
+
}
|
|
5813
|
+
|
|
5814
|
+
if ("development" !== "production" && notifySpy) {
|
|
5815
|
+
spyReportEnd();
|
|
5816
|
+
}
|
|
5236
5817
|
}
|
|
5237
5818
|
} finally {
|
|
5238
5819
|
endBatch();
|
|
@@ -5248,7 +5829,10 @@
|
|
|
5248
5829
|
;
|
|
5249
5830
|
|
|
5250
5831
|
_proto.observe_ = function observe_(callback, fireImmediately) {
|
|
5251
|
-
if ( fireImmediately === true)
|
|
5832
|
+
if ( fireImmediately === true) {
|
|
5833
|
+
die("`observe` doesn't support the fire immediately property for observable objects.");
|
|
5834
|
+
}
|
|
5835
|
+
|
|
5252
5836
|
return registerListener(this, callback);
|
|
5253
5837
|
};
|
|
5254
5838
|
|
|
@@ -5271,9 +5855,18 @@
|
|
|
5271
5855
|
name: key,
|
|
5272
5856
|
newValue: value
|
|
5273
5857
|
} : null;
|
|
5274
|
-
|
|
5275
|
-
if (
|
|
5276
|
-
|
|
5858
|
+
|
|
5859
|
+
if ( notifySpy) {
|
|
5860
|
+
spyReportStart(change);
|
|
5861
|
+
}
|
|
5862
|
+
|
|
5863
|
+
if (notify) {
|
|
5864
|
+
notifyListeners(this, change);
|
|
5865
|
+
}
|
|
5866
|
+
|
|
5867
|
+
if ( notifySpy) {
|
|
5868
|
+
spyReportEnd();
|
|
5869
|
+
}
|
|
5277
5870
|
}
|
|
5278
5871
|
|
|
5279
5872
|
(_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
|
|
@@ -5314,7 +5907,10 @@
|
|
|
5314
5907
|
return target;
|
|
5315
5908
|
}
|
|
5316
5909
|
|
|
5317
|
-
if ( !Object.isExtensible(target))
|
|
5910
|
+
if ( !Object.isExtensible(target)) {
|
|
5911
|
+
die("Cannot make the designated object observable; it is not extensible");
|
|
5912
|
+
}
|
|
5913
|
+
|
|
5318
5914
|
var name = (_options$name = options == null ? void 0 : options.name) != null ? _options$name : (isPlainObject(target) ? "ObservableObject" : target.constructor.name) + "@" + getNextId() ;
|
|
5319
5915
|
var adm = new ObservableObjectAdministration(target, new Map(), String(name), getAnnotationFromOptions(options));
|
|
5320
5916
|
addHiddenProp(target, $mobx, adm);
|
|
@@ -5471,7 +6067,6 @@
|
|
|
5471
6067
|
var nextIndex = 0;
|
|
5472
6068
|
return makeIterable({
|
|
5473
6069
|
next: function next() {
|
|
5474
|
-
// @ts-ignore
|
|
5475
6070
|
return nextIndex < self.length ? {
|
|
5476
6071
|
value: self[nextIndex++],
|
|
5477
6072
|
done: false
|
|
@@ -5504,7 +6099,10 @@
|
|
|
5504
6099
|
Object.entries(arrayExtensions).forEach(function (_ref) {
|
|
5505
6100
|
var prop = _ref[0],
|
|
5506
6101
|
fn = _ref[1];
|
|
5507
|
-
|
|
6102
|
+
|
|
6103
|
+
if (prop !== "concat") {
|
|
6104
|
+
addHiddenProp(LegacyObservableArray.prototype, prop, fn);
|
|
6105
|
+
}
|
|
5508
6106
|
});
|
|
5509
6107
|
|
|
5510
6108
|
function createArrayEntryDescriptor(index) {
|
|
@@ -5541,7 +6139,10 @@
|
|
|
5541
6139
|
function getAtom(thing, property) {
|
|
5542
6140
|
if (typeof thing === "object" && thing !== null) {
|
|
5543
6141
|
if (isObservableArray(thing)) {
|
|
5544
|
-
if (property !== undefined)
|
|
6142
|
+
if (property !== undefined) {
|
|
6143
|
+
die(23);
|
|
6144
|
+
}
|
|
6145
|
+
|
|
5545
6146
|
return thing[$mobx].atom_;
|
|
5546
6147
|
}
|
|
5547
6148
|
|
|
@@ -5550,18 +6151,31 @@
|
|
|
5550
6151
|
}
|
|
5551
6152
|
|
|
5552
6153
|
if (isObservableMap(thing)) {
|
|
5553
|
-
if (property === undefined)
|
|
6154
|
+
if (property === undefined) {
|
|
6155
|
+
return thing.keysAtom_;
|
|
6156
|
+
}
|
|
6157
|
+
|
|
5554
6158
|
var observable = thing.data_.get(property) || thing.hasMap_.get(property);
|
|
5555
|
-
|
|
6159
|
+
|
|
6160
|
+
if (!observable) {
|
|
6161
|
+
die(25, property, getDebugName(thing));
|
|
6162
|
+
}
|
|
6163
|
+
|
|
5556
6164
|
return observable;
|
|
5557
6165
|
}
|
|
5558
6166
|
|
|
6167
|
+
|
|
5559
6168
|
if (isObservableObject(thing)) {
|
|
5560
|
-
if (!property)
|
|
6169
|
+
if (!property) {
|
|
6170
|
+
return die(26);
|
|
6171
|
+
}
|
|
5561
6172
|
|
|
5562
6173
|
var _observable = thing[$mobx].values_.get(property);
|
|
5563
6174
|
|
|
5564
|
-
if (!_observable)
|
|
6175
|
+
if (!_observable) {
|
|
6176
|
+
die(27, property, getDebugName(thing));
|
|
6177
|
+
}
|
|
6178
|
+
|
|
5565
6179
|
return _observable;
|
|
5566
6180
|
}
|
|
5567
6181
|
|
|
@@ -5578,11 +6192,26 @@
|
|
|
5578
6192
|
die(28);
|
|
5579
6193
|
}
|
|
5580
6194
|
function getAdministration(thing, property) {
|
|
5581
|
-
if (!thing)
|
|
5582
|
-
|
|
5583
|
-
|
|
5584
|
-
|
|
5585
|
-
if (
|
|
6195
|
+
if (!thing) {
|
|
6196
|
+
die(29);
|
|
6197
|
+
}
|
|
6198
|
+
|
|
6199
|
+
if (property !== undefined) {
|
|
6200
|
+
return getAdministration(getAtom(thing, property));
|
|
6201
|
+
}
|
|
6202
|
+
|
|
6203
|
+
if (isAtom(thing) || isComputedValue(thing) || isReaction(thing)) {
|
|
6204
|
+
return thing;
|
|
6205
|
+
}
|
|
6206
|
+
|
|
6207
|
+
if (isObservableMap(thing) || isObservableSet(thing)) {
|
|
6208
|
+
return thing;
|
|
6209
|
+
}
|
|
6210
|
+
|
|
6211
|
+
if (thing[$mobx]) {
|
|
6212
|
+
return thing[$mobx];
|
|
6213
|
+
}
|
|
6214
|
+
|
|
5586
6215
|
die(24, thing);
|
|
5587
6216
|
}
|
|
5588
6217
|
function getDebugName(thing, property) {
|
|
@@ -5615,17 +6244,33 @@
|
|
|
5615
6244
|
function eq(a, b, depth, aStack, bStack) {
|
|
5616
6245
|
// Identical objects are equal. `0 === -0`, but they aren't identical.
|
|
5617
6246
|
// See the [Harmony `egal` proposal](http://wiki.ecmascript.org/doku.php?id=harmony:egal).
|
|
5618
|
-
if (a === b)
|
|
6247
|
+
if (a === b) {
|
|
6248
|
+
return a !== 0 || 1 / a === 1 / b;
|
|
6249
|
+
} // `null` or `undefined` only equal to itself (strict comparison).
|
|
6250
|
+
|
|
6251
|
+
|
|
6252
|
+
if (a == null || b == null) {
|
|
6253
|
+
return false;
|
|
6254
|
+
} // `NaN`s are equivalent, but non-reflexive.
|
|
6255
|
+
|
|
5619
6256
|
|
|
5620
|
-
if (a
|
|
6257
|
+
if (a !== a) {
|
|
6258
|
+
return b !== b;
|
|
6259
|
+
} // Exhaust primitive checks
|
|
5621
6260
|
|
|
5622
|
-
if (a !== a) return b !== b; // Exhaust primitive checks
|
|
5623
6261
|
|
|
5624
6262
|
var type = typeof a;
|
|
5625
|
-
|
|
6263
|
+
|
|
6264
|
+
if (type !== "function" && type !== "object" && typeof b != "object") {
|
|
6265
|
+
return false;
|
|
6266
|
+
} // Compare `[[Class]]` names.
|
|
6267
|
+
|
|
5626
6268
|
|
|
5627
6269
|
var className = toString.call(a);
|
|
5628
|
-
|
|
6270
|
+
|
|
6271
|
+
if (className !== toString.call(b)) {
|
|
6272
|
+
return false;
|
|
6273
|
+
}
|
|
5629
6274
|
|
|
5630
6275
|
switch (className) {
|
|
5631
6276
|
// Strings, numbers, regular expressions, dates, and booleans are compared by value.
|
|
@@ -5639,7 +6284,10 @@
|
|
|
5639
6284
|
case "[object Number]":
|
|
5640
6285
|
// `NaN`s are equivalent, but non-reflexive.
|
|
5641
6286
|
// Object(NaN) is equivalent to NaN.
|
|
5642
|
-
if (+a !== +a)
|
|
6287
|
+
if (+a !== +a) {
|
|
6288
|
+
return +b !== +b;
|
|
6289
|
+
} // An `egal` comparison is performed for other numeric values.
|
|
6290
|
+
|
|
5643
6291
|
|
|
5644
6292
|
return +a === 0 ? 1 / +a === 1 / b : +a === +b;
|
|
5645
6293
|
|
|
@@ -5670,9 +6318,12 @@
|
|
|
5670
6318
|
var areArrays = className === "[object Array]";
|
|
5671
6319
|
|
|
5672
6320
|
if (!areArrays) {
|
|
5673
|
-
if (typeof a != "object" || typeof b != "object")
|
|
6321
|
+
if (typeof a != "object" || typeof b != "object") {
|
|
6322
|
+
return false;
|
|
6323
|
+
} // Objects with different constructors are not equivalent, but `Object`s or `Array`s
|
|
5674
6324
|
// from different frames are.
|
|
5675
6325
|
|
|
6326
|
+
|
|
5676
6327
|
var aCtor = a.constructor,
|
|
5677
6328
|
bCtor = b.constructor;
|
|
5678
6329
|
|
|
@@ -5698,7 +6349,9 @@
|
|
|
5698
6349
|
while (length--) {
|
|
5699
6350
|
// Linear search. Performance is inversely proportional to the number of
|
|
5700
6351
|
// unique nested structures.
|
|
5701
|
-
if (aStack[length] === a)
|
|
6352
|
+
if (aStack[length] === a) {
|
|
6353
|
+
return bStack[length] === b;
|
|
6354
|
+
}
|
|
5702
6355
|
} // Add the first object to the stack of traversed objects.
|
|
5703
6356
|
|
|
5704
6357
|
|
|
@@ -5708,10 +6361,16 @@
|
|
|
5708
6361
|
if (areArrays) {
|
|
5709
6362
|
// Compare array lengths to determine if a deep comparison is necessary.
|
|
5710
6363
|
length = a.length;
|
|
5711
|
-
|
|
6364
|
+
|
|
6365
|
+
if (length !== b.length) {
|
|
6366
|
+
return false;
|
|
6367
|
+
} // Deep compare the contents, ignoring non-numeric properties.
|
|
6368
|
+
|
|
5712
6369
|
|
|
5713
6370
|
while (length--) {
|
|
5714
|
-
if (!eq(a[length], b[length], depth - 1, aStack, bStack))
|
|
6371
|
+
if (!eq(a[length], b[length], depth - 1, aStack, bStack)) {
|
|
6372
|
+
return false;
|
|
6373
|
+
}
|
|
5715
6374
|
}
|
|
5716
6375
|
} else {
|
|
5717
6376
|
// Deep compare objects.
|
|
@@ -5719,12 +6378,17 @@
|
|
|
5719
6378
|
var key;
|
|
5720
6379
|
length = keys.length; // Ensure that both objects contain the same number of properties before comparing deep equality.
|
|
5721
6380
|
|
|
5722
|
-
if (Object.keys(b).length !== length)
|
|
6381
|
+
if (Object.keys(b).length !== length) {
|
|
6382
|
+
return false;
|
|
6383
|
+
}
|
|
5723
6384
|
|
|
5724
6385
|
while (length--) {
|
|
5725
6386
|
// Deep compare each member
|
|
5726
6387
|
key = keys[length];
|
|
5727
|
-
|
|
6388
|
+
|
|
6389
|
+
if (!(hasProp(b, key) && eq(a[key], b[key], depth - 1, aStack, bStack))) {
|
|
6390
|
+
return false;
|
|
6391
|
+
}
|
|
5728
6392
|
}
|
|
5729
6393
|
} // Remove the first object from the stack of traversed objects.
|
|
5730
6394
|
|
|
@@ -5735,9 +6399,18 @@
|
|
|
5735
6399
|
}
|
|
5736
6400
|
|
|
5737
6401
|
function unwrap(a) {
|
|
5738
|
-
if (isObservableArray(a))
|
|
5739
|
-
|
|
5740
|
-
|
|
6402
|
+
if (isObservableArray(a)) {
|
|
6403
|
+
return a.slice();
|
|
6404
|
+
}
|
|
6405
|
+
|
|
6406
|
+
if (isES6Map(a) || isObservableMap(a)) {
|
|
6407
|
+
return Array.from(a.entries());
|
|
6408
|
+
}
|
|
6409
|
+
|
|
6410
|
+
if (isES6Set(a) || isObservableSet(a)) {
|
|
6411
|
+
return Array.from(a.entries());
|
|
6412
|
+
}
|
|
6413
|
+
|
|
5741
6414
|
return a;
|
|
5742
6415
|
}
|
|
5743
6416
|
|