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
|
@@ -27,9 +27,9 @@ var niceErrors = {
|
|
|
27
27
|
10: "'has()' can only be used on observable objects, arrays and maps",
|
|
28
28
|
11: "'get()' can only be used on observable objects, arrays and maps",
|
|
29
29
|
12: "Invalid annotation",
|
|
30
|
-
13: "Dynamic observable objects cannot be frozen",
|
|
30
|
+
13: "Dynamic observable objects cannot be frozen. If you're passing observables to 3rd party component/function that calls Object.freeze, pass copy instead: toJS(observable)",
|
|
31
31
|
14: "Intercept handlers should return nothing or a change object",
|
|
32
|
-
15: "Observable arrays cannot be frozen",
|
|
32
|
+
15: "Observable arrays cannot be frozen. If you're passing observables to 3rd party component/function that calls Object.freeze, pass copy instead: toJS(observable)",
|
|
33
33
|
16: "Modification exception: the internal structure of an observable array was changed.",
|
|
34
34
|
17: function _(index, length) {
|
|
35
35
|
return "[mobx.array] Index out of bounds, " + index + " is larger than " + length;
|
|
@@ -143,7 +143,10 @@ function getNextId() {
|
|
|
143
143
|
function once(func) {
|
|
144
144
|
var invoked = false;
|
|
145
145
|
return function () {
|
|
146
|
-
if (invoked)
|
|
146
|
+
if (invoked) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
|
|
147
150
|
invoked = true;
|
|
148
151
|
return func.apply(this, arguments);
|
|
149
152
|
};
|
|
@@ -168,17 +171,31 @@ function isObject(value) {
|
|
|
168
171
|
return value !== null && typeof value === "object";
|
|
169
172
|
}
|
|
170
173
|
function isPlainObject(value) {
|
|
171
|
-
if (!isObject(value))
|
|
174
|
+
if (!isObject(value)) {
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
|
|
172
178
|
var proto = Object.getPrototypeOf(value);
|
|
173
|
-
|
|
179
|
+
|
|
180
|
+
if (proto == null) {
|
|
181
|
+
return true;
|
|
182
|
+
}
|
|
183
|
+
|
|
174
184
|
var protoConstructor = Object.hasOwnProperty.call(proto, "constructor") && proto.constructor;
|
|
175
185
|
return typeof protoConstructor === "function" && protoConstructor.toString() === plainObjectString;
|
|
176
186
|
} // https://stackoverflow.com/a/37865170
|
|
177
187
|
|
|
178
188
|
function isGenerator(obj) {
|
|
179
189
|
var constructor = obj == null ? void 0 : obj.constructor;
|
|
180
|
-
|
|
181
|
-
if (
|
|
190
|
+
|
|
191
|
+
if (!constructor) {
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if ("GeneratorFunction" === constructor.name || "GeneratorFunction" === constructor.displayName) {
|
|
196
|
+
return true;
|
|
197
|
+
}
|
|
198
|
+
|
|
182
199
|
return false;
|
|
183
200
|
}
|
|
184
201
|
function addHiddenProp(object, propName, value) {
|
|
@@ -218,9 +235,16 @@ var hasGetOwnPropertySymbols = typeof Object.getOwnPropertySymbols !== "undefine
|
|
|
218
235
|
function getPlainObjectKeys(object) {
|
|
219
236
|
var keys = Object.keys(object); // Not supported in IE, so there are not going to be symbol props anyway...
|
|
220
237
|
|
|
221
|
-
if (!hasGetOwnPropertySymbols)
|
|
238
|
+
if (!hasGetOwnPropertySymbols) {
|
|
239
|
+
return keys;
|
|
240
|
+
}
|
|
241
|
+
|
|
222
242
|
var symbols = Object.getOwnPropertySymbols(object);
|
|
223
|
-
|
|
243
|
+
|
|
244
|
+
if (!symbols.length) {
|
|
245
|
+
return keys;
|
|
246
|
+
}
|
|
247
|
+
|
|
224
248
|
return [].concat(keys, symbols.filter(function (s) {
|
|
225
249
|
return objectPrototype.propertyIsEnumerable.call(object, s);
|
|
226
250
|
}));
|
|
@@ -233,8 +257,14 @@ var ownKeys = typeof Reflect !== "undefined" && Reflect.ownKeys ? Reflect.ownKey
|
|
|
233
257
|
/* istanbul ignore next */
|
|
234
258
|
Object.getOwnPropertyNames;
|
|
235
259
|
function stringifyKey(key) {
|
|
236
|
-
if (typeof key === "string")
|
|
237
|
-
|
|
260
|
+
if (typeof key === "string") {
|
|
261
|
+
return key;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if (typeof key === "symbol") {
|
|
265
|
+
return key.toString();
|
|
266
|
+
}
|
|
267
|
+
|
|
238
268
|
return new String(key).toString();
|
|
239
269
|
}
|
|
240
270
|
function toPrimitive(value) {
|
|
@@ -522,7 +552,10 @@ function shallowComparer(a, b) {
|
|
|
522
552
|
}
|
|
523
553
|
|
|
524
554
|
function defaultComparer(a, b) {
|
|
525
|
-
if (Object.is)
|
|
555
|
+
if (Object.is) {
|
|
556
|
+
return Object.is(a, b);
|
|
557
|
+
}
|
|
558
|
+
|
|
526
559
|
return a === b ? a !== 0 || 1 / a === 1 / b : a !== a && b !== b;
|
|
527
560
|
}
|
|
528
561
|
|
|
@@ -535,20 +568,34 @@ var comparer = {
|
|
|
535
568
|
|
|
536
569
|
function deepEnhancer(v, _, name) {
|
|
537
570
|
// it is an observable already, done
|
|
538
|
-
if (isObservable(v))
|
|
571
|
+
if (isObservable(v)) {
|
|
572
|
+
return v;
|
|
573
|
+
} // something that can be converted and mutated?
|
|
539
574
|
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
}
|
|
575
|
+
|
|
576
|
+
if (Array.isArray(v)) {
|
|
577
|
+
return observable.array(v, {
|
|
578
|
+
name: name
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
if (isPlainObject(v)) {
|
|
583
|
+
return observable.object(v, undefined, {
|
|
584
|
+
name: name
|
|
585
|
+
});
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
if (isES6Map(v)) {
|
|
589
|
+
return observable.map(v, {
|
|
590
|
+
name: name
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
if (isES6Set(v)) {
|
|
595
|
+
return observable.set(v, {
|
|
596
|
+
name: name
|
|
597
|
+
});
|
|
598
|
+
}
|
|
552
599
|
|
|
553
600
|
if (typeof v === "function" && !isAction(v) && !isFlow(v)) {
|
|
554
601
|
if (isGenerator(v)) {
|
|
@@ -561,33 +608,59 @@ function deepEnhancer(v, _, name) {
|
|
|
561
608
|
return v;
|
|
562
609
|
}
|
|
563
610
|
function shallowEnhancer(v, _, name) {
|
|
564
|
-
if (v === undefined || v === null)
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
611
|
+
if (v === undefined || v === null) {
|
|
612
|
+
return v;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
if (isObservableObject(v) || isObservableArray(v) || isObservableMap(v) || isObservableSet(v)) {
|
|
616
|
+
return v;
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
if (Array.isArray(v)) {
|
|
620
|
+
return observable.array(v, {
|
|
621
|
+
name: name,
|
|
622
|
+
deep: false
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
if (isPlainObject(v)) {
|
|
627
|
+
return observable.object(v, undefined, {
|
|
628
|
+
name: name,
|
|
629
|
+
deep: false
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
if (isES6Map(v)) {
|
|
634
|
+
return observable.map(v, {
|
|
635
|
+
name: name,
|
|
636
|
+
deep: false
|
|
637
|
+
});
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
if (isES6Set(v)) {
|
|
641
|
+
return observable.set(v, {
|
|
642
|
+
name: name,
|
|
643
|
+
deep: false
|
|
644
|
+
});
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
{
|
|
648
|
+
die("The shallow modifier / decorator can only used in combination with arrays, objects, maps and sets");
|
|
649
|
+
}
|
|
583
650
|
}
|
|
584
651
|
function referenceEnhancer(newValue) {
|
|
585
652
|
// never turn into an observable
|
|
586
653
|
return newValue;
|
|
587
654
|
}
|
|
588
655
|
function refStructEnhancer(v, oldValue) {
|
|
589
|
-
if ( isObservable(v))
|
|
590
|
-
|
|
656
|
+
if ( isObservable(v)) {
|
|
657
|
+
die("observable.struct should not be used with observable values");
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
if (deepEqual(v, oldValue)) {
|
|
661
|
+
return oldValue;
|
|
662
|
+
}
|
|
663
|
+
|
|
591
664
|
return v;
|
|
592
665
|
}
|
|
593
666
|
|
|
@@ -736,9 +809,11 @@ function make_$2(adm, key, descriptor, source) {
|
|
|
736
809
|
|
|
737
810
|
|
|
738
811
|
if ((_this$options_ = this.options_) != null && _this$options_.bound && (!hasProp(adm.target_, key) || !isFlow(adm.target_[key]))) {
|
|
739
|
-
if (this.extend_(adm, key, descriptor, false) === null)
|
|
740
|
-
|
|
741
|
-
|
|
812
|
+
if (this.extend_(adm, key, descriptor, false) === null) {
|
|
813
|
+
return 0
|
|
814
|
+
/* Cancel */
|
|
815
|
+
;
|
|
816
|
+
}
|
|
742
817
|
}
|
|
743
818
|
|
|
744
819
|
if (isFlow(descriptor.value)) {
|
|
@@ -1029,17 +1104,35 @@ function createObservable(v, arg2, arg3) {
|
|
|
1029
1104
|
} // already observable - ignore
|
|
1030
1105
|
|
|
1031
1106
|
|
|
1032
|
-
if (isObservable(v))
|
|
1107
|
+
if (isObservable(v)) {
|
|
1108
|
+
return v;
|
|
1109
|
+
} // plain object
|
|
1110
|
+
|
|
1111
|
+
|
|
1112
|
+
if (isPlainObject(v)) {
|
|
1113
|
+
return observable.object(v, arg2, arg3);
|
|
1114
|
+
} // Array
|
|
1115
|
+
|
|
1116
|
+
|
|
1117
|
+
if (Array.isArray(v)) {
|
|
1118
|
+
return observable.array(v, arg2);
|
|
1119
|
+
} // Map
|
|
1120
|
+
|
|
1033
1121
|
|
|
1034
|
-
if (
|
|
1122
|
+
if (isES6Map(v)) {
|
|
1123
|
+
return observable.map(v, arg2);
|
|
1124
|
+
} // Set
|
|
1035
1125
|
|
|
1036
|
-
if (Array.isArray(v)) return observable.array(v, arg2); // Map
|
|
1037
1126
|
|
|
1038
|
-
if (
|
|
1127
|
+
if (isES6Set(v)) {
|
|
1128
|
+
return observable.set(v, arg2);
|
|
1129
|
+
} // other object - ignore
|
|
1039
1130
|
|
|
1040
|
-
if (isES6Set(v)) return observable.set(v, arg2); // other object - ignore
|
|
1041
1131
|
|
|
1042
|
-
if (typeof v === "object" && v !== null)
|
|
1132
|
+
if (typeof v === "object" && v !== null) {
|
|
1133
|
+
return v;
|
|
1134
|
+
} // anything else
|
|
1135
|
+
|
|
1043
1136
|
|
|
1044
1137
|
return observable.box(v, arg2);
|
|
1045
1138
|
}
|
|
@@ -1097,8 +1190,13 @@ var computed = function computed(arg1, arg2) {
|
|
|
1097
1190
|
|
|
1098
1191
|
|
|
1099
1192
|
{
|
|
1100
|
-
if (!isFunction(arg1))
|
|
1101
|
-
|
|
1193
|
+
if (!isFunction(arg1)) {
|
|
1194
|
+
die("First argument to `computed` should be an expression.");
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
if (isFunction(arg2)) {
|
|
1198
|
+
die("A setter as second argument is no longer supported, use `{ set: fn }` option instead");
|
|
1199
|
+
}
|
|
1102
1200
|
}
|
|
1103
1201
|
|
|
1104
1202
|
var opts = isPlainObject(arg2) ? arg2 : {};
|
|
@@ -1130,8 +1228,13 @@ function createAction(actionName, fn, autoAction, ref) {
|
|
|
1130
1228
|
}
|
|
1131
1229
|
|
|
1132
1230
|
{
|
|
1133
|
-
if (!isFunction(fn))
|
|
1134
|
-
|
|
1231
|
+
if (!isFunction(fn)) {
|
|
1232
|
+
die("`action` can only be invoked on functions");
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
if (typeof actionName !== "string" || !actionName) {
|
|
1236
|
+
die("actions should have valid names, got: '" + actionName + "'");
|
|
1237
|
+
}
|
|
1135
1238
|
}
|
|
1136
1239
|
|
|
1137
1240
|
function res() {
|
|
@@ -1213,7 +1316,10 @@ function _endAction(runInfo) {
|
|
|
1213
1316
|
allowStateChangesEnd(runInfo.prevAllowStateChanges_);
|
|
1214
1317
|
allowStateReadsEnd(runInfo.prevAllowStateReads_);
|
|
1215
1318
|
endBatch();
|
|
1216
|
-
|
|
1319
|
+
|
|
1320
|
+
if (runInfo.runAsAction_) {
|
|
1321
|
+
untrackedEnd(runInfo.prevDerivation_);
|
|
1322
|
+
}
|
|
1217
1323
|
|
|
1218
1324
|
if ( runInfo.notifySpy_) {
|
|
1219
1325
|
spyReportEnd({
|
|
@@ -1293,7 +1399,10 @@ var ObservableValue = /*#__PURE__*/function (_Atom, _Symbol$toPrimitive2) {
|
|
|
1293
1399
|
var _proto = ObservableValue.prototype;
|
|
1294
1400
|
|
|
1295
1401
|
_proto.dehanceValue = function dehanceValue(value) {
|
|
1296
|
-
if (this.dehancer !== undefined)
|
|
1402
|
+
if (this.dehancer !== undefined) {
|
|
1403
|
+
return this.dehancer(value);
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1297
1406
|
return value;
|
|
1298
1407
|
};
|
|
1299
1408
|
|
|
@@ -1316,7 +1425,10 @@ var ObservableValue = /*#__PURE__*/function (_Atom, _Symbol$toPrimitive2) {
|
|
|
1316
1425
|
}
|
|
1317
1426
|
|
|
1318
1427
|
this.setNewValue_(newValue);
|
|
1319
|
-
|
|
1428
|
+
|
|
1429
|
+
if ( notifySpy) {
|
|
1430
|
+
spyReportEnd();
|
|
1431
|
+
}
|
|
1320
1432
|
}
|
|
1321
1433
|
};
|
|
1322
1434
|
|
|
@@ -1329,7 +1441,11 @@ var ObservableValue = /*#__PURE__*/function (_Atom, _Symbol$toPrimitive2) {
|
|
|
1329
1441
|
type: UPDATE,
|
|
1330
1442
|
newValue: newValue
|
|
1331
1443
|
});
|
|
1332
|
-
|
|
1444
|
+
|
|
1445
|
+
if (!change) {
|
|
1446
|
+
return globalState.UNCHANGED;
|
|
1447
|
+
}
|
|
1448
|
+
|
|
1333
1449
|
newValue = change.newValue;
|
|
1334
1450
|
} // apply modifier
|
|
1335
1451
|
|
|
@@ -1363,14 +1479,17 @@ var ObservableValue = /*#__PURE__*/function (_Atom, _Symbol$toPrimitive2) {
|
|
|
1363
1479
|
};
|
|
1364
1480
|
|
|
1365
1481
|
_proto.observe_ = function observe_(listener, fireImmediately) {
|
|
1366
|
-
if (fireImmediately)
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1482
|
+
if (fireImmediately) {
|
|
1483
|
+
listener({
|
|
1484
|
+
observableKind: "value",
|
|
1485
|
+
debugObjectName: this.name_,
|
|
1486
|
+
object: this,
|
|
1487
|
+
type: UPDATE,
|
|
1488
|
+
newValue: this.value_,
|
|
1489
|
+
oldValue: undefined
|
|
1490
|
+
});
|
|
1491
|
+
}
|
|
1492
|
+
|
|
1374
1493
|
return registerListener(this, listener);
|
|
1375
1494
|
};
|
|
1376
1495
|
|
|
@@ -1465,7 +1584,11 @@ var ComputedValue = /*#__PURE__*/function (_Symbol$toPrimitive2) {
|
|
|
1465
1584
|
this.keepAlive_ = void 0;
|
|
1466
1585
|
this.onBOL = void 0;
|
|
1467
1586
|
this.onBUOL = void 0;
|
|
1468
|
-
|
|
1587
|
+
|
|
1588
|
+
if (!options.get) {
|
|
1589
|
+
die(31);
|
|
1590
|
+
}
|
|
1591
|
+
|
|
1469
1592
|
this.derivation = options.get;
|
|
1470
1593
|
this.name_ = options.name || ( "ComputedValue@" + getNextId() );
|
|
1471
1594
|
|
|
@@ -1507,7 +1630,9 @@ var ComputedValue = /*#__PURE__*/function (_Symbol$toPrimitive2) {
|
|
|
1507
1630
|
;
|
|
1508
1631
|
|
|
1509
1632
|
_proto.get = function get() {
|
|
1510
|
-
if (this.isComputing_)
|
|
1633
|
+
if (this.isComputing_) {
|
|
1634
|
+
die(32, this.name_, this.derivation);
|
|
1635
|
+
}
|
|
1511
1636
|
|
|
1512
1637
|
if (globalState.inBatch === 0 && // !globalState.trackingDerivatpion &&
|
|
1513
1638
|
this.observers_.size === 0 && !this.keepAlive_) {
|
|
@@ -1523,20 +1648,34 @@ var ComputedValue = /*#__PURE__*/function (_Symbol$toPrimitive2) {
|
|
|
1523
1648
|
|
|
1524
1649
|
if (shouldCompute(this)) {
|
|
1525
1650
|
var prevTrackingContext = globalState.trackingContext;
|
|
1526
|
-
|
|
1527
|
-
if (this.
|
|
1651
|
+
|
|
1652
|
+
if (this.keepAlive_ && !prevTrackingContext) {
|
|
1653
|
+
globalState.trackingContext = this;
|
|
1654
|
+
}
|
|
1655
|
+
|
|
1656
|
+
if (this.trackAndCompute()) {
|
|
1657
|
+
propagateChangeConfirmed(this);
|
|
1658
|
+
}
|
|
1659
|
+
|
|
1528
1660
|
globalState.trackingContext = prevTrackingContext;
|
|
1529
1661
|
}
|
|
1530
1662
|
}
|
|
1531
1663
|
|
|
1532
1664
|
var result = this.value_;
|
|
1533
|
-
|
|
1665
|
+
|
|
1666
|
+
if (isCaughtException(result)) {
|
|
1667
|
+
throw result.cause;
|
|
1668
|
+
}
|
|
1669
|
+
|
|
1534
1670
|
return result;
|
|
1535
1671
|
};
|
|
1536
1672
|
|
|
1537
1673
|
_proto.set = function set(value) {
|
|
1538
1674
|
if (this.setter_) {
|
|
1539
|
-
if (this.isRunningSetter_)
|
|
1675
|
+
if (this.isRunningSetter_) {
|
|
1676
|
+
die(33, this.name_);
|
|
1677
|
+
}
|
|
1678
|
+
|
|
1540
1679
|
this.isRunningSetter_ = true;
|
|
1541
1680
|
|
|
1542
1681
|
try {
|
|
@@ -1544,7 +1683,9 @@ var ComputedValue = /*#__PURE__*/function (_Symbol$toPrimitive2) {
|
|
|
1544
1683
|
} finally {
|
|
1545
1684
|
this.isRunningSetter_ = false;
|
|
1546
1685
|
}
|
|
1547
|
-
} else
|
|
1686
|
+
} else {
|
|
1687
|
+
die(34, this.name_);
|
|
1688
|
+
}
|
|
1548
1689
|
};
|
|
1549
1690
|
|
|
1550
1691
|
_proto.trackAndCompute = function trackAndCompute() {
|
|
@@ -1773,7 +1914,9 @@ function checkIfStateModificationsAreAllowed(atom) {
|
|
|
1773
1914
|
|
|
1774
1915
|
var hasObservers = atom.observers_.size > 0; // Should not be possible to change observed state outside strict mode, except during initialization, see #563
|
|
1775
1916
|
|
|
1776
|
-
if (!globalState.allowStateChanges && (hasObservers || globalState.enforceActions === "always"))
|
|
1917
|
+
if (!globalState.allowStateChanges && (hasObservers || globalState.enforceActions === "always")) {
|
|
1918
|
+
console.warn("[MobX] " + (globalState.enforceActions ? "Since strict-mode is enabled, changing (observed) observable values without using an action is not allowed. Tried to modify: " : "Side effects like changing state are not allowed at this point. Are you trying to modify state from, for example, a computed value or the render function of a React component? You can wrap side effects in 'runInAction' (or decorate functions with 'action') if needed. Tried to modify: ") + atom.name_);
|
|
1919
|
+
}
|
|
1777
1920
|
}
|
|
1778
1921
|
function checkIfStateReadsAreAllowed(observable) {
|
|
1779
1922
|
if ( !globalState.allowStateReads && globalState.observableRequiresReaction) {
|
|
@@ -1818,9 +1961,12 @@ function trackDerivedFunction(derivation, f, context) {
|
|
|
1818
1961
|
}
|
|
1819
1962
|
|
|
1820
1963
|
function warnAboutDerivationWithoutDependencies(derivation) {
|
|
1821
|
-
if (derivation.observing_.length !== 0) return;
|
|
1822
1964
|
|
|
1823
|
-
if (
|
|
1965
|
+
if (derivation.observing_.length !== 0) {
|
|
1966
|
+
return;
|
|
1967
|
+
}
|
|
1968
|
+
|
|
1969
|
+
if (typeof derivation.requiresObservable_ === "boolean" ? derivation.requiresObservable_ : globalState.reactionRequiresObservable) {
|
|
1824
1970
|
console.warn("[mobx] Derivation '" + derivation.name_ + "' is created/updated without reading any observable value.");
|
|
1825
1971
|
}
|
|
1826
1972
|
}
|
|
@@ -1847,7 +1993,11 @@ function bindDependencies(derivation) {
|
|
|
1847
1993
|
|
|
1848
1994
|
if (dep.diffValue_ === 0) {
|
|
1849
1995
|
dep.diffValue_ = 1;
|
|
1850
|
-
|
|
1996
|
+
|
|
1997
|
+
if (i0 !== i) {
|
|
1998
|
+
observing[i0] = dep;
|
|
1999
|
+
}
|
|
2000
|
+
|
|
1851
2001
|
i0++;
|
|
1852
2002
|
} // Upcast is 'safe' here, because if dep is IObservable, `dependenciesState` will be undefined,
|
|
1853
2003
|
// not hitting the condition
|
|
@@ -1939,7 +2089,10 @@ function allowStateReadsEnd(prev) {
|
|
|
1939
2089
|
*/
|
|
1940
2090
|
|
|
1941
2091
|
function changeDependenciesStateTo0(derivation) {
|
|
1942
|
-
if (derivation.dependenciesState_ === IDerivationState_.UP_TO_DATE_)
|
|
2092
|
+
if (derivation.dependenciesState_ === IDerivationState_.UP_TO_DATE_) {
|
|
2093
|
+
return;
|
|
2094
|
+
}
|
|
2095
|
+
|
|
1943
2096
|
derivation.dependenciesState_ = IDerivationState_.UP_TO_DATE_;
|
|
1944
2097
|
var obs = derivation.observing_;
|
|
1945
2098
|
var i = obs.length;
|
|
@@ -1983,8 +2136,14 @@ var canMergeGlobalState = true;
|
|
|
1983
2136
|
var isolateCalled = false;
|
|
1984
2137
|
var globalState = /*#__PURE__*/function () {
|
|
1985
2138
|
var global = /*#__PURE__*/getGlobal();
|
|
1986
|
-
|
|
1987
|
-
if (global.
|
|
2139
|
+
|
|
2140
|
+
if (global.__mobxInstanceCount > 0 && !global.__mobxGlobals) {
|
|
2141
|
+
canMergeGlobalState = false;
|
|
2142
|
+
}
|
|
2143
|
+
|
|
2144
|
+
if (global.__mobxGlobals && global.__mobxGlobals.version !== new MobXGlobals().version) {
|
|
2145
|
+
canMergeGlobalState = false;
|
|
2146
|
+
}
|
|
1988
2147
|
|
|
1989
2148
|
if (!canMergeGlobalState) {
|
|
1990
2149
|
// Because this is a IIFE we need to let isolateCalled a chance to change
|
|
@@ -1997,7 +2156,11 @@ var globalState = /*#__PURE__*/function () {
|
|
|
1997
2156
|
return new MobXGlobals();
|
|
1998
2157
|
} else if (global.__mobxGlobals) {
|
|
1999
2158
|
global.__mobxInstanceCount += 1;
|
|
2000
|
-
|
|
2159
|
+
|
|
2160
|
+
if (!global.__mobxGlobals.UNCHANGED) {
|
|
2161
|
+
global.__mobxGlobals.UNCHANGED = {};
|
|
2162
|
+
} // make merge backward compatible
|
|
2163
|
+
|
|
2001
2164
|
|
|
2002
2165
|
return global.__mobxGlobals;
|
|
2003
2166
|
} else {
|
|
@@ -2006,12 +2169,19 @@ var globalState = /*#__PURE__*/function () {
|
|
|
2006
2169
|
}
|
|
2007
2170
|
}();
|
|
2008
2171
|
function isolateGlobalState() {
|
|
2009
|
-
if (globalState.pendingReactions.length || globalState.inBatch || globalState.isRunningReactions)
|
|
2172
|
+
if (globalState.pendingReactions.length || globalState.inBatch || globalState.isRunningReactions) {
|
|
2173
|
+
die(36);
|
|
2174
|
+
}
|
|
2175
|
+
|
|
2010
2176
|
isolateCalled = true;
|
|
2011
2177
|
|
|
2012
2178
|
if (canMergeGlobalState) {
|
|
2013
2179
|
var global = getGlobal();
|
|
2014
|
-
|
|
2180
|
+
|
|
2181
|
+
if (--global.__mobxInstanceCount === 0) {
|
|
2182
|
+
global.__mobxGlobals = undefined;
|
|
2183
|
+
}
|
|
2184
|
+
|
|
2015
2185
|
globalState = new MobXGlobals();
|
|
2016
2186
|
}
|
|
2017
2187
|
}
|
|
@@ -2027,7 +2197,9 @@ function resetGlobalState() {
|
|
|
2027
2197
|
var defaultGlobals = new MobXGlobals();
|
|
2028
2198
|
|
|
2029
2199
|
for (var key in defaultGlobals) {
|
|
2030
|
-
if (persistentKeys.indexOf(key) === -1)
|
|
2200
|
+
if (persistentKeys.indexOf(key) === -1) {
|
|
2201
|
+
globalState[key] = defaultGlobals[key];
|
|
2202
|
+
}
|
|
2031
2203
|
}
|
|
2032
2204
|
|
|
2033
2205
|
globalState.allowStateChanges = !globalState.enforceActions;
|
|
@@ -2061,8 +2233,12 @@ function addObserver(observable, node) {
|
|
|
2061
2233
|
// invariant(observable._observers.indexOf(node) === -1, "INTERNAL ERROR add already added node");
|
|
2062
2234
|
// invariantObservers(observable);
|
|
2063
2235
|
observable.observers_.add(node);
|
|
2064
|
-
|
|
2236
|
+
|
|
2237
|
+
if (observable.lowestObserverState_ > node.dependenciesState_) {
|
|
2238
|
+
observable.lowestObserverState_ = node.dependenciesState_;
|
|
2239
|
+
} // invariantObservers(observable);
|
|
2065
2240
|
// invariant(observable._observers.indexOf(node) !== -1, "INTERNAL ERROR didn't add node");
|
|
2241
|
+
|
|
2066
2242
|
}
|
|
2067
2243
|
function removeObserver(observable, node) {
|
|
2068
2244
|
// invariant(globalState.inBatch > 0, "INTERNAL ERROR, remove should be called only inside batch");
|
|
@@ -2173,7 +2349,10 @@ function reportObserved(observable) {
|
|
|
2173
2349
|
|
|
2174
2350
|
function propagateChanged(observable) {
|
|
2175
2351
|
// invariantLOS(observable, "changed start");
|
|
2176
|
-
if (observable.lowestObserverState_ === IDerivationState_.STALE_)
|
|
2352
|
+
if (observable.lowestObserverState_ === IDerivationState_.STALE_) {
|
|
2353
|
+
return;
|
|
2354
|
+
}
|
|
2355
|
+
|
|
2177
2356
|
observable.lowestObserverState_ = IDerivationState_.STALE_; // Ideally we use for..of here, but the downcompiled version is really slow...
|
|
2178
2357
|
|
|
2179
2358
|
observable.observers_.forEach(function (d) {
|
|
@@ -2191,7 +2370,10 @@ function propagateChanged(observable) {
|
|
|
2191
2370
|
|
|
2192
2371
|
function propagateChangeConfirmed(observable) {
|
|
2193
2372
|
// invariantLOS(observable, "confirmed start");
|
|
2194
|
-
if (observable.lowestObserverState_ === IDerivationState_.STALE_)
|
|
2373
|
+
if (observable.lowestObserverState_ === IDerivationState_.STALE_) {
|
|
2374
|
+
return;
|
|
2375
|
+
}
|
|
2376
|
+
|
|
2195
2377
|
observable.lowestObserverState_ = IDerivationState_.STALE_;
|
|
2196
2378
|
observable.observers_.forEach(function (d) {
|
|
2197
2379
|
if (d.dependenciesState_ === IDerivationState_.POSSIBLY_STALE_) {
|
|
@@ -2209,7 +2391,10 @@ function propagateChangeConfirmed(observable) {
|
|
|
2209
2391
|
|
|
2210
2392
|
function propagateMaybeChanged(observable) {
|
|
2211
2393
|
// invariantLOS(observable, "maybe start");
|
|
2212
|
-
if (observable.lowestObserverState_ !== IDerivationState_.UP_TO_DATE_)
|
|
2394
|
+
if (observable.lowestObserverState_ !== IDerivationState_.UP_TO_DATE_) {
|
|
2395
|
+
return;
|
|
2396
|
+
}
|
|
2397
|
+
|
|
2213
2398
|
observable.lowestObserverState_ = IDerivationState_.POSSIBLY_STALE_;
|
|
2214
2399
|
observable.observers_.forEach(function (d) {
|
|
2215
2400
|
if (d.dependenciesState_ === IDerivationState_.UP_TO_DATE_) {
|
|
@@ -2237,9 +2422,12 @@ function printDepTree(tree, lines, depth) {
|
|
|
2237
2422
|
}
|
|
2238
2423
|
|
|
2239
2424
|
lines.push("" + "\t".repeat(depth - 1) + tree.name);
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2425
|
+
|
|
2426
|
+
if (tree.dependencies) {
|
|
2427
|
+
tree.dependencies.forEach(function (child) {
|
|
2428
|
+
return printDepTree(child, lines, depth + 1);
|
|
2429
|
+
});
|
|
2430
|
+
}
|
|
2243
2431
|
}
|
|
2244
2432
|
|
|
2245
2433
|
var Reaction = /*#__PURE__*/function () {
|
|
@@ -2249,10 +2437,6 @@ var Reaction = /*#__PURE__*/function () {
|
|
|
2249
2437
|
name_ = "Reaction@" + getNextId() ;
|
|
2250
2438
|
}
|
|
2251
2439
|
|
|
2252
|
-
if (requiresObservable_ === void 0) {
|
|
2253
|
-
requiresObservable_ = false;
|
|
2254
|
-
}
|
|
2255
|
-
|
|
2256
2440
|
this.name_ = void 0;
|
|
2257
2441
|
this.onInvalidate_ = void 0;
|
|
2258
2442
|
this.errorHandler_ = void 0;
|
|
@@ -2357,7 +2541,9 @@ var Reaction = /*#__PURE__*/function () {
|
|
|
2357
2541
|
clearObserving(this);
|
|
2358
2542
|
}
|
|
2359
2543
|
|
|
2360
|
-
if (isCaughtException(result))
|
|
2544
|
+
if (isCaughtException(result)) {
|
|
2545
|
+
this.reportExceptionInDerivation_(result.cause);
|
|
2546
|
+
}
|
|
2361
2547
|
|
|
2362
2548
|
if ( notify) {
|
|
2363
2549
|
spyReportEnd({
|
|
@@ -2376,13 +2562,18 @@ var Reaction = /*#__PURE__*/function () {
|
|
|
2376
2562
|
return;
|
|
2377
2563
|
}
|
|
2378
2564
|
|
|
2379
|
-
if (globalState.disableErrorBoundaries)
|
|
2565
|
+
if (globalState.disableErrorBoundaries) {
|
|
2566
|
+
throw error;
|
|
2567
|
+
}
|
|
2568
|
+
|
|
2380
2569
|
var message = "[mobx] Encountered an uncaught exception that was thrown by a reaction or observer component, in: '" + this + "'" ;
|
|
2381
2570
|
|
|
2382
2571
|
if (!globalState.suppressReactionErrors) {
|
|
2383
2572
|
console.error(message, error);
|
|
2384
2573
|
/** If debugging brought you here, please, read the above message :-). Tnx! */
|
|
2385
|
-
} else
|
|
2574
|
+
} else {
|
|
2575
|
+
console.warn("[mobx] (error in reaction '" + this.name_ + "' suppressed, fix error of causing action below)");
|
|
2576
|
+
} // prettier-ignore
|
|
2386
2577
|
|
|
2387
2578
|
|
|
2388
2579
|
if ( isSpyEnabled()) {
|
|
@@ -2436,7 +2627,10 @@ function onReactionError(handler) {
|
|
|
2436
2627
|
globalState.globalReactionErrorHandlers.push(handler);
|
|
2437
2628
|
return function () {
|
|
2438
2629
|
var idx = globalState.globalReactionErrorHandlers.indexOf(handler);
|
|
2439
|
-
|
|
2630
|
+
|
|
2631
|
+
if (idx >= 0) {
|
|
2632
|
+
globalState.globalReactionErrorHandlers.splice(idx, 1);
|
|
2633
|
+
}
|
|
2440
2634
|
};
|
|
2441
2635
|
}
|
|
2442
2636
|
/**
|
|
@@ -2453,7 +2647,10 @@ var reactionScheduler = function reactionScheduler(f) {
|
|
|
2453
2647
|
|
|
2454
2648
|
function runReactions() {
|
|
2455
2649
|
// Trampolining, if runReactions are already running, new reactions will be picked up
|
|
2456
|
-
if (globalState.inBatch > 0 || globalState.isRunningReactions)
|
|
2650
|
+
if (globalState.inBatch > 0 || globalState.isRunningReactions) {
|
|
2651
|
+
return;
|
|
2652
|
+
}
|
|
2653
|
+
|
|
2457
2654
|
reactionScheduler(runReactionsHelper);
|
|
2458
2655
|
}
|
|
2459
2656
|
|
|
@@ -2496,7 +2693,11 @@ function isSpyEnabled() {
|
|
|
2496
2693
|
}
|
|
2497
2694
|
function spyReport(event) {
|
|
2498
2695
|
|
|
2499
|
-
|
|
2696
|
+
|
|
2697
|
+
if (!globalState.spyListeners.length) {
|
|
2698
|
+
return;
|
|
2699
|
+
}
|
|
2700
|
+
|
|
2500
2701
|
var listeners = globalState.spyListeners;
|
|
2501
2702
|
|
|
2502
2703
|
for (var i = 0, l = listeners.length; i < l; i++) {
|
|
@@ -2516,10 +2717,15 @@ var END_EVENT = {
|
|
|
2516
2717
|
spyReportEnd: true
|
|
2517
2718
|
};
|
|
2518
2719
|
function spyReportEnd(change) {
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2720
|
+
|
|
2721
|
+
if (change) {
|
|
2722
|
+
spyReport(_extends({}, change, {
|
|
2723
|
+
type: "report-end",
|
|
2724
|
+
spyReportEnd: true
|
|
2725
|
+
}));
|
|
2726
|
+
} else {
|
|
2727
|
+
spyReport(END_EVENT);
|
|
2728
|
+
}
|
|
2523
2729
|
}
|
|
2524
2730
|
function spy(listener) {
|
|
2525
2731
|
{
|
|
@@ -2552,9 +2758,15 @@ var autoActionBoundAnnotation = /*#__PURE__*/createActionAnnotation(AUTOACTION_B
|
|
|
2552
2758
|
function createActionFactory(autoAction) {
|
|
2553
2759
|
var res = function action(arg1, arg2) {
|
|
2554
2760
|
// action(fn() {})
|
|
2555
|
-
if (isFunction(arg1))
|
|
2761
|
+
if (isFunction(arg1)) {
|
|
2762
|
+
return createAction(arg1.name || DEFAULT_ACTION_NAME, arg1, autoAction);
|
|
2763
|
+
} // action("name", fn() {})
|
|
2764
|
+
|
|
2765
|
+
|
|
2766
|
+
if (isFunction(arg2)) {
|
|
2767
|
+
return createAction(arg1, arg2, autoAction);
|
|
2768
|
+
} // @action
|
|
2556
2769
|
|
|
2557
|
-
if (isFunction(arg2)) return createAction(arg1, arg2, autoAction); // @action
|
|
2558
2770
|
|
|
2559
2771
|
if (isStringish(arg2)) {
|
|
2560
2772
|
return storeAnnotation(arg1, arg2, autoAction ? autoActionAnnotation : actionAnnotation);
|
|
@@ -2568,7 +2780,9 @@ function createActionFactory(autoAction) {
|
|
|
2568
2780
|
}));
|
|
2569
2781
|
}
|
|
2570
2782
|
|
|
2571
|
-
|
|
2783
|
+
{
|
|
2784
|
+
die("Invalid arguments for `action`");
|
|
2785
|
+
}
|
|
2572
2786
|
};
|
|
2573
2787
|
|
|
2574
2788
|
return res;
|
|
@@ -2602,8 +2816,13 @@ function autorun(view, opts) {
|
|
|
2602
2816
|
}
|
|
2603
2817
|
|
|
2604
2818
|
{
|
|
2605
|
-
if (!isFunction(view))
|
|
2606
|
-
|
|
2819
|
+
if (!isFunction(view)) {
|
|
2820
|
+
die("Autorun expects a function as first argument");
|
|
2821
|
+
}
|
|
2822
|
+
|
|
2823
|
+
if (isAction(view)) {
|
|
2824
|
+
die("Autorun does not accept actions since actions are untrackable");
|
|
2825
|
+
}
|
|
2607
2826
|
}
|
|
2608
2827
|
|
|
2609
2828
|
var name = (_opts$name = (_opts = opts) == null ? void 0 : _opts.name) != null ? _opts$name : view.name || "Autorun@" + getNextId() ;
|
|
@@ -2624,7 +2843,10 @@ function autorun(view, opts) {
|
|
|
2624
2843
|
isScheduled = true;
|
|
2625
2844
|
scheduler(function () {
|
|
2626
2845
|
isScheduled = false;
|
|
2627
|
-
|
|
2846
|
+
|
|
2847
|
+
if (!reaction.isDisposed_) {
|
|
2848
|
+
reaction.track(reactionRunner);
|
|
2849
|
+
}
|
|
2628
2850
|
});
|
|
2629
2851
|
}
|
|
2630
2852
|
}, opts.onError, opts.requiresObservable);
|
|
@@ -2656,8 +2878,13 @@ function reaction(expression, effect, opts) {
|
|
|
2656
2878
|
}
|
|
2657
2879
|
|
|
2658
2880
|
{
|
|
2659
|
-
if (!isFunction(expression) || !isFunction(effect))
|
|
2660
|
-
|
|
2881
|
+
if (!isFunction(expression) || !isFunction(effect)) {
|
|
2882
|
+
die("First and second argument to reaction should be functions");
|
|
2883
|
+
}
|
|
2884
|
+
|
|
2885
|
+
if (!isPlainObject(opts)) {
|
|
2886
|
+
die("Third argument of reactions should be an object");
|
|
2887
|
+
}
|
|
2661
2888
|
}
|
|
2662
2889
|
|
|
2663
2890
|
var name = (_opts$name2 = opts.name) != null ? _opts$name2 : "Reaction@" + getNextId() ;
|
|
@@ -2680,7 +2907,11 @@ function reaction(expression, effect, opts) {
|
|
|
2680
2907
|
|
|
2681
2908
|
function reactionRunner() {
|
|
2682
2909
|
isScheduled = false;
|
|
2683
|
-
|
|
2910
|
+
|
|
2911
|
+
if (r.isDisposed_) {
|
|
2912
|
+
return;
|
|
2913
|
+
}
|
|
2914
|
+
|
|
2684
2915
|
var changed = false;
|
|
2685
2916
|
r.track(function () {
|
|
2686
2917
|
var nextValue = allowStateChanges(false, function () {
|
|
@@ -2690,7 +2921,13 @@ function reaction(expression, effect, opts) {
|
|
|
2690
2921
|
oldValue = value;
|
|
2691
2922
|
value = nextValue;
|
|
2692
2923
|
});
|
|
2693
|
-
|
|
2924
|
+
|
|
2925
|
+
if (firstTime && opts.fireImmediately) {
|
|
2926
|
+
effectAction(value, oldValue, r);
|
|
2927
|
+
} else if (!firstTime && changed) {
|
|
2928
|
+
effectAction(value, oldValue, r);
|
|
2929
|
+
}
|
|
2930
|
+
|
|
2694
2931
|
firstTime = false;
|
|
2695
2932
|
}
|
|
2696
2933
|
|
|
@@ -2757,7 +2994,9 @@ function configure(options) {
|
|
|
2757
2994
|
globalState.useProxies = useProxies === ALWAYS ? true : useProxies === NEVER ? false : typeof Proxy !== "undefined";
|
|
2758
2995
|
}
|
|
2759
2996
|
|
|
2760
|
-
if (useProxies === "ifavailable")
|
|
2997
|
+
if (useProxies === "ifavailable") {
|
|
2998
|
+
globalState.verifyProxies = true;
|
|
2999
|
+
}
|
|
2761
3000
|
|
|
2762
3001
|
if (enforceActions !== undefined) {
|
|
2763
3002
|
var ea = enforceActions === ALWAYS ? ALWAYS : enforceActions === OBSERVED;
|
|
@@ -2765,7 +3004,9 @@ function configure(options) {
|
|
|
2765
3004
|
globalState.allowStateChanges = ea === true || ea === ALWAYS ? false : true;
|
|
2766
3005
|
}
|
|
2767
3006
|
["computedRequiresReaction", "reactionRequiresObservable", "observableRequiresReaction", "disableErrorBoundaries", "safeDescriptors"].forEach(function (key) {
|
|
2768
|
-
if (key in options)
|
|
3007
|
+
if (key in options) {
|
|
3008
|
+
globalState[key] = !!options[key];
|
|
3009
|
+
}
|
|
2769
3010
|
});
|
|
2770
3011
|
globalState.allowStateReads = !globalState.observableRequiresReaction;
|
|
2771
3012
|
|
|
@@ -2780,11 +3021,25 @@ function configure(options) {
|
|
|
2780
3021
|
|
|
2781
3022
|
function extendObservable(target, properties, annotations, options) {
|
|
2782
3023
|
{
|
|
2783
|
-
if (arguments.length > 4)
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
if (
|
|
3024
|
+
if (arguments.length > 4) {
|
|
3025
|
+
die("'extendObservable' expected 2-4 arguments");
|
|
3026
|
+
}
|
|
3027
|
+
|
|
3028
|
+
if (typeof target !== "object") {
|
|
3029
|
+
die("'extendObservable' expects an object as first argument");
|
|
3030
|
+
}
|
|
3031
|
+
|
|
3032
|
+
if (isObservableMap(target)) {
|
|
3033
|
+
die("'extendObservable' should not be used on maps, use map.merge instead");
|
|
3034
|
+
}
|
|
3035
|
+
|
|
3036
|
+
if (!isPlainObject(properties)) {
|
|
3037
|
+
die("'extendObservable' only accepts plain objects as second argument");
|
|
3038
|
+
}
|
|
3039
|
+
|
|
3040
|
+
if (isObservable(properties) || isObservable(annotations)) {
|
|
3041
|
+
die("Extending an object with another observable (object) is not supported");
|
|
3042
|
+
}
|
|
2788
3043
|
} // Pull descriptors first, so we don't have to deal with props added by administration ($mobx)
|
|
2789
3044
|
|
|
2790
3045
|
|
|
@@ -2812,7 +3067,11 @@ function nodeToDependencyTree(node) {
|
|
|
2812
3067
|
var result = {
|
|
2813
3068
|
name: node.name_
|
|
2814
3069
|
};
|
|
2815
|
-
|
|
3070
|
+
|
|
3071
|
+
if (node.observing_ && node.observing_.length > 0) {
|
|
3072
|
+
result.dependencies = unique(node.observing_).map(nodeToDependencyTree);
|
|
3073
|
+
}
|
|
3074
|
+
|
|
2816
3075
|
return result;
|
|
2817
3076
|
}
|
|
2818
3077
|
|
|
@@ -2824,7 +3083,11 @@ function nodeToObserverTree(node) {
|
|
|
2824
3083
|
var result = {
|
|
2825
3084
|
name: node.name_
|
|
2826
3085
|
};
|
|
2827
|
-
|
|
3086
|
+
|
|
3087
|
+
if (hasObservers(node)) {
|
|
3088
|
+
result.observers = Array.from(getObservers(node)).map(nodeToObserverTree);
|
|
3089
|
+
}
|
|
3090
|
+
|
|
2828
3091
|
return result;
|
|
2829
3092
|
}
|
|
2830
3093
|
|
|
@@ -2851,7 +3114,10 @@ var flow = /*#__PURE__*/Object.assign(function flow(arg1, arg2) {
|
|
|
2851
3114
|
} // flow(fn)
|
|
2852
3115
|
|
|
2853
3116
|
|
|
2854
|
-
if ( arguments.length !== 1)
|
|
3117
|
+
if ( arguments.length !== 1) {
|
|
3118
|
+
die("Flow expects single argument with generator function");
|
|
3119
|
+
}
|
|
3120
|
+
|
|
2855
3121
|
var generator = arg1;
|
|
2856
3122
|
var name = generator.name || "<unnamed flow>"; // Implementation based on https://github.com/tj/co/blob/master/index.js
|
|
2857
3123
|
|
|
@@ -2899,7 +3165,10 @@ var flow = /*#__PURE__*/Object.assign(function flow(arg1, arg2) {
|
|
|
2899
3165
|
return;
|
|
2900
3166
|
}
|
|
2901
3167
|
|
|
2902
|
-
if (ret.done)
|
|
3168
|
+
if (ret.done) {
|
|
3169
|
+
return resolve(ret.value);
|
|
3170
|
+
}
|
|
3171
|
+
|
|
2903
3172
|
pendingPromise = Promise.resolve(ret.value);
|
|
2904
3173
|
return pendingPromise.then(onFulfilled, onRejected);
|
|
2905
3174
|
}
|
|
@@ -2908,7 +3177,10 @@ var flow = /*#__PURE__*/Object.assign(function flow(arg1, arg2) {
|
|
|
2908
3177
|
});
|
|
2909
3178
|
promise.cancel = action(name + " - runid: " + runId + " - cancel", function () {
|
|
2910
3179
|
try {
|
|
2911
|
-
if (pendingPromise)
|
|
3180
|
+
if (pendingPromise) {
|
|
3181
|
+
cancelPromise(pendingPromise);
|
|
3182
|
+
} // Finally block can return (or yield) stuff..
|
|
3183
|
+
|
|
2912
3184
|
|
|
2913
3185
|
var _res = gen["return"](undefined); // eat anything that promise would do, it's cancelled!
|
|
2914
3186
|
|
|
@@ -2932,7 +3204,9 @@ var flow = /*#__PURE__*/Object.assign(function flow(arg1, arg2) {
|
|
|
2932
3204
|
flow.bound = /*#__PURE__*/createDecoratorAnnotation(flowBoundAnnotation);
|
|
2933
3205
|
|
|
2934
3206
|
function cancelPromise(promise) {
|
|
2935
|
-
if (isFunction(promise.cancel))
|
|
3207
|
+
if (isFunction(promise.cancel)) {
|
|
3208
|
+
promise.cancel();
|
|
3209
|
+
}
|
|
2936
3210
|
}
|
|
2937
3211
|
|
|
2938
3212
|
function flowResult(result) {
|
|
@@ -2948,13 +3222,19 @@ function interceptReads(thing, propOrHandler, handler) {
|
|
|
2948
3222
|
if (isObservableMap(thing) || isObservableArray(thing) || isObservableValue(thing)) {
|
|
2949
3223
|
target = getAdministration(thing);
|
|
2950
3224
|
} else if (isObservableObject(thing)) {
|
|
2951
|
-
if ( !isStringish(propOrHandler))
|
|
3225
|
+
if ( !isStringish(propOrHandler)) {
|
|
3226
|
+
return die("InterceptReads can only be used with a specific property, not with an object in general");
|
|
3227
|
+
}
|
|
3228
|
+
|
|
2952
3229
|
target = getAdministration(thing, propOrHandler);
|
|
2953
3230
|
} else {
|
|
2954
3231
|
return die("Expected observable map, object or array as first array");
|
|
2955
3232
|
}
|
|
2956
3233
|
|
|
2957
|
-
if ( target.dehancer !== undefined)
|
|
3234
|
+
if ( target.dehancer !== undefined) {
|
|
3235
|
+
return die("An intercept reader was already established");
|
|
3236
|
+
}
|
|
3237
|
+
|
|
2958
3238
|
target.dehancer = typeof propOrHandler === "function" ? propOrHandler : handler;
|
|
2959
3239
|
return function () {
|
|
2960
3240
|
target.dehancer = undefined;
|
|
@@ -2962,7 +3242,11 @@ function interceptReads(thing, propOrHandler, handler) {
|
|
|
2962
3242
|
}
|
|
2963
3243
|
|
|
2964
3244
|
function intercept(thing, propOrHandler, handler) {
|
|
2965
|
-
if (isFunction(handler))
|
|
3245
|
+
if (isFunction(handler)) {
|
|
3246
|
+
return interceptProperty(thing, propOrHandler, handler);
|
|
3247
|
+
} else {
|
|
3248
|
+
return interceptInterceptable(thing, propOrHandler);
|
|
3249
|
+
}
|
|
2966
3250
|
}
|
|
2967
3251
|
|
|
2968
3252
|
function interceptInterceptable(thing, handler) {
|
|
@@ -2978,25 +3262,41 @@ function _isComputed(value, property) {
|
|
|
2978
3262
|
return isComputedValue(value);
|
|
2979
3263
|
}
|
|
2980
3264
|
|
|
2981
|
-
if (isObservableObject(value) === false)
|
|
2982
|
-
|
|
3265
|
+
if (isObservableObject(value) === false) {
|
|
3266
|
+
return false;
|
|
3267
|
+
}
|
|
3268
|
+
|
|
3269
|
+
if (!value[$mobx].values_.has(property)) {
|
|
3270
|
+
return false;
|
|
3271
|
+
}
|
|
3272
|
+
|
|
2983
3273
|
var atom = getAtom(value, property);
|
|
2984
3274
|
return isComputedValue(atom);
|
|
2985
3275
|
}
|
|
2986
3276
|
function isComputed(value) {
|
|
2987
|
-
if ( arguments.length > 1)
|
|
3277
|
+
if ( arguments.length > 1) {
|
|
3278
|
+
return die("isComputed expects only 1 argument. Use isComputedProp to inspect the observability of a property");
|
|
3279
|
+
}
|
|
3280
|
+
|
|
2988
3281
|
return _isComputed(value);
|
|
2989
3282
|
}
|
|
2990
3283
|
function isComputedProp(value, propName) {
|
|
2991
|
-
if ( !isStringish(propName))
|
|
3284
|
+
if ( !isStringish(propName)) {
|
|
3285
|
+
return die("isComputed expected a property name as second argument");
|
|
3286
|
+
}
|
|
3287
|
+
|
|
2992
3288
|
return _isComputed(value, propName);
|
|
2993
3289
|
}
|
|
2994
3290
|
|
|
2995
3291
|
function _isObservable(value, property) {
|
|
2996
|
-
if (!value)
|
|
3292
|
+
if (!value) {
|
|
3293
|
+
return false;
|
|
3294
|
+
}
|
|
2997
3295
|
|
|
2998
3296
|
if (property !== undefined) {
|
|
2999
|
-
if ( (isObservableMap(value) || isObservableArray(value)))
|
|
3297
|
+
if ( (isObservableMap(value) || isObservableArray(value))) {
|
|
3298
|
+
return die("isObservable(object, propertyName) is not supported for arrays and maps. Use map.has or array.length instead.");
|
|
3299
|
+
}
|
|
3000
3300
|
|
|
3001
3301
|
if (isObservableObject(value)) {
|
|
3002
3302
|
return value[$mobx].values_.has(property);
|
|
@@ -3010,11 +3310,17 @@ function _isObservable(value, property) {
|
|
|
3010
3310
|
}
|
|
3011
3311
|
|
|
3012
3312
|
function isObservable(value) {
|
|
3013
|
-
if ( arguments.length !== 1)
|
|
3313
|
+
if ( arguments.length !== 1) {
|
|
3314
|
+
die("isObservable expects only 1 argument. Use isObservableProp to inspect the observability of a property");
|
|
3315
|
+
}
|
|
3316
|
+
|
|
3014
3317
|
return _isObservable(value);
|
|
3015
3318
|
}
|
|
3016
3319
|
function isObservableProp(value, propName) {
|
|
3017
|
-
if ( !isStringish(propName))
|
|
3320
|
+
if ( !isStringish(propName)) {
|
|
3321
|
+
return die("expected a property name as second argument");
|
|
3322
|
+
}
|
|
3323
|
+
|
|
3018
3324
|
return _isObservable(value, propName);
|
|
3019
3325
|
}
|
|
3020
3326
|
|
|
@@ -3106,13 +3412,25 @@ function set(obj, key, value) {
|
|
|
3106
3412
|
} else if (isObservableSet(obj)) {
|
|
3107
3413
|
obj.add(key);
|
|
3108
3414
|
} else if (isObservableArray(obj)) {
|
|
3109
|
-
if (typeof key !== "number")
|
|
3110
|
-
|
|
3415
|
+
if (typeof key !== "number") {
|
|
3416
|
+
key = parseInt(key, 10);
|
|
3417
|
+
}
|
|
3418
|
+
|
|
3419
|
+
if (key < 0) {
|
|
3420
|
+
die("Invalid index: '" + key + "'");
|
|
3421
|
+
}
|
|
3422
|
+
|
|
3111
3423
|
startBatch();
|
|
3112
|
-
|
|
3424
|
+
|
|
3425
|
+
if (key >= obj.length) {
|
|
3426
|
+
obj.length = key + 1;
|
|
3427
|
+
}
|
|
3428
|
+
|
|
3113
3429
|
obj[key] = value;
|
|
3114
3430
|
endBatch();
|
|
3115
|
-
} else
|
|
3431
|
+
} else {
|
|
3432
|
+
die(8);
|
|
3433
|
+
}
|
|
3116
3434
|
}
|
|
3117
3435
|
function remove(obj, key) {
|
|
3118
3436
|
if (isObservableObject(obj)) {
|
|
@@ -3122,7 +3440,10 @@ function remove(obj, key) {
|
|
|
3122
3440
|
} else if (isObservableSet(obj)) {
|
|
3123
3441
|
obj["delete"](key);
|
|
3124
3442
|
} else if (isObservableArray(obj)) {
|
|
3125
|
-
if (typeof key !== "number")
|
|
3443
|
+
if (typeof key !== "number") {
|
|
3444
|
+
key = parseInt(key, 10);
|
|
3445
|
+
}
|
|
3446
|
+
|
|
3126
3447
|
obj.splice(key, 1);
|
|
3127
3448
|
} else {
|
|
3128
3449
|
die(9);
|
|
@@ -3142,7 +3463,9 @@ function has(obj, key) {
|
|
|
3142
3463
|
die(10);
|
|
3143
3464
|
}
|
|
3144
3465
|
function get(obj, key) {
|
|
3145
|
-
if (!has(obj, key))
|
|
3466
|
+
if (!has(obj, key)) {
|
|
3467
|
+
return undefined;
|
|
3468
|
+
}
|
|
3146
3469
|
|
|
3147
3470
|
if (isObservableObject(obj)) {
|
|
3148
3471
|
return obj[$mobx].get_(key);
|
|
@@ -3170,7 +3493,11 @@ function apiOwnKeys(obj) {
|
|
|
3170
3493
|
}
|
|
3171
3494
|
|
|
3172
3495
|
function observe(thing, propOrCb, cbOrFire, fireImmediately) {
|
|
3173
|
-
if (isFunction(cbOrFire))
|
|
3496
|
+
if (isFunction(cbOrFire)) {
|
|
3497
|
+
return observeObservableProperty(thing, propOrCb, cbOrFire, fireImmediately);
|
|
3498
|
+
} else {
|
|
3499
|
+
return observeObservable(thing, propOrCb, cbOrFire);
|
|
3500
|
+
}
|
|
3174
3501
|
}
|
|
3175
3502
|
|
|
3176
3503
|
function observeObservable(thing, listener, fireImmediately) {
|
|
@@ -3187,8 +3514,13 @@ function cache(map, key, value) {
|
|
|
3187
3514
|
}
|
|
3188
3515
|
|
|
3189
3516
|
function toJSHelper(source, __alreadySeen) {
|
|
3190
|
-
if (source == null || typeof source !== "object" || source instanceof Date || !isObservable(source))
|
|
3191
|
-
|
|
3517
|
+
if (source == null || typeof source !== "object" || source instanceof Date || !isObservable(source)) {
|
|
3518
|
+
return source;
|
|
3519
|
+
}
|
|
3520
|
+
|
|
3521
|
+
if (isObservableValue(source) || isComputedValue(source)) {
|
|
3522
|
+
return toJSHelper(source.get(), __alreadySeen);
|
|
3523
|
+
}
|
|
3192
3524
|
|
|
3193
3525
|
if (__alreadySeen.has(source)) {
|
|
3194
3526
|
return __alreadySeen.get(source);
|
|
@@ -3239,18 +3571,25 @@ function toJSHelper(source, __alreadySeen) {
|
|
|
3239
3571
|
|
|
3240
3572
|
|
|
3241
3573
|
function toJS(source, options) {
|
|
3242
|
-
if ( options)
|
|
3574
|
+
if ( options) {
|
|
3575
|
+
die("toJS no longer supports options");
|
|
3576
|
+
}
|
|
3577
|
+
|
|
3243
3578
|
return toJSHelper(source, new Map());
|
|
3244
3579
|
}
|
|
3245
3580
|
|
|
3246
3581
|
function trace() {
|
|
3582
|
+
|
|
3247
3583
|
var enterBreakPoint = false;
|
|
3248
3584
|
|
|
3249
3585
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
3250
3586
|
args[_key] = arguments[_key];
|
|
3251
3587
|
}
|
|
3252
3588
|
|
|
3253
|
-
if (typeof args[args.length - 1] === "boolean")
|
|
3589
|
+
if (typeof args[args.length - 1] === "boolean") {
|
|
3590
|
+
enterBreakPoint = args.pop();
|
|
3591
|
+
}
|
|
3592
|
+
|
|
3254
3593
|
var derivation = getAtomFromArgs(args);
|
|
3255
3594
|
|
|
3256
3595
|
if (!derivation) {
|
|
@@ -3300,7 +3639,10 @@ function transaction(action, thisArg) {
|
|
|
3300
3639
|
}
|
|
3301
3640
|
|
|
3302
3641
|
function when(predicate, arg1, arg2) {
|
|
3303
|
-
if (arguments.length === 1 || arg1 && typeof arg1 === "object")
|
|
3642
|
+
if (arguments.length === 1 || arg1 && typeof arg1 === "object") {
|
|
3643
|
+
return whenPromise(predicate, arg1);
|
|
3644
|
+
}
|
|
3645
|
+
|
|
3304
3646
|
return _when(predicate, arg1, arg2 || {});
|
|
3305
3647
|
}
|
|
3306
3648
|
|
|
@@ -3312,7 +3654,12 @@ function _when(predicate, effect, opts) {
|
|
|
3312
3654
|
timeoutHandle = setTimeout(function () {
|
|
3313
3655
|
if (!disposer[$mobx].isDisposed_) {
|
|
3314
3656
|
disposer();
|
|
3315
|
-
|
|
3657
|
+
|
|
3658
|
+
if (opts.onError) {
|
|
3659
|
+
opts.onError(error);
|
|
3660
|
+
} else {
|
|
3661
|
+
throw error;
|
|
3662
|
+
}
|
|
3316
3663
|
}
|
|
3317
3664
|
}, opts.timeout);
|
|
3318
3665
|
}
|
|
@@ -3326,7 +3673,11 @@ function _when(predicate, effect, opts) {
|
|
|
3326
3673
|
|
|
3327
3674
|
if (cond) {
|
|
3328
3675
|
r.dispose();
|
|
3329
|
-
|
|
3676
|
+
|
|
3677
|
+
if (timeoutHandle) {
|
|
3678
|
+
clearTimeout(timeoutHandle);
|
|
3679
|
+
}
|
|
3680
|
+
|
|
3330
3681
|
effectAction();
|
|
3331
3682
|
}
|
|
3332
3683
|
}, opts);
|
|
@@ -3334,7 +3685,10 @@ function _when(predicate, effect, opts) {
|
|
|
3334
3685
|
}
|
|
3335
3686
|
|
|
3336
3687
|
function whenPromise(predicate, opts) {
|
|
3337
|
-
if ( opts && opts.onError)
|
|
3688
|
+
if ( opts && opts.onError) {
|
|
3689
|
+
return die("the options 'onError' and 'promise' cannot be combined");
|
|
3690
|
+
}
|
|
3691
|
+
|
|
3338
3692
|
var cancel;
|
|
3339
3693
|
var res = new Promise(function (resolve, reject) {
|
|
3340
3694
|
var disposer = _when(predicate, resolve, _extends({}, opts, {
|
|
@@ -3358,7 +3712,10 @@ function getAdm(target) {
|
|
|
3358
3712
|
|
|
3359
3713
|
var objectProxyTraps = {
|
|
3360
3714
|
has: function has(target, name) {
|
|
3361
|
-
if ( globalState.trackingDerivation)
|
|
3715
|
+
if ( globalState.trackingDerivation) {
|
|
3716
|
+
warnAboutProxyRequirement("detect new properties using the 'in' operator. Use 'has' from 'mobx' instead.");
|
|
3717
|
+
}
|
|
3718
|
+
|
|
3362
3719
|
return getAdm(target).has_(name);
|
|
3363
3720
|
},
|
|
3364
3721
|
get: function get(target, name) {
|
|
@@ -3367,7 +3724,9 @@ var objectProxyTraps = {
|
|
|
3367
3724
|
set: function set(target, name, value) {
|
|
3368
3725
|
var _getAdm$set_;
|
|
3369
3726
|
|
|
3370
|
-
if (!isStringish(name))
|
|
3727
|
+
if (!isStringish(name)) {
|
|
3728
|
+
return false;
|
|
3729
|
+
}
|
|
3371
3730
|
|
|
3372
3731
|
if ( !getAdm(target).values_.has(name)) {
|
|
3373
3732
|
warnAboutProxyRequirement("add a new observable property through direct assignment. Use 'set' from 'mobx' instead.");
|
|
@@ -3383,7 +3742,10 @@ var objectProxyTraps = {
|
|
|
3383
3742
|
warnAboutProxyRequirement("delete properties from an observable object. Use 'remove' from 'mobx' instead.");
|
|
3384
3743
|
}
|
|
3385
3744
|
|
|
3386
|
-
if (!isStringish(name))
|
|
3745
|
+
if (!isStringish(name)) {
|
|
3746
|
+
return false;
|
|
3747
|
+
} // null (intercepted) -> true (success)
|
|
3748
|
+
|
|
3387
3749
|
|
|
3388
3750
|
return (_getAdm$delete_ = getAdm(target).delete_(name, true)) != null ? _getAdm$delete_ : true;
|
|
3389
3751
|
},
|
|
@@ -3398,7 +3760,10 @@ var objectProxyTraps = {
|
|
|
3398
3760
|
return (_getAdm$definePropert = getAdm(target).defineProperty_(name, descriptor)) != null ? _getAdm$definePropert : true;
|
|
3399
3761
|
},
|
|
3400
3762
|
ownKeys: function ownKeys(target) {
|
|
3401
|
-
if ( globalState.trackingDerivation)
|
|
3763
|
+
if ( globalState.trackingDerivation) {
|
|
3764
|
+
warnAboutProxyRequirement("iterate keys to detect added / removed properties. Use 'keys' from 'mobx' instead.");
|
|
3765
|
+
}
|
|
3766
|
+
|
|
3402
3767
|
return getAdm(target).ownKeys_();
|
|
3403
3768
|
},
|
|
3404
3769
|
preventExtensions: function preventExtensions(target) {
|
|
@@ -3421,7 +3786,10 @@ function registerInterceptor(interceptable, handler) {
|
|
|
3421
3786
|
interceptors.push(handler);
|
|
3422
3787
|
return once(function () {
|
|
3423
3788
|
var idx = interceptors.indexOf(handler);
|
|
3424
|
-
|
|
3789
|
+
|
|
3790
|
+
if (idx !== -1) {
|
|
3791
|
+
interceptors.splice(idx, 1);
|
|
3792
|
+
}
|
|
3425
3793
|
});
|
|
3426
3794
|
}
|
|
3427
3795
|
function interceptChange(interceptable, change) {
|
|
@@ -3433,8 +3801,14 @@ function interceptChange(interceptable, change) {
|
|
|
3433
3801
|
|
|
3434
3802
|
for (var i = 0, l = interceptors.length; i < l; i++) {
|
|
3435
3803
|
change = interceptors[i](change);
|
|
3436
|
-
|
|
3437
|
-
if (!change)
|
|
3804
|
+
|
|
3805
|
+
if (change && !change.type) {
|
|
3806
|
+
die(14);
|
|
3807
|
+
}
|
|
3808
|
+
|
|
3809
|
+
if (!change) {
|
|
3810
|
+
break;
|
|
3811
|
+
}
|
|
3438
3812
|
}
|
|
3439
3813
|
|
|
3440
3814
|
return change;
|
|
@@ -3451,13 +3825,20 @@ function registerListener(listenable, handler) {
|
|
|
3451
3825
|
listeners.push(handler);
|
|
3452
3826
|
return once(function () {
|
|
3453
3827
|
var idx = listeners.indexOf(handler);
|
|
3454
|
-
|
|
3828
|
+
|
|
3829
|
+
if (idx !== -1) {
|
|
3830
|
+
listeners.splice(idx, 1);
|
|
3831
|
+
}
|
|
3455
3832
|
});
|
|
3456
3833
|
}
|
|
3457
3834
|
function notifyListeners(listenable, change) {
|
|
3458
3835
|
var prevU = untrackedStart();
|
|
3459
3836
|
var listeners = listenable.changeListeners_;
|
|
3460
|
-
|
|
3837
|
+
|
|
3838
|
+
if (!listeners) {
|
|
3839
|
+
return;
|
|
3840
|
+
}
|
|
3841
|
+
|
|
3461
3842
|
listeners = listeners.slice();
|
|
3462
3843
|
|
|
3463
3844
|
for (var i = 0, l = listeners.length; i < l; i++) {
|
|
@@ -3494,8 +3875,13 @@ function makeObservable(target, annotations, options) {
|
|
|
3494
3875
|
var keysSymbol = /*#__PURE__*/Symbol("mobx-keys");
|
|
3495
3876
|
function makeAutoObservable(target, overrides, options) {
|
|
3496
3877
|
{
|
|
3497
|
-
if (!isPlainObject(target) && !isPlainObject(Object.getPrototypeOf(target)))
|
|
3498
|
-
|
|
3878
|
+
if (!isPlainObject(target) && !isPlainObject(Object.getPrototypeOf(target))) {
|
|
3879
|
+
die("'makeAutoObservable' can only be used for classes that don't have a superclass");
|
|
3880
|
+
}
|
|
3881
|
+
|
|
3882
|
+
if (isObservableObject(target)) {
|
|
3883
|
+
die("makeAutoObservable can only be used on objects not already made observable");
|
|
3884
|
+
}
|
|
3499
3885
|
} // Optimization: avoid visiting protos
|
|
3500
3886
|
// Assumes that annotation.make_/.extend_ works the same for plain objects
|
|
3501
3887
|
|
|
@@ -3536,8 +3922,14 @@ var MAX_SPLICE_SIZE = 10000; // See e.g. https://github.com/mobxjs/mobx/issues/8
|
|
|
3536
3922
|
var arrayTraps = {
|
|
3537
3923
|
get: function get(target, name) {
|
|
3538
3924
|
var adm = target[$mobx];
|
|
3539
|
-
|
|
3540
|
-
if (name ===
|
|
3925
|
+
|
|
3926
|
+
if (name === $mobx) {
|
|
3927
|
+
return adm;
|
|
3928
|
+
}
|
|
3929
|
+
|
|
3930
|
+
if (name === "length") {
|
|
3931
|
+
return adm.getArrayLength_();
|
|
3932
|
+
}
|
|
3541
3933
|
|
|
3542
3934
|
if (typeof name === "string" && !isNaN(name)) {
|
|
3543
3935
|
return adm.get_(parseInt(name));
|
|
@@ -3598,12 +3990,18 @@ var ObservableArrayAdministration = /*#__PURE__*/function () {
|
|
|
3598
3990
|
var _proto = ObservableArrayAdministration.prototype;
|
|
3599
3991
|
|
|
3600
3992
|
_proto.dehanceValue_ = function dehanceValue_(value) {
|
|
3601
|
-
if (this.dehancer !== undefined)
|
|
3993
|
+
if (this.dehancer !== undefined) {
|
|
3994
|
+
return this.dehancer(value);
|
|
3995
|
+
}
|
|
3996
|
+
|
|
3602
3997
|
return value;
|
|
3603
3998
|
};
|
|
3604
3999
|
|
|
3605
4000
|
_proto.dehanceValues_ = function dehanceValues_(values) {
|
|
3606
|
-
if (this.dehancer !== undefined && values.length > 0)
|
|
4001
|
+
if (this.dehancer !== undefined && values.length > 0) {
|
|
4002
|
+
return values.map(this.dehancer);
|
|
4003
|
+
}
|
|
4004
|
+
|
|
3607
4005
|
return values;
|
|
3608
4006
|
};
|
|
3609
4007
|
|
|
@@ -3639,9 +4037,15 @@ var ObservableArrayAdministration = /*#__PURE__*/function () {
|
|
|
3639
4037
|
};
|
|
3640
4038
|
|
|
3641
4039
|
_proto.setArrayLength_ = function setArrayLength_(newLength) {
|
|
3642
|
-
if (typeof newLength !== "number" || isNaN(newLength) || newLength < 0)
|
|
4040
|
+
if (typeof newLength !== "number" || isNaN(newLength) || newLength < 0) {
|
|
4041
|
+
die("Out of range: " + newLength);
|
|
4042
|
+
}
|
|
4043
|
+
|
|
3643
4044
|
var currentLength = this.values_.length;
|
|
3644
|
-
|
|
4045
|
+
|
|
4046
|
+
if (newLength === currentLength) {
|
|
4047
|
+
return;
|
|
4048
|
+
} else if (newLength > currentLength) {
|
|
3645
4049
|
var newItems = new Array(newLength - currentLength);
|
|
3646
4050
|
|
|
3647
4051
|
for (var i = 0; i < newLength - currentLength; i++) {
|
|
@@ -3650,13 +4054,21 @@ var ObservableArrayAdministration = /*#__PURE__*/function () {
|
|
|
3650
4054
|
|
|
3651
4055
|
|
|
3652
4056
|
this.spliceWithArray_(currentLength, 0, newItems);
|
|
3653
|
-
} else
|
|
4057
|
+
} else {
|
|
4058
|
+
this.spliceWithArray_(newLength, currentLength - newLength);
|
|
4059
|
+
}
|
|
3654
4060
|
};
|
|
3655
4061
|
|
|
3656
4062
|
_proto.updateArrayLength_ = function updateArrayLength_(oldLength, delta) {
|
|
3657
|
-
if (oldLength !== this.lastKnownLength_)
|
|
4063
|
+
if (oldLength !== this.lastKnownLength_) {
|
|
4064
|
+
die(16);
|
|
4065
|
+
}
|
|
4066
|
+
|
|
3658
4067
|
this.lastKnownLength_ += delta;
|
|
3659
|
-
|
|
4068
|
+
|
|
4069
|
+
if (this.legacyMode_ && delta > 0) {
|
|
4070
|
+
reserveArrayBuffer(oldLength + delta + 1);
|
|
4071
|
+
}
|
|
3660
4072
|
};
|
|
3661
4073
|
|
|
3662
4074
|
_proto.spliceWithArray_ = function spliceWithArray_(index, deleteCount, newItems) {
|
|
@@ -3664,9 +4076,26 @@ var ObservableArrayAdministration = /*#__PURE__*/function () {
|
|
|
3664
4076
|
|
|
3665
4077
|
checkIfStateModificationsAreAllowed(this.atom_);
|
|
3666
4078
|
var length = this.values_.length;
|
|
3667
|
-
|
|
3668
|
-
if (
|
|
3669
|
-
|
|
4079
|
+
|
|
4080
|
+
if (index === undefined) {
|
|
4081
|
+
index = 0;
|
|
4082
|
+
} else if (index > length) {
|
|
4083
|
+
index = length;
|
|
4084
|
+
} else if (index < 0) {
|
|
4085
|
+
index = Math.max(0, length + index);
|
|
4086
|
+
}
|
|
4087
|
+
|
|
4088
|
+
if (arguments.length === 1) {
|
|
4089
|
+
deleteCount = length - index;
|
|
4090
|
+
} else if (deleteCount === undefined || deleteCount === null) {
|
|
4091
|
+
deleteCount = 0;
|
|
4092
|
+
} else {
|
|
4093
|
+
deleteCount = Math.max(0, Math.min(deleteCount, length - index));
|
|
4094
|
+
}
|
|
4095
|
+
|
|
4096
|
+
if (newItems === undefined) {
|
|
4097
|
+
newItems = EMPTY_ARRAY;
|
|
4098
|
+
}
|
|
3670
4099
|
|
|
3671
4100
|
if (hasInterceptors(this)) {
|
|
3672
4101
|
var change = interceptChange(this, {
|
|
@@ -3676,7 +4105,11 @@ var ObservableArrayAdministration = /*#__PURE__*/function () {
|
|
|
3676
4105
|
removedCount: deleteCount,
|
|
3677
4106
|
added: newItems
|
|
3678
4107
|
});
|
|
3679
|
-
|
|
4108
|
+
|
|
4109
|
+
if (!change) {
|
|
4110
|
+
return EMPTY_ARRAY;
|
|
4111
|
+
}
|
|
4112
|
+
|
|
3680
4113
|
deleteCount = change.removedCount;
|
|
3681
4114
|
newItems = change.added;
|
|
3682
4115
|
}
|
|
@@ -3691,7 +4124,11 @@ var ObservableArrayAdministration = /*#__PURE__*/function () {
|
|
|
3691
4124
|
}
|
|
3692
4125
|
|
|
3693
4126
|
var res = this.spliceItemsIntoValues_(index, deleteCount, newItems);
|
|
3694
|
-
|
|
4127
|
+
|
|
4128
|
+
if (deleteCount !== 0 || newItems.length !== 0) {
|
|
4129
|
+
this.notifyArraySplice_(index, newItems, res);
|
|
4130
|
+
}
|
|
4131
|
+
|
|
3695
4132
|
return this.dehanceValues_(res);
|
|
3696
4133
|
};
|
|
3697
4134
|
|
|
@@ -3734,10 +4171,19 @@ var ObservableArrayAdministration = /*#__PURE__*/function () {
|
|
|
3734
4171
|
} : null; // The reason why this is on right hand side here (and not above), is this way the uglifier will drop it, but it won't
|
|
3735
4172
|
// cause any runtime overhead in development mode without NODE_ENV set, unless spying is enabled
|
|
3736
4173
|
|
|
3737
|
-
if ( notifySpy)
|
|
4174
|
+
if ( notifySpy) {
|
|
4175
|
+
spyReportStart(change);
|
|
4176
|
+
}
|
|
4177
|
+
|
|
3738
4178
|
this.atom_.reportChanged();
|
|
3739
|
-
|
|
3740
|
-
if (
|
|
4179
|
+
|
|
4180
|
+
if (notify) {
|
|
4181
|
+
notifyListeners(this, change);
|
|
4182
|
+
}
|
|
4183
|
+
|
|
4184
|
+
if ( notifySpy) {
|
|
4185
|
+
spyReportEnd();
|
|
4186
|
+
}
|
|
3741
4187
|
};
|
|
3742
4188
|
|
|
3743
4189
|
_proto.notifyArraySplice_ = function notifyArraySplice_(index, added, removed) {
|
|
@@ -3754,11 +4200,20 @@ var ObservableArrayAdministration = /*#__PURE__*/function () {
|
|
|
3754
4200
|
removedCount: removed.length,
|
|
3755
4201
|
addedCount: added.length
|
|
3756
4202
|
} : null;
|
|
3757
|
-
|
|
4203
|
+
|
|
4204
|
+
if ( notifySpy) {
|
|
4205
|
+
spyReportStart(change);
|
|
4206
|
+
}
|
|
4207
|
+
|
|
3758
4208
|
this.atom_.reportChanged(); // conform: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/observe
|
|
3759
4209
|
|
|
3760
|
-
if (notify)
|
|
3761
|
-
|
|
4210
|
+
if (notify) {
|
|
4211
|
+
notifyListeners(this, change);
|
|
4212
|
+
}
|
|
4213
|
+
|
|
4214
|
+
if ( notifySpy) {
|
|
4215
|
+
spyReportEnd();
|
|
4216
|
+
}
|
|
3762
4217
|
};
|
|
3763
4218
|
|
|
3764
4219
|
_proto.get_ = function get_(index) {
|
|
@@ -3785,7 +4240,11 @@ var ObservableArrayAdministration = /*#__PURE__*/function () {
|
|
|
3785
4240
|
index: index,
|
|
3786
4241
|
newValue: newValue
|
|
3787
4242
|
});
|
|
3788
|
-
|
|
4243
|
+
|
|
4244
|
+
if (!change) {
|
|
4245
|
+
return;
|
|
4246
|
+
}
|
|
4247
|
+
|
|
3789
4248
|
newValue = change.newValue;
|
|
3790
4249
|
}
|
|
3791
4250
|
|
|
@@ -4069,7 +4528,10 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4069
4528
|
_proto.has = function has(key) {
|
|
4070
4529
|
var _this2 = this;
|
|
4071
4530
|
|
|
4072
|
-
if (!globalState.trackingDerivation)
|
|
4531
|
+
if (!globalState.trackingDerivation) {
|
|
4532
|
+
return this.has_(key);
|
|
4533
|
+
}
|
|
4534
|
+
|
|
4073
4535
|
var entry = this.hasMap_.get(key);
|
|
4074
4536
|
|
|
4075
4537
|
if (!entry) {
|
|
@@ -4093,7 +4555,11 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4093
4555
|
newValue: value,
|
|
4094
4556
|
name: key
|
|
4095
4557
|
});
|
|
4096
|
-
|
|
4558
|
+
|
|
4559
|
+
if (!change) {
|
|
4560
|
+
return this;
|
|
4561
|
+
}
|
|
4562
|
+
|
|
4097
4563
|
value = change.newValue;
|
|
4098
4564
|
}
|
|
4099
4565
|
|
|
@@ -4117,7 +4583,10 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4117
4583
|
object: this,
|
|
4118
4584
|
name: key
|
|
4119
4585
|
});
|
|
4120
|
-
|
|
4586
|
+
|
|
4587
|
+
if (!change) {
|
|
4588
|
+
return false;
|
|
4589
|
+
}
|
|
4121
4590
|
}
|
|
4122
4591
|
|
|
4123
4592
|
if (this.has_(key)) {
|
|
@@ -4133,7 +4602,10 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4133
4602
|
name: key
|
|
4134
4603
|
} : null;
|
|
4135
4604
|
|
|
4136
|
-
if ( notifySpy)
|
|
4605
|
+
if ( notifySpy) {
|
|
4606
|
+
spyReportStart(_change);
|
|
4607
|
+
} // TODO fix type
|
|
4608
|
+
|
|
4137
4609
|
|
|
4138
4610
|
transaction(function () {
|
|
4139
4611
|
var _this3$hasMap_$get;
|
|
@@ -4148,8 +4620,15 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4148
4620
|
|
|
4149
4621
|
_this3.data_["delete"](key);
|
|
4150
4622
|
});
|
|
4151
|
-
|
|
4152
|
-
if (
|
|
4623
|
+
|
|
4624
|
+
if (notify) {
|
|
4625
|
+
notifyListeners(this, _change);
|
|
4626
|
+
}
|
|
4627
|
+
|
|
4628
|
+
if ( notifySpy) {
|
|
4629
|
+
spyReportEnd();
|
|
4630
|
+
}
|
|
4631
|
+
|
|
4153
4632
|
return true;
|
|
4154
4633
|
}
|
|
4155
4634
|
|
|
@@ -4172,11 +4651,21 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4172
4651
|
name: key,
|
|
4173
4652
|
newValue: newValue
|
|
4174
4653
|
} : null;
|
|
4175
|
-
|
|
4654
|
+
|
|
4655
|
+
if ( notifySpy) {
|
|
4656
|
+
spyReportStart(change);
|
|
4657
|
+
} // TODO fix type
|
|
4658
|
+
|
|
4176
4659
|
|
|
4177
4660
|
observable.setNewValue_(newValue);
|
|
4178
|
-
|
|
4179
|
-
if (
|
|
4661
|
+
|
|
4662
|
+
if (notify) {
|
|
4663
|
+
notifyListeners(this, change);
|
|
4664
|
+
}
|
|
4665
|
+
|
|
4666
|
+
if ( notifySpy) {
|
|
4667
|
+
spyReportEnd();
|
|
4668
|
+
}
|
|
4180
4669
|
}
|
|
4181
4670
|
};
|
|
4182
4671
|
|
|
@@ -4207,14 +4696,26 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4207
4696
|
name: key,
|
|
4208
4697
|
newValue: newValue
|
|
4209
4698
|
} : null;
|
|
4210
|
-
if ( notifySpy) spyReportStart(change); // TODO fix type
|
|
4211
4699
|
|
|
4212
|
-
if (
|
|
4213
|
-
|
|
4700
|
+
if ( notifySpy) {
|
|
4701
|
+
spyReportStart(change);
|
|
4702
|
+
} // TODO fix type
|
|
4703
|
+
|
|
4704
|
+
|
|
4705
|
+
if (notify) {
|
|
4706
|
+
notifyListeners(this, change);
|
|
4707
|
+
}
|
|
4708
|
+
|
|
4709
|
+
if ( notifySpy) {
|
|
4710
|
+
spyReportEnd();
|
|
4711
|
+
}
|
|
4214
4712
|
};
|
|
4215
4713
|
|
|
4216
4714
|
_proto.get = function get(key) {
|
|
4217
|
-
if (this.has(key))
|
|
4715
|
+
if (this.has(key)) {
|
|
4716
|
+
return this.dehanceValue_(this.data_.get(key).get());
|
|
4717
|
+
}
|
|
4718
|
+
|
|
4218
4719
|
return this.dehanceValue_(undefined);
|
|
4219
4720
|
};
|
|
4220
4721
|
|
|
@@ -4288,18 +4789,27 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4288
4789
|
}
|
|
4289
4790
|
|
|
4290
4791
|
transaction(function () {
|
|
4291
|
-
if (isPlainObject(other))
|
|
4292
|
-
|
|
4293
|
-
|
|
4294
|
-
|
|
4295
|
-
|
|
4296
|
-
|
|
4297
|
-
|
|
4298
|
-
|
|
4792
|
+
if (isPlainObject(other)) {
|
|
4793
|
+
getPlainObjectKeys(other).forEach(function (key) {
|
|
4794
|
+
return _this5.set(key, other[key]);
|
|
4795
|
+
});
|
|
4796
|
+
} else if (Array.isArray(other)) {
|
|
4797
|
+
other.forEach(function (_ref) {
|
|
4798
|
+
var key = _ref[0],
|
|
4799
|
+
value = _ref[1];
|
|
4800
|
+
return _this5.set(key, value);
|
|
4801
|
+
});
|
|
4802
|
+
} else if (isES6Map(other)) {
|
|
4803
|
+
if (other.constructor !== Map) {
|
|
4804
|
+
die(19, other);
|
|
4805
|
+
}
|
|
4806
|
+
|
|
4299
4807
|
other.forEach(function (value, key) {
|
|
4300
4808
|
return _this5.set(key, value);
|
|
4301
4809
|
});
|
|
4302
|
-
} else if (other !== null && other !== undefined)
|
|
4810
|
+
} else if (other !== null && other !== undefined) {
|
|
4811
|
+
die(20, other);
|
|
4812
|
+
}
|
|
4303
4813
|
});
|
|
4304
4814
|
return this;
|
|
4305
4815
|
};
|
|
@@ -4430,7 +4940,10 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4430
4940
|
* for callback details
|
|
4431
4941
|
*/
|
|
4432
4942
|
_proto.observe_ = function observe_(listener, fireImmediately) {
|
|
4433
|
-
if ( fireImmediately === true)
|
|
4943
|
+
if ( fireImmediately === true) {
|
|
4944
|
+
die("`observe` doesn't support fireImmediately=true in combination with maps.");
|
|
4945
|
+
}
|
|
4946
|
+
|
|
4434
4947
|
return registerListener(this, listener);
|
|
4435
4948
|
};
|
|
4436
4949
|
|
|
@@ -4555,8 +5068,12 @@ var ObservableSet = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4555
5068
|
object: this,
|
|
4556
5069
|
newValue: value
|
|
4557
5070
|
});
|
|
4558
|
-
|
|
5071
|
+
|
|
5072
|
+
if (!change) {
|
|
5073
|
+
return this;
|
|
5074
|
+
} // ideally, value = change.value would be done here, so that values can be
|
|
4559
5075
|
// changed by interceptor. Same applies for other Set and Map api's.
|
|
5076
|
+
|
|
4560
5077
|
}
|
|
4561
5078
|
|
|
4562
5079
|
if (!this.has(value)) {
|
|
@@ -4576,9 +5093,17 @@ var ObservableSet = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4576
5093
|
newValue: value
|
|
4577
5094
|
} : null;
|
|
4578
5095
|
|
|
4579
|
-
if (notifySpy && "development" !== "production")
|
|
4580
|
-
|
|
4581
|
-
|
|
5096
|
+
if (notifySpy && "development" !== "production") {
|
|
5097
|
+
spyReportStart(_change);
|
|
5098
|
+
}
|
|
5099
|
+
|
|
5100
|
+
if (notify) {
|
|
5101
|
+
notifyListeners(this, _change);
|
|
5102
|
+
}
|
|
5103
|
+
|
|
5104
|
+
if (notifySpy && "development" !== "production") {
|
|
5105
|
+
spyReportEnd();
|
|
5106
|
+
}
|
|
4582
5107
|
}
|
|
4583
5108
|
|
|
4584
5109
|
return this;
|
|
@@ -4593,7 +5118,10 @@ var ObservableSet = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4593
5118
|
object: this,
|
|
4594
5119
|
oldValue: value
|
|
4595
5120
|
});
|
|
4596
|
-
|
|
5121
|
+
|
|
5122
|
+
if (!change) {
|
|
5123
|
+
return false;
|
|
5124
|
+
}
|
|
4597
5125
|
}
|
|
4598
5126
|
|
|
4599
5127
|
if (this.has(value)) {
|
|
@@ -4608,14 +5136,24 @@ var ObservableSet = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4608
5136
|
oldValue: value
|
|
4609
5137
|
} : null;
|
|
4610
5138
|
|
|
4611
|
-
if (notifySpy && "development" !== "production")
|
|
5139
|
+
if (notifySpy && "development" !== "production") {
|
|
5140
|
+
spyReportStart(_change2);
|
|
5141
|
+
}
|
|
5142
|
+
|
|
4612
5143
|
transaction(function () {
|
|
4613
5144
|
_this3.atom_.reportChanged();
|
|
4614
5145
|
|
|
4615
5146
|
_this3.data_["delete"](value);
|
|
4616
5147
|
});
|
|
4617
|
-
|
|
4618
|
-
if (
|
|
5148
|
+
|
|
5149
|
+
if (notify) {
|
|
5150
|
+
notifyListeners(this, _change2);
|
|
5151
|
+
}
|
|
5152
|
+
|
|
5153
|
+
if (notifySpy && "development" !== "production") {
|
|
5154
|
+
spyReportEnd();
|
|
5155
|
+
}
|
|
5156
|
+
|
|
4619
5157
|
return true;
|
|
4620
5158
|
}
|
|
4621
5159
|
|
|
@@ -4695,7 +5233,10 @@ var ObservableSet = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4695
5233
|
|
|
4696
5234
|
_proto.observe_ = function observe_(listener, fireImmediately) {
|
|
4697
5235
|
// ... 'fireImmediately' could also be true?
|
|
4698
|
-
if ( fireImmediately === true)
|
|
5236
|
+
if ( fireImmediately === true) {
|
|
5237
|
+
die("`observe` doesn't support fireImmediately=true in combination with sets.");
|
|
5238
|
+
}
|
|
5239
|
+
|
|
4699
5240
|
return registerListener(this, listener);
|
|
4700
5241
|
};
|
|
4701
5242
|
|
|
@@ -4797,7 +5338,11 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
4797
5338
|
name: key,
|
|
4798
5339
|
newValue: newValue
|
|
4799
5340
|
});
|
|
4800
|
-
|
|
5341
|
+
|
|
5342
|
+
if (!change) {
|
|
5343
|
+
return null;
|
|
5344
|
+
}
|
|
5345
|
+
|
|
4801
5346
|
newValue = change.newValue;
|
|
4802
5347
|
}
|
|
4803
5348
|
|
|
@@ -4817,10 +5362,18 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
4817
5362
|
newValue: newValue
|
|
4818
5363
|
} : null;
|
|
4819
5364
|
|
|
4820
|
-
if ( notifySpy)
|
|
5365
|
+
if ( notifySpy) {
|
|
5366
|
+
spyReportStart(_change);
|
|
5367
|
+
}
|
|
4821
5368
|
observable.setNewValue_(newValue);
|
|
4822
|
-
|
|
4823
|
-
if (
|
|
5369
|
+
|
|
5370
|
+
if (notify) {
|
|
5371
|
+
notifyListeners(this, _change);
|
|
5372
|
+
}
|
|
5373
|
+
|
|
5374
|
+
if ( notifySpy) {
|
|
5375
|
+
spyReportEnd();
|
|
5376
|
+
}
|
|
4824
5377
|
}
|
|
4825
5378
|
|
|
4826
5379
|
return true;
|
|
@@ -4929,12 +5482,18 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
4929
5482
|
|
|
4930
5483
|
if (descriptor) {
|
|
4931
5484
|
var outcome = annotation.make_(this, key, descriptor, source);
|
|
5485
|
+
|
|
4932
5486
|
if (outcome === 0
|
|
4933
5487
|
/* Cancel */
|
|
4934
|
-
)
|
|
5488
|
+
) {
|
|
5489
|
+
return;
|
|
5490
|
+
}
|
|
5491
|
+
|
|
4935
5492
|
if (outcome === 1
|
|
4936
5493
|
/* Break */
|
|
4937
|
-
)
|
|
5494
|
+
) {
|
|
5495
|
+
break;
|
|
5496
|
+
}
|
|
4938
5497
|
}
|
|
4939
5498
|
|
|
4940
5499
|
source = Object.getPrototypeOf(source);
|
|
@@ -5004,7 +5563,11 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
5004
5563
|
type: ADD,
|
|
5005
5564
|
newValue: descriptor.value
|
|
5006
5565
|
});
|
|
5007
|
-
|
|
5566
|
+
|
|
5567
|
+
if (!change) {
|
|
5568
|
+
return null;
|
|
5569
|
+
}
|
|
5570
|
+
|
|
5008
5571
|
var newValue = change.newValue;
|
|
5009
5572
|
|
|
5010
5573
|
if (descriptor.value !== newValue) {
|
|
@@ -5056,7 +5619,11 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
5056
5619
|
type: ADD,
|
|
5057
5620
|
newValue: value
|
|
5058
5621
|
});
|
|
5059
|
-
|
|
5622
|
+
|
|
5623
|
+
if (!change) {
|
|
5624
|
+
return null;
|
|
5625
|
+
}
|
|
5626
|
+
|
|
5060
5627
|
value = change.newValue;
|
|
5061
5628
|
}
|
|
5062
5629
|
|
|
@@ -5111,7 +5678,10 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
5111
5678
|
type: ADD,
|
|
5112
5679
|
newValue: undefined
|
|
5113
5680
|
});
|
|
5114
|
-
|
|
5681
|
+
|
|
5682
|
+
if (!change) {
|
|
5683
|
+
return null;
|
|
5684
|
+
}
|
|
5115
5685
|
}
|
|
5116
5686
|
|
|
5117
5687
|
options.name || (options.name = "development" !== "production" ? this.name_ + "." + key.toString() : "ObservableObject.key");
|
|
@@ -5167,7 +5737,9 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
5167
5737
|
type: REMOVE
|
|
5168
5738
|
}); // Cancelled
|
|
5169
5739
|
|
|
5170
|
-
if (!change)
|
|
5740
|
+
if (!change) {
|
|
5741
|
+
return null;
|
|
5742
|
+
}
|
|
5171
5743
|
} // Delete
|
|
5172
5744
|
|
|
5173
5745
|
|
|
@@ -5228,9 +5800,18 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
5228
5800
|
oldValue: value,
|
|
5229
5801
|
name: key
|
|
5230
5802
|
};
|
|
5231
|
-
|
|
5232
|
-
if (
|
|
5233
|
-
|
|
5803
|
+
|
|
5804
|
+
if ("development" !== "production" && notifySpy) {
|
|
5805
|
+
spyReportStart(_change2);
|
|
5806
|
+
}
|
|
5807
|
+
|
|
5808
|
+
if (notify) {
|
|
5809
|
+
notifyListeners(this, _change2);
|
|
5810
|
+
}
|
|
5811
|
+
|
|
5812
|
+
if ("development" !== "production" && notifySpy) {
|
|
5813
|
+
spyReportEnd();
|
|
5814
|
+
}
|
|
5234
5815
|
}
|
|
5235
5816
|
} finally {
|
|
5236
5817
|
endBatch();
|
|
@@ -5246,7 +5827,10 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
5246
5827
|
;
|
|
5247
5828
|
|
|
5248
5829
|
_proto.observe_ = function observe_(callback, fireImmediately) {
|
|
5249
|
-
if ( fireImmediately === true)
|
|
5830
|
+
if ( fireImmediately === true) {
|
|
5831
|
+
die("`observe` doesn't support the fire immediately property for observable objects.");
|
|
5832
|
+
}
|
|
5833
|
+
|
|
5250
5834
|
return registerListener(this, callback);
|
|
5251
5835
|
};
|
|
5252
5836
|
|
|
@@ -5269,9 +5853,18 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
5269
5853
|
name: key,
|
|
5270
5854
|
newValue: value
|
|
5271
5855
|
} : null;
|
|
5272
|
-
|
|
5273
|
-
if (
|
|
5274
|
-
|
|
5856
|
+
|
|
5857
|
+
if ( notifySpy) {
|
|
5858
|
+
spyReportStart(change);
|
|
5859
|
+
}
|
|
5860
|
+
|
|
5861
|
+
if (notify) {
|
|
5862
|
+
notifyListeners(this, change);
|
|
5863
|
+
}
|
|
5864
|
+
|
|
5865
|
+
if ( notifySpy) {
|
|
5866
|
+
spyReportEnd();
|
|
5867
|
+
}
|
|
5275
5868
|
}
|
|
5276
5869
|
|
|
5277
5870
|
(_this$pendingKeys_2 = this.pendingKeys_) == null ? void 0 : (_this$pendingKeys_2$g = _this$pendingKeys_2.get(key)) == null ? void 0 : _this$pendingKeys_2$g.set(true); // Notify "keys/entries/values" observers
|
|
@@ -5312,7 +5905,10 @@ function asObservableObject(target, options) {
|
|
|
5312
5905
|
return target;
|
|
5313
5906
|
}
|
|
5314
5907
|
|
|
5315
|
-
if ( !Object.isExtensible(target))
|
|
5908
|
+
if ( !Object.isExtensible(target)) {
|
|
5909
|
+
die("Cannot make the designated object observable; it is not extensible");
|
|
5910
|
+
}
|
|
5911
|
+
|
|
5316
5912
|
var name = (_options$name = options == null ? void 0 : options.name) != null ? _options$name : (isPlainObject(target) ? "ObservableObject" : target.constructor.name) + "@" + getNextId() ;
|
|
5317
5913
|
var adm = new ObservableObjectAdministration(target, new Map(), String(name), getAnnotationFromOptions(options));
|
|
5318
5914
|
addHiddenProp(target, $mobx, adm);
|
|
@@ -5469,7 +6065,6 @@ var LegacyObservableArray = /*#__PURE__*/function (_StubArray, _Symbol$toStringT
|
|
|
5469
6065
|
var nextIndex = 0;
|
|
5470
6066
|
return makeIterable({
|
|
5471
6067
|
next: function next() {
|
|
5472
|
-
// @ts-ignore
|
|
5473
6068
|
return nextIndex < self.length ? {
|
|
5474
6069
|
value: self[nextIndex++],
|
|
5475
6070
|
done: false
|
|
@@ -5502,7 +6097,10 @@ var LegacyObservableArray = /*#__PURE__*/function (_StubArray, _Symbol$toStringT
|
|
|
5502
6097
|
Object.entries(arrayExtensions).forEach(function (_ref) {
|
|
5503
6098
|
var prop = _ref[0],
|
|
5504
6099
|
fn = _ref[1];
|
|
5505
|
-
|
|
6100
|
+
|
|
6101
|
+
if (prop !== "concat") {
|
|
6102
|
+
addHiddenProp(LegacyObservableArray.prototype, prop, fn);
|
|
6103
|
+
}
|
|
5506
6104
|
});
|
|
5507
6105
|
|
|
5508
6106
|
function createArrayEntryDescriptor(index) {
|
|
@@ -5539,7 +6137,10 @@ function createLegacyArray(initialValues, enhancer, name) {
|
|
|
5539
6137
|
function getAtom(thing, property) {
|
|
5540
6138
|
if (typeof thing === "object" && thing !== null) {
|
|
5541
6139
|
if (isObservableArray(thing)) {
|
|
5542
|
-
if (property !== undefined)
|
|
6140
|
+
if (property !== undefined) {
|
|
6141
|
+
die(23);
|
|
6142
|
+
}
|
|
6143
|
+
|
|
5543
6144
|
return thing[$mobx].atom_;
|
|
5544
6145
|
}
|
|
5545
6146
|
|
|
@@ -5548,18 +6149,31 @@ function getAtom(thing, property) {
|
|
|
5548
6149
|
}
|
|
5549
6150
|
|
|
5550
6151
|
if (isObservableMap(thing)) {
|
|
5551
|
-
if (property === undefined)
|
|
6152
|
+
if (property === undefined) {
|
|
6153
|
+
return thing.keysAtom_;
|
|
6154
|
+
}
|
|
6155
|
+
|
|
5552
6156
|
var observable = thing.data_.get(property) || thing.hasMap_.get(property);
|
|
5553
|
-
|
|
6157
|
+
|
|
6158
|
+
if (!observable) {
|
|
6159
|
+
die(25, property, getDebugName(thing));
|
|
6160
|
+
}
|
|
6161
|
+
|
|
5554
6162
|
return observable;
|
|
5555
6163
|
}
|
|
5556
6164
|
|
|
6165
|
+
|
|
5557
6166
|
if (isObservableObject(thing)) {
|
|
5558
|
-
if (!property)
|
|
6167
|
+
if (!property) {
|
|
6168
|
+
return die(26);
|
|
6169
|
+
}
|
|
5559
6170
|
|
|
5560
6171
|
var _observable = thing[$mobx].values_.get(property);
|
|
5561
6172
|
|
|
5562
|
-
if (!_observable)
|
|
6173
|
+
if (!_observable) {
|
|
6174
|
+
die(27, property, getDebugName(thing));
|
|
6175
|
+
}
|
|
6176
|
+
|
|
5563
6177
|
return _observable;
|
|
5564
6178
|
}
|
|
5565
6179
|
|
|
@@ -5576,11 +6190,26 @@ function getAtom(thing, property) {
|
|
|
5576
6190
|
die(28);
|
|
5577
6191
|
}
|
|
5578
6192
|
function getAdministration(thing, property) {
|
|
5579
|
-
if (!thing)
|
|
5580
|
-
|
|
5581
|
-
|
|
5582
|
-
|
|
5583
|
-
if (
|
|
6193
|
+
if (!thing) {
|
|
6194
|
+
die(29);
|
|
6195
|
+
}
|
|
6196
|
+
|
|
6197
|
+
if (property !== undefined) {
|
|
6198
|
+
return getAdministration(getAtom(thing, property));
|
|
6199
|
+
}
|
|
6200
|
+
|
|
6201
|
+
if (isAtom(thing) || isComputedValue(thing) || isReaction(thing)) {
|
|
6202
|
+
return thing;
|
|
6203
|
+
}
|
|
6204
|
+
|
|
6205
|
+
if (isObservableMap(thing) || isObservableSet(thing)) {
|
|
6206
|
+
return thing;
|
|
6207
|
+
}
|
|
6208
|
+
|
|
6209
|
+
if (thing[$mobx]) {
|
|
6210
|
+
return thing[$mobx];
|
|
6211
|
+
}
|
|
6212
|
+
|
|
5584
6213
|
die(24, thing);
|
|
5585
6214
|
}
|
|
5586
6215
|
function getDebugName(thing, property) {
|
|
@@ -5613,17 +6242,33 @@ function deepEqual(a, b, depth) {
|
|
|
5613
6242
|
function eq(a, b, depth, aStack, bStack) {
|
|
5614
6243
|
// Identical objects are equal. `0 === -0`, but they aren't identical.
|
|
5615
6244
|
// See the [Harmony `egal` proposal](http://wiki.ecmascript.org/doku.php?id=harmony:egal).
|
|
5616
|
-
if (a === b)
|
|
6245
|
+
if (a === b) {
|
|
6246
|
+
return a !== 0 || 1 / a === 1 / b;
|
|
6247
|
+
} // `null` or `undefined` only equal to itself (strict comparison).
|
|
6248
|
+
|
|
6249
|
+
|
|
6250
|
+
if (a == null || b == null) {
|
|
6251
|
+
return false;
|
|
6252
|
+
} // `NaN`s are equivalent, but non-reflexive.
|
|
6253
|
+
|
|
5617
6254
|
|
|
5618
|
-
if (a
|
|
6255
|
+
if (a !== a) {
|
|
6256
|
+
return b !== b;
|
|
6257
|
+
} // Exhaust primitive checks
|
|
5619
6258
|
|
|
5620
|
-
if (a !== a) return b !== b; // Exhaust primitive checks
|
|
5621
6259
|
|
|
5622
6260
|
var type = typeof a;
|
|
5623
|
-
|
|
6261
|
+
|
|
6262
|
+
if (type !== "function" && type !== "object" && typeof b != "object") {
|
|
6263
|
+
return false;
|
|
6264
|
+
} // Compare `[[Class]]` names.
|
|
6265
|
+
|
|
5624
6266
|
|
|
5625
6267
|
var className = toString.call(a);
|
|
5626
|
-
|
|
6268
|
+
|
|
6269
|
+
if (className !== toString.call(b)) {
|
|
6270
|
+
return false;
|
|
6271
|
+
}
|
|
5627
6272
|
|
|
5628
6273
|
switch (className) {
|
|
5629
6274
|
// Strings, numbers, regular expressions, dates, and booleans are compared by value.
|
|
@@ -5637,7 +6282,10 @@ function eq(a, b, depth, aStack, bStack) {
|
|
|
5637
6282
|
case "[object Number]":
|
|
5638
6283
|
// `NaN`s are equivalent, but non-reflexive.
|
|
5639
6284
|
// Object(NaN) is equivalent to NaN.
|
|
5640
|
-
if (+a !== +a)
|
|
6285
|
+
if (+a !== +a) {
|
|
6286
|
+
return +b !== +b;
|
|
6287
|
+
} // An `egal` comparison is performed for other numeric values.
|
|
6288
|
+
|
|
5641
6289
|
|
|
5642
6290
|
return +a === 0 ? 1 / +a === 1 / b : +a === +b;
|
|
5643
6291
|
|
|
@@ -5668,9 +6316,12 @@ function eq(a, b, depth, aStack, bStack) {
|
|
|
5668
6316
|
var areArrays = className === "[object Array]";
|
|
5669
6317
|
|
|
5670
6318
|
if (!areArrays) {
|
|
5671
|
-
if (typeof a != "object" || typeof b != "object")
|
|
6319
|
+
if (typeof a != "object" || typeof b != "object") {
|
|
6320
|
+
return false;
|
|
6321
|
+
} // Objects with different constructors are not equivalent, but `Object`s or `Array`s
|
|
5672
6322
|
// from different frames are.
|
|
5673
6323
|
|
|
6324
|
+
|
|
5674
6325
|
var aCtor = a.constructor,
|
|
5675
6326
|
bCtor = b.constructor;
|
|
5676
6327
|
|
|
@@ -5696,7 +6347,9 @@ function eq(a, b, depth, aStack, bStack) {
|
|
|
5696
6347
|
while (length--) {
|
|
5697
6348
|
// Linear search. Performance is inversely proportional to the number of
|
|
5698
6349
|
// unique nested structures.
|
|
5699
|
-
if (aStack[length] === a)
|
|
6350
|
+
if (aStack[length] === a) {
|
|
6351
|
+
return bStack[length] === b;
|
|
6352
|
+
}
|
|
5700
6353
|
} // Add the first object to the stack of traversed objects.
|
|
5701
6354
|
|
|
5702
6355
|
|
|
@@ -5706,10 +6359,16 @@ function eq(a, b, depth, aStack, bStack) {
|
|
|
5706
6359
|
if (areArrays) {
|
|
5707
6360
|
// Compare array lengths to determine if a deep comparison is necessary.
|
|
5708
6361
|
length = a.length;
|
|
5709
|
-
|
|
6362
|
+
|
|
6363
|
+
if (length !== b.length) {
|
|
6364
|
+
return false;
|
|
6365
|
+
} // Deep compare the contents, ignoring non-numeric properties.
|
|
6366
|
+
|
|
5710
6367
|
|
|
5711
6368
|
while (length--) {
|
|
5712
|
-
if (!eq(a[length], b[length], depth - 1, aStack, bStack))
|
|
6369
|
+
if (!eq(a[length], b[length], depth - 1, aStack, bStack)) {
|
|
6370
|
+
return false;
|
|
6371
|
+
}
|
|
5713
6372
|
}
|
|
5714
6373
|
} else {
|
|
5715
6374
|
// Deep compare objects.
|
|
@@ -5717,12 +6376,17 @@ function eq(a, b, depth, aStack, bStack) {
|
|
|
5717
6376
|
var key;
|
|
5718
6377
|
length = keys.length; // Ensure that both objects contain the same number of properties before comparing deep equality.
|
|
5719
6378
|
|
|
5720
|
-
if (Object.keys(b).length !== length)
|
|
6379
|
+
if (Object.keys(b).length !== length) {
|
|
6380
|
+
return false;
|
|
6381
|
+
}
|
|
5721
6382
|
|
|
5722
6383
|
while (length--) {
|
|
5723
6384
|
// Deep compare each member
|
|
5724
6385
|
key = keys[length];
|
|
5725
|
-
|
|
6386
|
+
|
|
6387
|
+
if (!(hasProp(b, key) && eq(a[key], b[key], depth - 1, aStack, bStack))) {
|
|
6388
|
+
return false;
|
|
6389
|
+
}
|
|
5726
6390
|
}
|
|
5727
6391
|
} // Remove the first object from the stack of traversed objects.
|
|
5728
6392
|
|
|
@@ -5733,9 +6397,18 @@ function eq(a, b, depth, aStack, bStack) {
|
|
|
5733
6397
|
}
|
|
5734
6398
|
|
|
5735
6399
|
function unwrap(a) {
|
|
5736
|
-
if (isObservableArray(a))
|
|
5737
|
-
|
|
5738
|
-
|
|
6400
|
+
if (isObservableArray(a)) {
|
|
6401
|
+
return a.slice();
|
|
6402
|
+
}
|
|
6403
|
+
|
|
6404
|
+
if (isES6Map(a) || isObservableMap(a)) {
|
|
6405
|
+
return Array.from(a.entries());
|
|
6406
|
+
}
|
|
6407
|
+
|
|
6408
|
+
if (isES6Set(a) || isObservableSet(a)) {
|
|
6409
|
+
return Array.from(a.entries());
|
|
6410
|
+
}
|
|
6411
|
+
|
|
5739
6412
|
return a;
|
|
5740
6413
|
}
|
|
5741
6414
|
|