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
|
@@ -23,9 +23,9 @@ var niceErrors = {
|
|
|
23
23
|
10: "'has()' can only be used on observable objects, arrays and maps",
|
|
24
24
|
11: "'get()' can only be used on observable objects, arrays and maps",
|
|
25
25
|
12: "Invalid annotation",
|
|
26
|
-
13: "Dynamic observable objects cannot be frozen",
|
|
26
|
+
13: "Dynamic observable objects cannot be frozen. If you're passing observables to 3rd party component/function that calls Object.freeze, pass copy instead: toJS(observable)",
|
|
27
27
|
14: "Intercept handlers should return nothing or a change object",
|
|
28
|
-
15: "Observable arrays cannot be frozen",
|
|
28
|
+
15: "Observable arrays cannot be frozen. If you're passing observables to 3rd party component/function that calls Object.freeze, pass copy instead: toJS(observable)",
|
|
29
29
|
16: "Modification exception: the internal structure of an observable array was changed.",
|
|
30
30
|
17: function _(index, length) {
|
|
31
31
|
return "[mobx.array] Index out of bounds, " + index + " is larger than " + length;
|
|
@@ -139,7 +139,10 @@ function getNextId() {
|
|
|
139
139
|
function once(func) {
|
|
140
140
|
var invoked = false;
|
|
141
141
|
return function () {
|
|
142
|
-
if (invoked)
|
|
142
|
+
if (invoked) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
|
|
143
146
|
invoked = true;
|
|
144
147
|
return func.apply(this, arguments);
|
|
145
148
|
};
|
|
@@ -164,17 +167,31 @@ function isObject(value) {
|
|
|
164
167
|
return value !== null && typeof value === "object";
|
|
165
168
|
}
|
|
166
169
|
function isPlainObject(value) {
|
|
167
|
-
if (!isObject(value))
|
|
170
|
+
if (!isObject(value)) {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
|
|
168
174
|
var proto = Object.getPrototypeOf(value);
|
|
169
|
-
|
|
175
|
+
|
|
176
|
+
if (proto == null) {
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
|
|
170
180
|
var protoConstructor = Object.hasOwnProperty.call(proto, "constructor") && proto.constructor;
|
|
171
181
|
return typeof protoConstructor === "function" && protoConstructor.toString() === plainObjectString;
|
|
172
182
|
} // https://stackoverflow.com/a/37865170
|
|
173
183
|
|
|
174
184
|
function isGenerator(obj) {
|
|
175
185
|
var constructor = obj == null ? void 0 : obj.constructor;
|
|
176
|
-
|
|
177
|
-
if (
|
|
186
|
+
|
|
187
|
+
if (!constructor) {
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if ("GeneratorFunction" === constructor.name || "GeneratorFunction" === constructor.displayName) {
|
|
192
|
+
return true;
|
|
193
|
+
}
|
|
194
|
+
|
|
178
195
|
return false;
|
|
179
196
|
}
|
|
180
197
|
function addHiddenProp(object, propName, value) {
|
|
@@ -214,9 +231,16 @@ var hasGetOwnPropertySymbols = typeof Object.getOwnPropertySymbols !== "undefine
|
|
|
214
231
|
function getPlainObjectKeys(object) {
|
|
215
232
|
var keys = Object.keys(object); // Not supported in IE, so there are not going to be symbol props anyway...
|
|
216
233
|
|
|
217
|
-
if (!hasGetOwnPropertySymbols)
|
|
234
|
+
if (!hasGetOwnPropertySymbols) {
|
|
235
|
+
return keys;
|
|
236
|
+
}
|
|
237
|
+
|
|
218
238
|
var symbols = Object.getOwnPropertySymbols(object);
|
|
219
|
-
|
|
239
|
+
|
|
240
|
+
if (!symbols.length) {
|
|
241
|
+
return keys;
|
|
242
|
+
}
|
|
243
|
+
|
|
220
244
|
return [].concat(keys, symbols.filter(function (s) {
|
|
221
245
|
return objectPrototype.propertyIsEnumerable.call(object, s);
|
|
222
246
|
}));
|
|
@@ -229,8 +253,14 @@ var ownKeys = typeof Reflect !== "undefined" && Reflect.ownKeys ? Reflect.ownKey
|
|
|
229
253
|
/* istanbul ignore next */
|
|
230
254
|
Object.getOwnPropertyNames;
|
|
231
255
|
function stringifyKey(key) {
|
|
232
|
-
if (typeof key === "string")
|
|
233
|
-
|
|
256
|
+
if (typeof key === "string") {
|
|
257
|
+
return key;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if (typeof key === "symbol") {
|
|
261
|
+
return key.toString();
|
|
262
|
+
}
|
|
263
|
+
|
|
234
264
|
return new String(key).toString();
|
|
235
265
|
}
|
|
236
266
|
function toPrimitive(value) {
|
|
@@ -518,7 +548,10 @@ function shallowComparer(a, b) {
|
|
|
518
548
|
}
|
|
519
549
|
|
|
520
550
|
function defaultComparer(a, b) {
|
|
521
|
-
if (Object.is)
|
|
551
|
+
if (Object.is) {
|
|
552
|
+
return Object.is(a, b);
|
|
553
|
+
}
|
|
554
|
+
|
|
522
555
|
return a === b ? a !== 0 || 1 / a === 1 / b : a !== a && b !== b;
|
|
523
556
|
}
|
|
524
557
|
|
|
@@ -531,20 +564,34 @@ var comparer = {
|
|
|
531
564
|
|
|
532
565
|
function deepEnhancer(v, _, name) {
|
|
533
566
|
// it is an observable already, done
|
|
534
|
-
if (isObservable(v))
|
|
567
|
+
if (isObservable(v)) {
|
|
568
|
+
return v;
|
|
569
|
+
} // something that can be converted and mutated?
|
|
535
570
|
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
}
|
|
571
|
+
|
|
572
|
+
if (Array.isArray(v)) {
|
|
573
|
+
return observable.array(v, {
|
|
574
|
+
name: name
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
if (isPlainObject(v)) {
|
|
579
|
+
return observable.object(v, undefined, {
|
|
580
|
+
name: name
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
if (isES6Map(v)) {
|
|
585
|
+
return observable.map(v, {
|
|
586
|
+
name: name
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
if (isES6Set(v)) {
|
|
591
|
+
return observable.set(v, {
|
|
592
|
+
name: name
|
|
593
|
+
});
|
|
594
|
+
}
|
|
548
595
|
|
|
549
596
|
if (typeof v === "function" && !isAction(v) && !isFlow(v)) {
|
|
550
597
|
if (isGenerator(v)) {
|
|
@@ -557,33 +604,59 @@ function deepEnhancer(v, _, name) {
|
|
|
557
604
|
return v;
|
|
558
605
|
}
|
|
559
606
|
function shallowEnhancer(v, _, name) {
|
|
560
|
-
if (v === undefined || v === null)
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
607
|
+
if (v === undefined || v === null) {
|
|
608
|
+
return v;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
if (isObservableObject(v) || isObservableArray(v) || isObservableMap(v) || isObservableSet(v)) {
|
|
612
|
+
return v;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
if (Array.isArray(v)) {
|
|
616
|
+
return observable.array(v, {
|
|
617
|
+
name: name,
|
|
618
|
+
deep: false
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
if (isPlainObject(v)) {
|
|
623
|
+
return observable.object(v, undefined, {
|
|
624
|
+
name: name,
|
|
625
|
+
deep: false
|
|
626
|
+
});
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
if (isES6Map(v)) {
|
|
630
|
+
return observable.map(v, {
|
|
631
|
+
name: name,
|
|
632
|
+
deep: false
|
|
633
|
+
});
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
if (isES6Set(v)) {
|
|
637
|
+
return observable.set(v, {
|
|
638
|
+
name: name,
|
|
639
|
+
deep: false
|
|
640
|
+
});
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
{
|
|
644
|
+
die("The shallow modifier / decorator can only used in combination with arrays, objects, maps and sets");
|
|
645
|
+
}
|
|
579
646
|
}
|
|
580
647
|
function referenceEnhancer(newValue) {
|
|
581
648
|
// never turn into an observable
|
|
582
649
|
return newValue;
|
|
583
650
|
}
|
|
584
651
|
function refStructEnhancer(v, oldValue) {
|
|
585
|
-
if ( isObservable(v))
|
|
586
|
-
|
|
652
|
+
if ( isObservable(v)) {
|
|
653
|
+
die("observable.struct should not be used with observable values");
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
if (deepEqual(v, oldValue)) {
|
|
657
|
+
return oldValue;
|
|
658
|
+
}
|
|
659
|
+
|
|
587
660
|
return v;
|
|
588
661
|
}
|
|
589
662
|
|
|
@@ -732,9 +805,11 @@ function make_$2(adm, key, descriptor, source) {
|
|
|
732
805
|
|
|
733
806
|
|
|
734
807
|
if ((_this$options_ = this.options_) != null && _this$options_.bound && (!hasProp(adm.target_, key) || !isFlow(adm.target_[key]))) {
|
|
735
|
-
if (this.extend_(adm, key, descriptor, false) === null)
|
|
736
|
-
|
|
737
|
-
|
|
808
|
+
if (this.extend_(adm, key, descriptor, false) === null) {
|
|
809
|
+
return 0
|
|
810
|
+
/* Cancel */
|
|
811
|
+
;
|
|
812
|
+
}
|
|
738
813
|
}
|
|
739
814
|
|
|
740
815
|
if (isFlow(descriptor.value)) {
|
|
@@ -1025,17 +1100,35 @@ function createObservable(v, arg2, arg3) {
|
|
|
1025
1100
|
} // already observable - ignore
|
|
1026
1101
|
|
|
1027
1102
|
|
|
1028
|
-
if (isObservable(v))
|
|
1103
|
+
if (isObservable(v)) {
|
|
1104
|
+
return v;
|
|
1105
|
+
} // plain object
|
|
1106
|
+
|
|
1107
|
+
|
|
1108
|
+
if (isPlainObject(v)) {
|
|
1109
|
+
return observable.object(v, arg2, arg3);
|
|
1110
|
+
} // Array
|
|
1111
|
+
|
|
1112
|
+
|
|
1113
|
+
if (Array.isArray(v)) {
|
|
1114
|
+
return observable.array(v, arg2);
|
|
1115
|
+
} // Map
|
|
1116
|
+
|
|
1029
1117
|
|
|
1030
|
-
if (
|
|
1118
|
+
if (isES6Map(v)) {
|
|
1119
|
+
return observable.map(v, arg2);
|
|
1120
|
+
} // Set
|
|
1031
1121
|
|
|
1032
|
-
if (Array.isArray(v)) return observable.array(v, arg2); // Map
|
|
1033
1122
|
|
|
1034
|
-
if (
|
|
1123
|
+
if (isES6Set(v)) {
|
|
1124
|
+
return observable.set(v, arg2);
|
|
1125
|
+
} // other object - ignore
|
|
1035
1126
|
|
|
1036
|
-
if (isES6Set(v)) return observable.set(v, arg2); // other object - ignore
|
|
1037
1127
|
|
|
1038
|
-
if (typeof v === "object" && v !== null)
|
|
1128
|
+
if (typeof v === "object" && v !== null) {
|
|
1129
|
+
return v;
|
|
1130
|
+
} // anything else
|
|
1131
|
+
|
|
1039
1132
|
|
|
1040
1133
|
return observable.box(v, arg2);
|
|
1041
1134
|
}
|
|
@@ -1093,8 +1186,13 @@ var computed = function computed(arg1, arg2) {
|
|
|
1093
1186
|
|
|
1094
1187
|
|
|
1095
1188
|
{
|
|
1096
|
-
if (!isFunction(arg1))
|
|
1097
|
-
|
|
1189
|
+
if (!isFunction(arg1)) {
|
|
1190
|
+
die("First argument to `computed` should be an expression.");
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
if (isFunction(arg2)) {
|
|
1194
|
+
die("A setter as second argument is no longer supported, use `{ set: fn }` option instead");
|
|
1195
|
+
}
|
|
1098
1196
|
}
|
|
1099
1197
|
|
|
1100
1198
|
var opts = isPlainObject(arg2) ? arg2 : {};
|
|
@@ -1126,8 +1224,13 @@ function createAction(actionName, fn, autoAction, ref) {
|
|
|
1126
1224
|
}
|
|
1127
1225
|
|
|
1128
1226
|
{
|
|
1129
|
-
if (!isFunction(fn))
|
|
1130
|
-
|
|
1227
|
+
if (!isFunction(fn)) {
|
|
1228
|
+
die("`action` can only be invoked on functions");
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1231
|
+
if (typeof actionName !== "string" || !actionName) {
|
|
1232
|
+
die("actions should have valid names, got: '" + actionName + "'");
|
|
1233
|
+
}
|
|
1131
1234
|
}
|
|
1132
1235
|
|
|
1133
1236
|
function res() {
|
|
@@ -1209,7 +1312,10 @@ function _endAction(runInfo) {
|
|
|
1209
1312
|
allowStateChangesEnd(runInfo.prevAllowStateChanges_);
|
|
1210
1313
|
allowStateReadsEnd(runInfo.prevAllowStateReads_);
|
|
1211
1314
|
endBatch();
|
|
1212
|
-
|
|
1315
|
+
|
|
1316
|
+
if (runInfo.runAsAction_) {
|
|
1317
|
+
untrackedEnd(runInfo.prevDerivation_);
|
|
1318
|
+
}
|
|
1213
1319
|
|
|
1214
1320
|
if ( runInfo.notifySpy_) {
|
|
1215
1321
|
spyReportEnd({
|
|
@@ -1289,7 +1395,10 @@ var ObservableValue = /*#__PURE__*/function (_Atom, _Symbol$toPrimitive2) {
|
|
|
1289
1395
|
var _proto = ObservableValue.prototype;
|
|
1290
1396
|
|
|
1291
1397
|
_proto.dehanceValue = function dehanceValue(value) {
|
|
1292
|
-
if (this.dehancer !== undefined)
|
|
1398
|
+
if (this.dehancer !== undefined) {
|
|
1399
|
+
return this.dehancer(value);
|
|
1400
|
+
}
|
|
1401
|
+
|
|
1293
1402
|
return value;
|
|
1294
1403
|
};
|
|
1295
1404
|
|
|
@@ -1312,7 +1421,10 @@ var ObservableValue = /*#__PURE__*/function (_Atom, _Symbol$toPrimitive2) {
|
|
|
1312
1421
|
}
|
|
1313
1422
|
|
|
1314
1423
|
this.setNewValue_(newValue);
|
|
1315
|
-
|
|
1424
|
+
|
|
1425
|
+
if ( notifySpy) {
|
|
1426
|
+
spyReportEnd();
|
|
1427
|
+
}
|
|
1316
1428
|
}
|
|
1317
1429
|
};
|
|
1318
1430
|
|
|
@@ -1325,7 +1437,11 @@ var ObservableValue = /*#__PURE__*/function (_Atom, _Symbol$toPrimitive2) {
|
|
|
1325
1437
|
type: UPDATE,
|
|
1326
1438
|
newValue: newValue
|
|
1327
1439
|
});
|
|
1328
|
-
|
|
1440
|
+
|
|
1441
|
+
if (!change) {
|
|
1442
|
+
return globalState.UNCHANGED;
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1329
1445
|
newValue = change.newValue;
|
|
1330
1446
|
} // apply modifier
|
|
1331
1447
|
|
|
@@ -1359,14 +1475,17 @@ var ObservableValue = /*#__PURE__*/function (_Atom, _Symbol$toPrimitive2) {
|
|
|
1359
1475
|
};
|
|
1360
1476
|
|
|
1361
1477
|
_proto.observe_ = function observe_(listener, fireImmediately) {
|
|
1362
|
-
if (fireImmediately)
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1478
|
+
if (fireImmediately) {
|
|
1479
|
+
listener({
|
|
1480
|
+
observableKind: "value",
|
|
1481
|
+
debugObjectName: this.name_,
|
|
1482
|
+
object: this,
|
|
1483
|
+
type: UPDATE,
|
|
1484
|
+
newValue: this.value_,
|
|
1485
|
+
oldValue: undefined
|
|
1486
|
+
});
|
|
1487
|
+
}
|
|
1488
|
+
|
|
1370
1489
|
return registerListener(this, listener);
|
|
1371
1490
|
};
|
|
1372
1491
|
|
|
@@ -1461,7 +1580,11 @@ var ComputedValue = /*#__PURE__*/function (_Symbol$toPrimitive2) {
|
|
|
1461
1580
|
this.keepAlive_ = void 0;
|
|
1462
1581
|
this.onBOL = void 0;
|
|
1463
1582
|
this.onBUOL = void 0;
|
|
1464
|
-
|
|
1583
|
+
|
|
1584
|
+
if (!options.get) {
|
|
1585
|
+
die(31);
|
|
1586
|
+
}
|
|
1587
|
+
|
|
1465
1588
|
this.derivation = options.get;
|
|
1466
1589
|
this.name_ = options.name || ( "ComputedValue@" + getNextId() );
|
|
1467
1590
|
|
|
@@ -1503,7 +1626,9 @@ var ComputedValue = /*#__PURE__*/function (_Symbol$toPrimitive2) {
|
|
|
1503
1626
|
;
|
|
1504
1627
|
|
|
1505
1628
|
_proto.get = function get() {
|
|
1506
|
-
if (this.isComputing_)
|
|
1629
|
+
if (this.isComputing_) {
|
|
1630
|
+
die(32, this.name_, this.derivation);
|
|
1631
|
+
}
|
|
1507
1632
|
|
|
1508
1633
|
if (globalState.inBatch === 0 && // !globalState.trackingDerivatpion &&
|
|
1509
1634
|
this.observers_.size === 0 && !this.keepAlive_) {
|
|
@@ -1519,20 +1644,34 @@ var ComputedValue = /*#__PURE__*/function (_Symbol$toPrimitive2) {
|
|
|
1519
1644
|
|
|
1520
1645
|
if (shouldCompute(this)) {
|
|
1521
1646
|
var prevTrackingContext = globalState.trackingContext;
|
|
1522
|
-
|
|
1523
|
-
if (this.
|
|
1647
|
+
|
|
1648
|
+
if (this.keepAlive_ && !prevTrackingContext) {
|
|
1649
|
+
globalState.trackingContext = this;
|
|
1650
|
+
}
|
|
1651
|
+
|
|
1652
|
+
if (this.trackAndCompute()) {
|
|
1653
|
+
propagateChangeConfirmed(this);
|
|
1654
|
+
}
|
|
1655
|
+
|
|
1524
1656
|
globalState.trackingContext = prevTrackingContext;
|
|
1525
1657
|
}
|
|
1526
1658
|
}
|
|
1527
1659
|
|
|
1528
1660
|
var result = this.value_;
|
|
1529
|
-
|
|
1661
|
+
|
|
1662
|
+
if (isCaughtException(result)) {
|
|
1663
|
+
throw result.cause;
|
|
1664
|
+
}
|
|
1665
|
+
|
|
1530
1666
|
return result;
|
|
1531
1667
|
};
|
|
1532
1668
|
|
|
1533
1669
|
_proto.set = function set(value) {
|
|
1534
1670
|
if (this.setter_) {
|
|
1535
|
-
if (this.isRunningSetter_)
|
|
1671
|
+
if (this.isRunningSetter_) {
|
|
1672
|
+
die(33, this.name_);
|
|
1673
|
+
}
|
|
1674
|
+
|
|
1536
1675
|
this.isRunningSetter_ = true;
|
|
1537
1676
|
|
|
1538
1677
|
try {
|
|
@@ -1540,7 +1679,9 @@ var ComputedValue = /*#__PURE__*/function (_Symbol$toPrimitive2) {
|
|
|
1540
1679
|
} finally {
|
|
1541
1680
|
this.isRunningSetter_ = false;
|
|
1542
1681
|
}
|
|
1543
|
-
} else
|
|
1682
|
+
} else {
|
|
1683
|
+
die(34, this.name_);
|
|
1684
|
+
}
|
|
1544
1685
|
};
|
|
1545
1686
|
|
|
1546
1687
|
_proto.trackAndCompute = function trackAndCompute() {
|
|
@@ -1769,7 +1910,9 @@ function checkIfStateModificationsAreAllowed(atom) {
|
|
|
1769
1910
|
|
|
1770
1911
|
var hasObservers = atom.observers_.size > 0; // Should not be possible to change observed state outside strict mode, except during initialization, see #563
|
|
1771
1912
|
|
|
1772
|
-
if (!globalState.allowStateChanges && (hasObservers || globalState.enforceActions === "always"))
|
|
1913
|
+
if (!globalState.allowStateChanges && (hasObservers || globalState.enforceActions === "always")) {
|
|
1914
|
+
console.warn("[MobX] " + (globalState.enforceActions ? "Since strict-mode is enabled, changing (observed) observable values without using an action is not allowed. Tried to modify: " : "Side effects like changing state are not allowed at this point. Are you trying to modify state from, for example, a computed value or the render function of a React component? You can wrap side effects in 'runInAction' (or decorate functions with 'action') if needed. Tried to modify: ") + atom.name_);
|
|
1915
|
+
}
|
|
1773
1916
|
}
|
|
1774
1917
|
function checkIfStateReadsAreAllowed(observable) {
|
|
1775
1918
|
if ( !globalState.allowStateReads && globalState.observableRequiresReaction) {
|
|
@@ -1814,9 +1957,12 @@ function trackDerivedFunction(derivation, f, context) {
|
|
|
1814
1957
|
}
|
|
1815
1958
|
|
|
1816
1959
|
function warnAboutDerivationWithoutDependencies(derivation) {
|
|
1817
|
-
if (derivation.observing_.length !== 0) return;
|
|
1818
1960
|
|
|
1819
|
-
if (
|
|
1961
|
+
if (derivation.observing_.length !== 0) {
|
|
1962
|
+
return;
|
|
1963
|
+
}
|
|
1964
|
+
|
|
1965
|
+
if (typeof derivation.requiresObservable_ === "boolean" ? derivation.requiresObservable_ : globalState.reactionRequiresObservable) {
|
|
1820
1966
|
console.warn("[mobx] Derivation '" + derivation.name_ + "' is created/updated without reading any observable value.");
|
|
1821
1967
|
}
|
|
1822
1968
|
}
|
|
@@ -1843,7 +1989,11 @@ function bindDependencies(derivation) {
|
|
|
1843
1989
|
|
|
1844
1990
|
if (dep.diffValue_ === 0) {
|
|
1845
1991
|
dep.diffValue_ = 1;
|
|
1846
|
-
|
|
1992
|
+
|
|
1993
|
+
if (i0 !== i) {
|
|
1994
|
+
observing[i0] = dep;
|
|
1995
|
+
}
|
|
1996
|
+
|
|
1847
1997
|
i0++;
|
|
1848
1998
|
} // Upcast is 'safe' here, because if dep is IObservable, `dependenciesState` will be undefined,
|
|
1849
1999
|
// not hitting the condition
|
|
@@ -1935,7 +2085,10 @@ function allowStateReadsEnd(prev) {
|
|
|
1935
2085
|
*/
|
|
1936
2086
|
|
|
1937
2087
|
function changeDependenciesStateTo0(derivation) {
|
|
1938
|
-
if (derivation.dependenciesState_ === IDerivationState_.UP_TO_DATE_)
|
|
2088
|
+
if (derivation.dependenciesState_ === IDerivationState_.UP_TO_DATE_) {
|
|
2089
|
+
return;
|
|
2090
|
+
}
|
|
2091
|
+
|
|
1939
2092
|
derivation.dependenciesState_ = IDerivationState_.UP_TO_DATE_;
|
|
1940
2093
|
var obs = derivation.observing_;
|
|
1941
2094
|
var i = obs.length;
|
|
@@ -1979,8 +2132,14 @@ var canMergeGlobalState = true;
|
|
|
1979
2132
|
var isolateCalled = false;
|
|
1980
2133
|
var globalState = /*#__PURE__*/function () {
|
|
1981
2134
|
var global = /*#__PURE__*/getGlobal();
|
|
1982
|
-
|
|
1983
|
-
if (global.
|
|
2135
|
+
|
|
2136
|
+
if (global.__mobxInstanceCount > 0 && !global.__mobxGlobals) {
|
|
2137
|
+
canMergeGlobalState = false;
|
|
2138
|
+
}
|
|
2139
|
+
|
|
2140
|
+
if (global.__mobxGlobals && global.__mobxGlobals.version !== new MobXGlobals().version) {
|
|
2141
|
+
canMergeGlobalState = false;
|
|
2142
|
+
}
|
|
1984
2143
|
|
|
1985
2144
|
if (!canMergeGlobalState) {
|
|
1986
2145
|
// Because this is a IIFE we need to let isolateCalled a chance to change
|
|
@@ -1993,7 +2152,11 @@ var globalState = /*#__PURE__*/function () {
|
|
|
1993
2152
|
return new MobXGlobals();
|
|
1994
2153
|
} else if (global.__mobxGlobals) {
|
|
1995
2154
|
global.__mobxInstanceCount += 1;
|
|
1996
|
-
|
|
2155
|
+
|
|
2156
|
+
if (!global.__mobxGlobals.UNCHANGED) {
|
|
2157
|
+
global.__mobxGlobals.UNCHANGED = {};
|
|
2158
|
+
} // make merge backward compatible
|
|
2159
|
+
|
|
1997
2160
|
|
|
1998
2161
|
return global.__mobxGlobals;
|
|
1999
2162
|
} else {
|
|
@@ -2002,12 +2165,19 @@ var globalState = /*#__PURE__*/function () {
|
|
|
2002
2165
|
}
|
|
2003
2166
|
}();
|
|
2004
2167
|
function isolateGlobalState() {
|
|
2005
|
-
if (globalState.pendingReactions.length || globalState.inBatch || globalState.isRunningReactions)
|
|
2168
|
+
if (globalState.pendingReactions.length || globalState.inBatch || globalState.isRunningReactions) {
|
|
2169
|
+
die(36);
|
|
2170
|
+
}
|
|
2171
|
+
|
|
2006
2172
|
isolateCalled = true;
|
|
2007
2173
|
|
|
2008
2174
|
if (canMergeGlobalState) {
|
|
2009
2175
|
var global = getGlobal();
|
|
2010
|
-
|
|
2176
|
+
|
|
2177
|
+
if (--global.__mobxInstanceCount === 0) {
|
|
2178
|
+
global.__mobxGlobals = undefined;
|
|
2179
|
+
}
|
|
2180
|
+
|
|
2011
2181
|
globalState = new MobXGlobals();
|
|
2012
2182
|
}
|
|
2013
2183
|
}
|
|
@@ -2023,7 +2193,9 @@ function resetGlobalState() {
|
|
|
2023
2193
|
var defaultGlobals = new MobXGlobals();
|
|
2024
2194
|
|
|
2025
2195
|
for (var key in defaultGlobals) {
|
|
2026
|
-
if (persistentKeys.indexOf(key) === -1)
|
|
2196
|
+
if (persistentKeys.indexOf(key) === -1) {
|
|
2197
|
+
globalState[key] = defaultGlobals[key];
|
|
2198
|
+
}
|
|
2027
2199
|
}
|
|
2028
2200
|
|
|
2029
2201
|
globalState.allowStateChanges = !globalState.enforceActions;
|
|
@@ -2057,8 +2229,12 @@ function addObserver(observable, node) {
|
|
|
2057
2229
|
// invariant(observable._observers.indexOf(node) === -1, "INTERNAL ERROR add already added node");
|
|
2058
2230
|
// invariantObservers(observable);
|
|
2059
2231
|
observable.observers_.add(node);
|
|
2060
|
-
|
|
2232
|
+
|
|
2233
|
+
if (observable.lowestObserverState_ > node.dependenciesState_) {
|
|
2234
|
+
observable.lowestObserverState_ = node.dependenciesState_;
|
|
2235
|
+
} // invariantObservers(observable);
|
|
2061
2236
|
// invariant(observable._observers.indexOf(node) !== -1, "INTERNAL ERROR didn't add node");
|
|
2237
|
+
|
|
2062
2238
|
}
|
|
2063
2239
|
function removeObserver(observable, node) {
|
|
2064
2240
|
// invariant(globalState.inBatch > 0, "INTERNAL ERROR, remove should be called only inside batch");
|
|
@@ -2169,7 +2345,10 @@ function reportObserved(observable) {
|
|
|
2169
2345
|
|
|
2170
2346
|
function propagateChanged(observable) {
|
|
2171
2347
|
// invariantLOS(observable, "changed start");
|
|
2172
|
-
if (observable.lowestObserverState_ === IDerivationState_.STALE_)
|
|
2348
|
+
if (observable.lowestObserverState_ === IDerivationState_.STALE_) {
|
|
2349
|
+
return;
|
|
2350
|
+
}
|
|
2351
|
+
|
|
2173
2352
|
observable.lowestObserverState_ = IDerivationState_.STALE_; // Ideally we use for..of here, but the downcompiled version is really slow...
|
|
2174
2353
|
|
|
2175
2354
|
observable.observers_.forEach(function (d) {
|
|
@@ -2187,7 +2366,10 @@ function propagateChanged(observable) {
|
|
|
2187
2366
|
|
|
2188
2367
|
function propagateChangeConfirmed(observable) {
|
|
2189
2368
|
// invariantLOS(observable, "confirmed start");
|
|
2190
|
-
if (observable.lowestObserverState_ === IDerivationState_.STALE_)
|
|
2369
|
+
if (observable.lowestObserverState_ === IDerivationState_.STALE_) {
|
|
2370
|
+
return;
|
|
2371
|
+
}
|
|
2372
|
+
|
|
2191
2373
|
observable.lowestObserverState_ = IDerivationState_.STALE_;
|
|
2192
2374
|
observable.observers_.forEach(function (d) {
|
|
2193
2375
|
if (d.dependenciesState_ === IDerivationState_.POSSIBLY_STALE_) {
|
|
@@ -2205,7 +2387,10 @@ function propagateChangeConfirmed(observable) {
|
|
|
2205
2387
|
|
|
2206
2388
|
function propagateMaybeChanged(observable) {
|
|
2207
2389
|
// invariantLOS(observable, "maybe start");
|
|
2208
|
-
if (observable.lowestObserverState_ !== IDerivationState_.UP_TO_DATE_)
|
|
2390
|
+
if (observable.lowestObserverState_ !== IDerivationState_.UP_TO_DATE_) {
|
|
2391
|
+
return;
|
|
2392
|
+
}
|
|
2393
|
+
|
|
2209
2394
|
observable.lowestObserverState_ = IDerivationState_.POSSIBLY_STALE_;
|
|
2210
2395
|
observable.observers_.forEach(function (d) {
|
|
2211
2396
|
if (d.dependenciesState_ === IDerivationState_.UP_TO_DATE_) {
|
|
@@ -2233,9 +2418,12 @@ function printDepTree(tree, lines, depth) {
|
|
|
2233
2418
|
}
|
|
2234
2419
|
|
|
2235
2420
|
lines.push("" + "\t".repeat(depth - 1) + tree.name);
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2421
|
+
|
|
2422
|
+
if (tree.dependencies) {
|
|
2423
|
+
tree.dependencies.forEach(function (child) {
|
|
2424
|
+
return printDepTree(child, lines, depth + 1);
|
|
2425
|
+
});
|
|
2426
|
+
}
|
|
2239
2427
|
}
|
|
2240
2428
|
|
|
2241
2429
|
var Reaction = /*#__PURE__*/function () {
|
|
@@ -2245,10 +2433,6 @@ var Reaction = /*#__PURE__*/function () {
|
|
|
2245
2433
|
name_ = "Reaction@" + getNextId() ;
|
|
2246
2434
|
}
|
|
2247
2435
|
|
|
2248
|
-
if (requiresObservable_ === void 0) {
|
|
2249
|
-
requiresObservable_ = false;
|
|
2250
|
-
}
|
|
2251
|
-
|
|
2252
2436
|
this.name_ = void 0;
|
|
2253
2437
|
this.onInvalidate_ = void 0;
|
|
2254
2438
|
this.errorHandler_ = void 0;
|
|
@@ -2353,7 +2537,9 @@ var Reaction = /*#__PURE__*/function () {
|
|
|
2353
2537
|
clearObserving(this);
|
|
2354
2538
|
}
|
|
2355
2539
|
|
|
2356
|
-
if (isCaughtException(result))
|
|
2540
|
+
if (isCaughtException(result)) {
|
|
2541
|
+
this.reportExceptionInDerivation_(result.cause);
|
|
2542
|
+
}
|
|
2357
2543
|
|
|
2358
2544
|
if ( notify) {
|
|
2359
2545
|
spyReportEnd({
|
|
@@ -2372,13 +2558,18 @@ var Reaction = /*#__PURE__*/function () {
|
|
|
2372
2558
|
return;
|
|
2373
2559
|
}
|
|
2374
2560
|
|
|
2375
|
-
if (globalState.disableErrorBoundaries)
|
|
2561
|
+
if (globalState.disableErrorBoundaries) {
|
|
2562
|
+
throw error;
|
|
2563
|
+
}
|
|
2564
|
+
|
|
2376
2565
|
var message = "[mobx] Encountered an uncaught exception that was thrown by a reaction or observer component, in: '" + this + "'" ;
|
|
2377
2566
|
|
|
2378
2567
|
if (!globalState.suppressReactionErrors) {
|
|
2379
2568
|
console.error(message, error);
|
|
2380
2569
|
/** If debugging brought you here, please, read the above message :-). Tnx! */
|
|
2381
|
-
} else
|
|
2570
|
+
} else {
|
|
2571
|
+
console.warn("[mobx] (error in reaction '" + this.name_ + "' suppressed, fix error of causing action below)");
|
|
2572
|
+
} // prettier-ignore
|
|
2382
2573
|
|
|
2383
2574
|
|
|
2384
2575
|
if ( isSpyEnabled()) {
|
|
@@ -2432,7 +2623,10 @@ function onReactionError(handler) {
|
|
|
2432
2623
|
globalState.globalReactionErrorHandlers.push(handler);
|
|
2433
2624
|
return function () {
|
|
2434
2625
|
var idx = globalState.globalReactionErrorHandlers.indexOf(handler);
|
|
2435
|
-
|
|
2626
|
+
|
|
2627
|
+
if (idx >= 0) {
|
|
2628
|
+
globalState.globalReactionErrorHandlers.splice(idx, 1);
|
|
2629
|
+
}
|
|
2436
2630
|
};
|
|
2437
2631
|
}
|
|
2438
2632
|
/**
|
|
@@ -2449,7 +2643,10 @@ var reactionScheduler = function reactionScheduler(f) {
|
|
|
2449
2643
|
|
|
2450
2644
|
function runReactions() {
|
|
2451
2645
|
// Trampolining, if runReactions are already running, new reactions will be picked up
|
|
2452
|
-
if (globalState.inBatch > 0 || globalState.isRunningReactions)
|
|
2646
|
+
if (globalState.inBatch > 0 || globalState.isRunningReactions) {
|
|
2647
|
+
return;
|
|
2648
|
+
}
|
|
2649
|
+
|
|
2453
2650
|
reactionScheduler(runReactionsHelper);
|
|
2454
2651
|
}
|
|
2455
2652
|
|
|
@@ -2492,7 +2689,11 @@ function isSpyEnabled() {
|
|
|
2492
2689
|
}
|
|
2493
2690
|
function spyReport(event) {
|
|
2494
2691
|
|
|
2495
|
-
|
|
2692
|
+
|
|
2693
|
+
if (!globalState.spyListeners.length) {
|
|
2694
|
+
return;
|
|
2695
|
+
}
|
|
2696
|
+
|
|
2496
2697
|
var listeners = globalState.spyListeners;
|
|
2497
2698
|
|
|
2498
2699
|
for (var i = 0, l = listeners.length; i < l; i++) {
|
|
@@ -2512,10 +2713,15 @@ var END_EVENT = {
|
|
|
2512
2713
|
spyReportEnd: true
|
|
2513
2714
|
};
|
|
2514
2715
|
function spyReportEnd(change) {
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2716
|
+
|
|
2717
|
+
if (change) {
|
|
2718
|
+
spyReport(_extends({}, change, {
|
|
2719
|
+
type: "report-end",
|
|
2720
|
+
spyReportEnd: true
|
|
2721
|
+
}));
|
|
2722
|
+
} else {
|
|
2723
|
+
spyReport(END_EVENT);
|
|
2724
|
+
}
|
|
2519
2725
|
}
|
|
2520
2726
|
function spy(listener) {
|
|
2521
2727
|
{
|
|
@@ -2548,9 +2754,15 @@ var autoActionBoundAnnotation = /*#__PURE__*/createActionAnnotation(AUTOACTION_B
|
|
|
2548
2754
|
function createActionFactory(autoAction) {
|
|
2549
2755
|
var res = function action(arg1, arg2) {
|
|
2550
2756
|
// action(fn() {})
|
|
2551
|
-
if (isFunction(arg1))
|
|
2757
|
+
if (isFunction(arg1)) {
|
|
2758
|
+
return createAction(arg1.name || DEFAULT_ACTION_NAME, arg1, autoAction);
|
|
2759
|
+
} // action("name", fn() {})
|
|
2760
|
+
|
|
2761
|
+
|
|
2762
|
+
if (isFunction(arg2)) {
|
|
2763
|
+
return createAction(arg1, arg2, autoAction);
|
|
2764
|
+
} // @action
|
|
2552
2765
|
|
|
2553
|
-
if (isFunction(arg2)) return createAction(arg1, arg2, autoAction); // @action
|
|
2554
2766
|
|
|
2555
2767
|
if (isStringish(arg2)) {
|
|
2556
2768
|
return storeAnnotation(arg1, arg2, autoAction ? autoActionAnnotation : actionAnnotation);
|
|
@@ -2564,7 +2776,9 @@ function createActionFactory(autoAction) {
|
|
|
2564
2776
|
}));
|
|
2565
2777
|
}
|
|
2566
2778
|
|
|
2567
|
-
|
|
2779
|
+
{
|
|
2780
|
+
die("Invalid arguments for `action`");
|
|
2781
|
+
}
|
|
2568
2782
|
};
|
|
2569
2783
|
|
|
2570
2784
|
return res;
|
|
@@ -2598,8 +2812,13 @@ function autorun(view, opts) {
|
|
|
2598
2812
|
}
|
|
2599
2813
|
|
|
2600
2814
|
{
|
|
2601
|
-
if (!isFunction(view))
|
|
2602
|
-
|
|
2815
|
+
if (!isFunction(view)) {
|
|
2816
|
+
die("Autorun expects a function as first argument");
|
|
2817
|
+
}
|
|
2818
|
+
|
|
2819
|
+
if (isAction(view)) {
|
|
2820
|
+
die("Autorun does not accept actions since actions are untrackable");
|
|
2821
|
+
}
|
|
2603
2822
|
}
|
|
2604
2823
|
|
|
2605
2824
|
var name = (_opts$name = (_opts = opts) == null ? void 0 : _opts.name) != null ? _opts$name : view.name || "Autorun@" + getNextId() ;
|
|
@@ -2620,7 +2839,10 @@ function autorun(view, opts) {
|
|
|
2620
2839
|
isScheduled = true;
|
|
2621
2840
|
scheduler(function () {
|
|
2622
2841
|
isScheduled = false;
|
|
2623
|
-
|
|
2842
|
+
|
|
2843
|
+
if (!reaction.isDisposed_) {
|
|
2844
|
+
reaction.track(reactionRunner);
|
|
2845
|
+
}
|
|
2624
2846
|
});
|
|
2625
2847
|
}
|
|
2626
2848
|
}, opts.onError, opts.requiresObservable);
|
|
@@ -2652,8 +2874,13 @@ function reaction(expression, effect, opts) {
|
|
|
2652
2874
|
}
|
|
2653
2875
|
|
|
2654
2876
|
{
|
|
2655
|
-
if (!isFunction(expression) || !isFunction(effect))
|
|
2656
|
-
|
|
2877
|
+
if (!isFunction(expression) || !isFunction(effect)) {
|
|
2878
|
+
die("First and second argument to reaction should be functions");
|
|
2879
|
+
}
|
|
2880
|
+
|
|
2881
|
+
if (!isPlainObject(opts)) {
|
|
2882
|
+
die("Third argument of reactions should be an object");
|
|
2883
|
+
}
|
|
2657
2884
|
}
|
|
2658
2885
|
|
|
2659
2886
|
var name = (_opts$name2 = opts.name) != null ? _opts$name2 : "Reaction@" + getNextId() ;
|
|
@@ -2676,7 +2903,11 @@ function reaction(expression, effect, opts) {
|
|
|
2676
2903
|
|
|
2677
2904
|
function reactionRunner() {
|
|
2678
2905
|
isScheduled = false;
|
|
2679
|
-
|
|
2906
|
+
|
|
2907
|
+
if (r.isDisposed_) {
|
|
2908
|
+
return;
|
|
2909
|
+
}
|
|
2910
|
+
|
|
2680
2911
|
var changed = false;
|
|
2681
2912
|
r.track(function () {
|
|
2682
2913
|
var nextValue = allowStateChanges(false, function () {
|
|
@@ -2686,7 +2917,13 @@ function reaction(expression, effect, opts) {
|
|
|
2686
2917
|
oldValue = value;
|
|
2687
2918
|
value = nextValue;
|
|
2688
2919
|
});
|
|
2689
|
-
|
|
2920
|
+
|
|
2921
|
+
if (firstTime && opts.fireImmediately) {
|
|
2922
|
+
effectAction(value, oldValue, r);
|
|
2923
|
+
} else if (!firstTime && changed) {
|
|
2924
|
+
effectAction(value, oldValue, r);
|
|
2925
|
+
}
|
|
2926
|
+
|
|
2690
2927
|
firstTime = false;
|
|
2691
2928
|
}
|
|
2692
2929
|
|
|
@@ -2753,7 +2990,9 @@ function configure(options) {
|
|
|
2753
2990
|
globalState.useProxies = useProxies === ALWAYS ? true : useProxies === NEVER ? false : typeof Proxy !== "undefined";
|
|
2754
2991
|
}
|
|
2755
2992
|
|
|
2756
|
-
if (useProxies === "ifavailable")
|
|
2993
|
+
if (useProxies === "ifavailable") {
|
|
2994
|
+
globalState.verifyProxies = true;
|
|
2995
|
+
}
|
|
2757
2996
|
|
|
2758
2997
|
if (enforceActions !== undefined) {
|
|
2759
2998
|
var ea = enforceActions === ALWAYS ? ALWAYS : enforceActions === OBSERVED;
|
|
@@ -2761,7 +3000,9 @@ function configure(options) {
|
|
|
2761
3000
|
globalState.allowStateChanges = ea === true || ea === ALWAYS ? false : true;
|
|
2762
3001
|
}
|
|
2763
3002
|
["computedRequiresReaction", "reactionRequiresObservable", "observableRequiresReaction", "disableErrorBoundaries", "safeDescriptors"].forEach(function (key) {
|
|
2764
|
-
if (key in options)
|
|
3003
|
+
if (key in options) {
|
|
3004
|
+
globalState[key] = !!options[key];
|
|
3005
|
+
}
|
|
2765
3006
|
});
|
|
2766
3007
|
globalState.allowStateReads = !globalState.observableRequiresReaction;
|
|
2767
3008
|
|
|
@@ -2776,11 +3017,25 @@ function configure(options) {
|
|
|
2776
3017
|
|
|
2777
3018
|
function extendObservable(target, properties, annotations, options) {
|
|
2778
3019
|
{
|
|
2779
|
-
if (arguments.length > 4)
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
if (
|
|
3020
|
+
if (arguments.length > 4) {
|
|
3021
|
+
die("'extendObservable' expected 2-4 arguments");
|
|
3022
|
+
}
|
|
3023
|
+
|
|
3024
|
+
if (typeof target !== "object") {
|
|
3025
|
+
die("'extendObservable' expects an object as first argument");
|
|
3026
|
+
}
|
|
3027
|
+
|
|
3028
|
+
if (isObservableMap(target)) {
|
|
3029
|
+
die("'extendObservable' should not be used on maps, use map.merge instead");
|
|
3030
|
+
}
|
|
3031
|
+
|
|
3032
|
+
if (!isPlainObject(properties)) {
|
|
3033
|
+
die("'extendObservable' only accepts plain objects as second argument");
|
|
3034
|
+
}
|
|
3035
|
+
|
|
3036
|
+
if (isObservable(properties) || isObservable(annotations)) {
|
|
3037
|
+
die("Extending an object with another observable (object) is not supported");
|
|
3038
|
+
}
|
|
2784
3039
|
} // Pull descriptors first, so we don't have to deal with props added by administration ($mobx)
|
|
2785
3040
|
|
|
2786
3041
|
|
|
@@ -2808,7 +3063,11 @@ function nodeToDependencyTree(node) {
|
|
|
2808
3063
|
var result = {
|
|
2809
3064
|
name: node.name_
|
|
2810
3065
|
};
|
|
2811
|
-
|
|
3066
|
+
|
|
3067
|
+
if (node.observing_ && node.observing_.length > 0) {
|
|
3068
|
+
result.dependencies = unique(node.observing_).map(nodeToDependencyTree);
|
|
3069
|
+
}
|
|
3070
|
+
|
|
2812
3071
|
return result;
|
|
2813
3072
|
}
|
|
2814
3073
|
|
|
@@ -2820,7 +3079,11 @@ function nodeToObserverTree(node) {
|
|
|
2820
3079
|
var result = {
|
|
2821
3080
|
name: node.name_
|
|
2822
3081
|
};
|
|
2823
|
-
|
|
3082
|
+
|
|
3083
|
+
if (hasObservers(node)) {
|
|
3084
|
+
result.observers = Array.from(getObservers(node)).map(nodeToObserverTree);
|
|
3085
|
+
}
|
|
3086
|
+
|
|
2824
3087
|
return result;
|
|
2825
3088
|
}
|
|
2826
3089
|
|
|
@@ -2847,7 +3110,10 @@ var flow = /*#__PURE__*/Object.assign(function flow(arg1, arg2) {
|
|
|
2847
3110
|
} // flow(fn)
|
|
2848
3111
|
|
|
2849
3112
|
|
|
2850
|
-
if ( arguments.length !== 1)
|
|
3113
|
+
if ( arguments.length !== 1) {
|
|
3114
|
+
die("Flow expects single argument with generator function");
|
|
3115
|
+
}
|
|
3116
|
+
|
|
2851
3117
|
var generator = arg1;
|
|
2852
3118
|
var name = generator.name || "<unnamed flow>"; // Implementation based on https://github.com/tj/co/blob/master/index.js
|
|
2853
3119
|
|
|
@@ -2895,7 +3161,10 @@ var flow = /*#__PURE__*/Object.assign(function flow(arg1, arg2) {
|
|
|
2895
3161
|
return;
|
|
2896
3162
|
}
|
|
2897
3163
|
|
|
2898
|
-
if (ret.done)
|
|
3164
|
+
if (ret.done) {
|
|
3165
|
+
return resolve(ret.value);
|
|
3166
|
+
}
|
|
3167
|
+
|
|
2899
3168
|
pendingPromise = Promise.resolve(ret.value);
|
|
2900
3169
|
return pendingPromise.then(onFulfilled, onRejected);
|
|
2901
3170
|
}
|
|
@@ -2904,7 +3173,10 @@ var flow = /*#__PURE__*/Object.assign(function flow(arg1, arg2) {
|
|
|
2904
3173
|
});
|
|
2905
3174
|
promise.cancel = action(name + " - runid: " + runId + " - cancel", function () {
|
|
2906
3175
|
try {
|
|
2907
|
-
if (pendingPromise)
|
|
3176
|
+
if (pendingPromise) {
|
|
3177
|
+
cancelPromise(pendingPromise);
|
|
3178
|
+
} // Finally block can return (or yield) stuff..
|
|
3179
|
+
|
|
2908
3180
|
|
|
2909
3181
|
var _res = gen["return"](undefined); // eat anything that promise would do, it's cancelled!
|
|
2910
3182
|
|
|
@@ -2928,7 +3200,9 @@ var flow = /*#__PURE__*/Object.assign(function flow(arg1, arg2) {
|
|
|
2928
3200
|
flow.bound = /*#__PURE__*/createDecoratorAnnotation(flowBoundAnnotation);
|
|
2929
3201
|
|
|
2930
3202
|
function cancelPromise(promise) {
|
|
2931
|
-
if (isFunction(promise.cancel))
|
|
3203
|
+
if (isFunction(promise.cancel)) {
|
|
3204
|
+
promise.cancel();
|
|
3205
|
+
}
|
|
2932
3206
|
}
|
|
2933
3207
|
|
|
2934
3208
|
function flowResult(result) {
|
|
@@ -2944,13 +3218,19 @@ function interceptReads(thing, propOrHandler, handler) {
|
|
|
2944
3218
|
if (isObservableMap(thing) || isObservableArray(thing) || isObservableValue(thing)) {
|
|
2945
3219
|
target = getAdministration(thing);
|
|
2946
3220
|
} else if (isObservableObject(thing)) {
|
|
2947
|
-
if ( !isStringish(propOrHandler))
|
|
3221
|
+
if ( !isStringish(propOrHandler)) {
|
|
3222
|
+
return die("InterceptReads can only be used with a specific property, not with an object in general");
|
|
3223
|
+
}
|
|
3224
|
+
|
|
2948
3225
|
target = getAdministration(thing, propOrHandler);
|
|
2949
3226
|
} else {
|
|
2950
3227
|
return die("Expected observable map, object or array as first array");
|
|
2951
3228
|
}
|
|
2952
3229
|
|
|
2953
|
-
if ( target.dehancer !== undefined)
|
|
3230
|
+
if ( target.dehancer !== undefined) {
|
|
3231
|
+
return die("An intercept reader was already established");
|
|
3232
|
+
}
|
|
3233
|
+
|
|
2954
3234
|
target.dehancer = typeof propOrHandler === "function" ? propOrHandler : handler;
|
|
2955
3235
|
return function () {
|
|
2956
3236
|
target.dehancer = undefined;
|
|
@@ -2958,7 +3238,11 @@ function interceptReads(thing, propOrHandler, handler) {
|
|
|
2958
3238
|
}
|
|
2959
3239
|
|
|
2960
3240
|
function intercept(thing, propOrHandler, handler) {
|
|
2961
|
-
if (isFunction(handler))
|
|
3241
|
+
if (isFunction(handler)) {
|
|
3242
|
+
return interceptProperty(thing, propOrHandler, handler);
|
|
3243
|
+
} else {
|
|
3244
|
+
return interceptInterceptable(thing, propOrHandler);
|
|
3245
|
+
}
|
|
2962
3246
|
}
|
|
2963
3247
|
|
|
2964
3248
|
function interceptInterceptable(thing, handler) {
|
|
@@ -2974,25 +3258,41 @@ function _isComputed(value, property) {
|
|
|
2974
3258
|
return isComputedValue(value);
|
|
2975
3259
|
}
|
|
2976
3260
|
|
|
2977
|
-
if (isObservableObject(value) === false)
|
|
2978
|
-
|
|
3261
|
+
if (isObservableObject(value) === false) {
|
|
3262
|
+
return false;
|
|
3263
|
+
}
|
|
3264
|
+
|
|
3265
|
+
if (!value[$mobx].values_.has(property)) {
|
|
3266
|
+
return false;
|
|
3267
|
+
}
|
|
3268
|
+
|
|
2979
3269
|
var atom = getAtom(value, property);
|
|
2980
3270
|
return isComputedValue(atom);
|
|
2981
3271
|
}
|
|
2982
3272
|
function isComputed(value) {
|
|
2983
|
-
if ( arguments.length > 1)
|
|
3273
|
+
if ( arguments.length > 1) {
|
|
3274
|
+
return die("isComputed expects only 1 argument. Use isComputedProp to inspect the observability of a property");
|
|
3275
|
+
}
|
|
3276
|
+
|
|
2984
3277
|
return _isComputed(value);
|
|
2985
3278
|
}
|
|
2986
3279
|
function isComputedProp(value, propName) {
|
|
2987
|
-
if ( !isStringish(propName))
|
|
3280
|
+
if ( !isStringish(propName)) {
|
|
3281
|
+
return die("isComputed expected a property name as second argument");
|
|
3282
|
+
}
|
|
3283
|
+
|
|
2988
3284
|
return _isComputed(value, propName);
|
|
2989
3285
|
}
|
|
2990
3286
|
|
|
2991
3287
|
function _isObservable(value, property) {
|
|
2992
|
-
if (!value)
|
|
3288
|
+
if (!value) {
|
|
3289
|
+
return false;
|
|
3290
|
+
}
|
|
2993
3291
|
|
|
2994
3292
|
if (property !== undefined) {
|
|
2995
|
-
if ( (isObservableMap(value) || isObservableArray(value)))
|
|
3293
|
+
if ( (isObservableMap(value) || isObservableArray(value))) {
|
|
3294
|
+
return die("isObservable(object, propertyName) is not supported for arrays and maps. Use map.has or array.length instead.");
|
|
3295
|
+
}
|
|
2996
3296
|
|
|
2997
3297
|
if (isObservableObject(value)) {
|
|
2998
3298
|
return value[$mobx].values_.has(property);
|
|
@@ -3006,11 +3306,17 @@ function _isObservable(value, property) {
|
|
|
3006
3306
|
}
|
|
3007
3307
|
|
|
3008
3308
|
function isObservable(value) {
|
|
3009
|
-
if ( arguments.length !== 1)
|
|
3309
|
+
if ( arguments.length !== 1) {
|
|
3310
|
+
die("isObservable expects only 1 argument. Use isObservableProp to inspect the observability of a property");
|
|
3311
|
+
}
|
|
3312
|
+
|
|
3010
3313
|
return _isObservable(value);
|
|
3011
3314
|
}
|
|
3012
3315
|
function isObservableProp(value, propName) {
|
|
3013
|
-
if ( !isStringish(propName))
|
|
3316
|
+
if ( !isStringish(propName)) {
|
|
3317
|
+
return die("expected a property name as second argument");
|
|
3318
|
+
}
|
|
3319
|
+
|
|
3014
3320
|
return _isObservable(value, propName);
|
|
3015
3321
|
}
|
|
3016
3322
|
|
|
@@ -3102,13 +3408,25 @@ function set(obj, key, value) {
|
|
|
3102
3408
|
} else if (isObservableSet(obj)) {
|
|
3103
3409
|
obj.add(key);
|
|
3104
3410
|
} else if (isObservableArray(obj)) {
|
|
3105
|
-
if (typeof key !== "number")
|
|
3106
|
-
|
|
3411
|
+
if (typeof key !== "number") {
|
|
3412
|
+
key = parseInt(key, 10);
|
|
3413
|
+
}
|
|
3414
|
+
|
|
3415
|
+
if (key < 0) {
|
|
3416
|
+
die("Invalid index: '" + key + "'");
|
|
3417
|
+
}
|
|
3418
|
+
|
|
3107
3419
|
startBatch();
|
|
3108
|
-
|
|
3420
|
+
|
|
3421
|
+
if (key >= obj.length) {
|
|
3422
|
+
obj.length = key + 1;
|
|
3423
|
+
}
|
|
3424
|
+
|
|
3109
3425
|
obj[key] = value;
|
|
3110
3426
|
endBatch();
|
|
3111
|
-
} else
|
|
3427
|
+
} else {
|
|
3428
|
+
die(8);
|
|
3429
|
+
}
|
|
3112
3430
|
}
|
|
3113
3431
|
function remove(obj, key) {
|
|
3114
3432
|
if (isObservableObject(obj)) {
|
|
@@ -3118,7 +3436,10 @@ function remove(obj, key) {
|
|
|
3118
3436
|
} else if (isObservableSet(obj)) {
|
|
3119
3437
|
obj["delete"](key);
|
|
3120
3438
|
} else if (isObservableArray(obj)) {
|
|
3121
|
-
if (typeof key !== "number")
|
|
3439
|
+
if (typeof key !== "number") {
|
|
3440
|
+
key = parseInt(key, 10);
|
|
3441
|
+
}
|
|
3442
|
+
|
|
3122
3443
|
obj.splice(key, 1);
|
|
3123
3444
|
} else {
|
|
3124
3445
|
die(9);
|
|
@@ -3138,7 +3459,9 @@ function has(obj, key) {
|
|
|
3138
3459
|
die(10);
|
|
3139
3460
|
}
|
|
3140
3461
|
function get(obj, key) {
|
|
3141
|
-
if (!has(obj, key))
|
|
3462
|
+
if (!has(obj, key)) {
|
|
3463
|
+
return undefined;
|
|
3464
|
+
}
|
|
3142
3465
|
|
|
3143
3466
|
if (isObservableObject(obj)) {
|
|
3144
3467
|
return obj[$mobx].get_(key);
|
|
@@ -3166,7 +3489,11 @@ function apiOwnKeys(obj) {
|
|
|
3166
3489
|
}
|
|
3167
3490
|
|
|
3168
3491
|
function observe(thing, propOrCb, cbOrFire, fireImmediately) {
|
|
3169
|
-
if (isFunction(cbOrFire))
|
|
3492
|
+
if (isFunction(cbOrFire)) {
|
|
3493
|
+
return observeObservableProperty(thing, propOrCb, cbOrFire, fireImmediately);
|
|
3494
|
+
} else {
|
|
3495
|
+
return observeObservable(thing, propOrCb, cbOrFire);
|
|
3496
|
+
}
|
|
3170
3497
|
}
|
|
3171
3498
|
|
|
3172
3499
|
function observeObservable(thing, listener, fireImmediately) {
|
|
@@ -3183,8 +3510,13 @@ function cache(map, key, value) {
|
|
|
3183
3510
|
}
|
|
3184
3511
|
|
|
3185
3512
|
function toJSHelper(source, __alreadySeen) {
|
|
3186
|
-
if (source == null || typeof source !== "object" || source instanceof Date || !isObservable(source))
|
|
3187
|
-
|
|
3513
|
+
if (source == null || typeof source !== "object" || source instanceof Date || !isObservable(source)) {
|
|
3514
|
+
return source;
|
|
3515
|
+
}
|
|
3516
|
+
|
|
3517
|
+
if (isObservableValue(source) || isComputedValue(source)) {
|
|
3518
|
+
return toJSHelper(source.get(), __alreadySeen);
|
|
3519
|
+
}
|
|
3188
3520
|
|
|
3189
3521
|
if (__alreadySeen.has(source)) {
|
|
3190
3522
|
return __alreadySeen.get(source);
|
|
@@ -3235,18 +3567,25 @@ function toJSHelper(source, __alreadySeen) {
|
|
|
3235
3567
|
|
|
3236
3568
|
|
|
3237
3569
|
function toJS(source, options) {
|
|
3238
|
-
if ( options)
|
|
3570
|
+
if ( options) {
|
|
3571
|
+
die("toJS no longer supports options");
|
|
3572
|
+
}
|
|
3573
|
+
|
|
3239
3574
|
return toJSHelper(source, new Map());
|
|
3240
3575
|
}
|
|
3241
3576
|
|
|
3242
3577
|
function trace() {
|
|
3578
|
+
|
|
3243
3579
|
var enterBreakPoint = false;
|
|
3244
3580
|
|
|
3245
3581
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
3246
3582
|
args[_key] = arguments[_key];
|
|
3247
3583
|
}
|
|
3248
3584
|
|
|
3249
|
-
if (typeof args[args.length - 1] === "boolean")
|
|
3585
|
+
if (typeof args[args.length - 1] === "boolean") {
|
|
3586
|
+
enterBreakPoint = args.pop();
|
|
3587
|
+
}
|
|
3588
|
+
|
|
3250
3589
|
var derivation = getAtomFromArgs(args);
|
|
3251
3590
|
|
|
3252
3591
|
if (!derivation) {
|
|
@@ -3296,7 +3635,10 @@ function transaction(action, thisArg) {
|
|
|
3296
3635
|
}
|
|
3297
3636
|
|
|
3298
3637
|
function when(predicate, arg1, arg2) {
|
|
3299
|
-
if (arguments.length === 1 || arg1 && typeof arg1 === "object")
|
|
3638
|
+
if (arguments.length === 1 || arg1 && typeof arg1 === "object") {
|
|
3639
|
+
return whenPromise(predicate, arg1);
|
|
3640
|
+
}
|
|
3641
|
+
|
|
3300
3642
|
return _when(predicate, arg1, arg2 || {});
|
|
3301
3643
|
}
|
|
3302
3644
|
|
|
@@ -3308,7 +3650,12 @@ function _when(predicate, effect, opts) {
|
|
|
3308
3650
|
timeoutHandle = setTimeout(function () {
|
|
3309
3651
|
if (!disposer[$mobx].isDisposed_) {
|
|
3310
3652
|
disposer();
|
|
3311
|
-
|
|
3653
|
+
|
|
3654
|
+
if (opts.onError) {
|
|
3655
|
+
opts.onError(error);
|
|
3656
|
+
} else {
|
|
3657
|
+
throw error;
|
|
3658
|
+
}
|
|
3312
3659
|
}
|
|
3313
3660
|
}, opts.timeout);
|
|
3314
3661
|
}
|
|
@@ -3322,7 +3669,11 @@ function _when(predicate, effect, opts) {
|
|
|
3322
3669
|
|
|
3323
3670
|
if (cond) {
|
|
3324
3671
|
r.dispose();
|
|
3325
|
-
|
|
3672
|
+
|
|
3673
|
+
if (timeoutHandle) {
|
|
3674
|
+
clearTimeout(timeoutHandle);
|
|
3675
|
+
}
|
|
3676
|
+
|
|
3326
3677
|
effectAction();
|
|
3327
3678
|
}
|
|
3328
3679
|
}, opts);
|
|
@@ -3330,7 +3681,10 @@ function _when(predicate, effect, opts) {
|
|
|
3330
3681
|
}
|
|
3331
3682
|
|
|
3332
3683
|
function whenPromise(predicate, opts) {
|
|
3333
|
-
if ( opts && opts.onError)
|
|
3684
|
+
if ( opts && opts.onError) {
|
|
3685
|
+
return die("the options 'onError' and 'promise' cannot be combined");
|
|
3686
|
+
}
|
|
3687
|
+
|
|
3334
3688
|
var cancel;
|
|
3335
3689
|
var res = new Promise(function (resolve, reject) {
|
|
3336
3690
|
var disposer = _when(predicate, resolve, _extends({}, opts, {
|
|
@@ -3354,7 +3708,10 @@ function getAdm(target) {
|
|
|
3354
3708
|
|
|
3355
3709
|
var objectProxyTraps = {
|
|
3356
3710
|
has: function has(target, name) {
|
|
3357
|
-
if ( globalState.trackingDerivation)
|
|
3711
|
+
if ( globalState.trackingDerivation) {
|
|
3712
|
+
warnAboutProxyRequirement("detect new properties using the 'in' operator. Use 'has' from 'mobx' instead.");
|
|
3713
|
+
}
|
|
3714
|
+
|
|
3358
3715
|
return getAdm(target).has_(name);
|
|
3359
3716
|
},
|
|
3360
3717
|
get: function get(target, name) {
|
|
@@ -3363,7 +3720,9 @@ var objectProxyTraps = {
|
|
|
3363
3720
|
set: function set(target, name, value) {
|
|
3364
3721
|
var _getAdm$set_;
|
|
3365
3722
|
|
|
3366
|
-
if (!isStringish(name))
|
|
3723
|
+
if (!isStringish(name)) {
|
|
3724
|
+
return false;
|
|
3725
|
+
}
|
|
3367
3726
|
|
|
3368
3727
|
if ( !getAdm(target).values_.has(name)) {
|
|
3369
3728
|
warnAboutProxyRequirement("add a new observable property through direct assignment. Use 'set' from 'mobx' instead.");
|
|
@@ -3379,7 +3738,10 @@ var objectProxyTraps = {
|
|
|
3379
3738
|
warnAboutProxyRequirement("delete properties from an observable object. Use 'remove' from 'mobx' instead.");
|
|
3380
3739
|
}
|
|
3381
3740
|
|
|
3382
|
-
if (!isStringish(name))
|
|
3741
|
+
if (!isStringish(name)) {
|
|
3742
|
+
return false;
|
|
3743
|
+
} // null (intercepted) -> true (success)
|
|
3744
|
+
|
|
3383
3745
|
|
|
3384
3746
|
return (_getAdm$delete_ = getAdm(target).delete_(name, true)) != null ? _getAdm$delete_ : true;
|
|
3385
3747
|
},
|
|
@@ -3394,7 +3756,10 @@ var objectProxyTraps = {
|
|
|
3394
3756
|
return (_getAdm$definePropert = getAdm(target).defineProperty_(name, descriptor)) != null ? _getAdm$definePropert : true;
|
|
3395
3757
|
},
|
|
3396
3758
|
ownKeys: function ownKeys(target) {
|
|
3397
|
-
if ( globalState.trackingDerivation)
|
|
3759
|
+
if ( globalState.trackingDerivation) {
|
|
3760
|
+
warnAboutProxyRequirement("iterate keys to detect added / removed properties. Use 'keys' from 'mobx' instead.");
|
|
3761
|
+
}
|
|
3762
|
+
|
|
3398
3763
|
return getAdm(target).ownKeys_();
|
|
3399
3764
|
},
|
|
3400
3765
|
preventExtensions: function preventExtensions(target) {
|
|
@@ -3417,7 +3782,10 @@ function registerInterceptor(interceptable, handler) {
|
|
|
3417
3782
|
interceptors.push(handler);
|
|
3418
3783
|
return once(function () {
|
|
3419
3784
|
var idx = interceptors.indexOf(handler);
|
|
3420
|
-
|
|
3785
|
+
|
|
3786
|
+
if (idx !== -1) {
|
|
3787
|
+
interceptors.splice(idx, 1);
|
|
3788
|
+
}
|
|
3421
3789
|
});
|
|
3422
3790
|
}
|
|
3423
3791
|
function interceptChange(interceptable, change) {
|
|
@@ -3429,8 +3797,14 @@ function interceptChange(interceptable, change) {
|
|
|
3429
3797
|
|
|
3430
3798
|
for (var i = 0, l = interceptors.length; i < l; i++) {
|
|
3431
3799
|
change = interceptors[i](change);
|
|
3432
|
-
|
|
3433
|
-
if (!change)
|
|
3800
|
+
|
|
3801
|
+
if (change && !change.type) {
|
|
3802
|
+
die(14);
|
|
3803
|
+
}
|
|
3804
|
+
|
|
3805
|
+
if (!change) {
|
|
3806
|
+
break;
|
|
3807
|
+
}
|
|
3434
3808
|
}
|
|
3435
3809
|
|
|
3436
3810
|
return change;
|
|
@@ -3447,13 +3821,20 @@ function registerListener(listenable, handler) {
|
|
|
3447
3821
|
listeners.push(handler);
|
|
3448
3822
|
return once(function () {
|
|
3449
3823
|
var idx = listeners.indexOf(handler);
|
|
3450
|
-
|
|
3824
|
+
|
|
3825
|
+
if (idx !== -1) {
|
|
3826
|
+
listeners.splice(idx, 1);
|
|
3827
|
+
}
|
|
3451
3828
|
});
|
|
3452
3829
|
}
|
|
3453
3830
|
function notifyListeners(listenable, change) {
|
|
3454
3831
|
var prevU = untrackedStart();
|
|
3455
3832
|
var listeners = listenable.changeListeners_;
|
|
3456
|
-
|
|
3833
|
+
|
|
3834
|
+
if (!listeners) {
|
|
3835
|
+
return;
|
|
3836
|
+
}
|
|
3837
|
+
|
|
3457
3838
|
listeners = listeners.slice();
|
|
3458
3839
|
|
|
3459
3840
|
for (var i = 0, l = listeners.length; i < l; i++) {
|
|
@@ -3490,8 +3871,13 @@ function makeObservable(target, annotations, options) {
|
|
|
3490
3871
|
var keysSymbol = /*#__PURE__*/Symbol("mobx-keys");
|
|
3491
3872
|
function makeAutoObservable(target, overrides, options) {
|
|
3492
3873
|
{
|
|
3493
|
-
if (!isPlainObject(target) && !isPlainObject(Object.getPrototypeOf(target)))
|
|
3494
|
-
|
|
3874
|
+
if (!isPlainObject(target) && !isPlainObject(Object.getPrototypeOf(target))) {
|
|
3875
|
+
die("'makeAutoObservable' can only be used for classes that don't have a superclass");
|
|
3876
|
+
}
|
|
3877
|
+
|
|
3878
|
+
if (isObservableObject(target)) {
|
|
3879
|
+
die("makeAutoObservable can only be used on objects not already made observable");
|
|
3880
|
+
}
|
|
3495
3881
|
} // Optimization: avoid visiting protos
|
|
3496
3882
|
// Assumes that annotation.make_/.extend_ works the same for plain objects
|
|
3497
3883
|
|
|
@@ -3532,8 +3918,14 @@ var MAX_SPLICE_SIZE = 10000; // See e.g. https://github.com/mobxjs/mobx/issues/8
|
|
|
3532
3918
|
var arrayTraps = {
|
|
3533
3919
|
get: function get(target, name) {
|
|
3534
3920
|
var adm = target[$mobx];
|
|
3535
|
-
|
|
3536
|
-
if (name ===
|
|
3921
|
+
|
|
3922
|
+
if (name === $mobx) {
|
|
3923
|
+
return adm;
|
|
3924
|
+
}
|
|
3925
|
+
|
|
3926
|
+
if (name === "length") {
|
|
3927
|
+
return adm.getArrayLength_();
|
|
3928
|
+
}
|
|
3537
3929
|
|
|
3538
3930
|
if (typeof name === "string" && !isNaN(name)) {
|
|
3539
3931
|
return adm.get_(parseInt(name));
|
|
@@ -3594,12 +3986,18 @@ var ObservableArrayAdministration = /*#__PURE__*/function () {
|
|
|
3594
3986
|
var _proto = ObservableArrayAdministration.prototype;
|
|
3595
3987
|
|
|
3596
3988
|
_proto.dehanceValue_ = function dehanceValue_(value) {
|
|
3597
|
-
if (this.dehancer !== undefined)
|
|
3989
|
+
if (this.dehancer !== undefined) {
|
|
3990
|
+
return this.dehancer(value);
|
|
3991
|
+
}
|
|
3992
|
+
|
|
3598
3993
|
return value;
|
|
3599
3994
|
};
|
|
3600
3995
|
|
|
3601
3996
|
_proto.dehanceValues_ = function dehanceValues_(values) {
|
|
3602
|
-
if (this.dehancer !== undefined && values.length > 0)
|
|
3997
|
+
if (this.dehancer !== undefined && values.length > 0) {
|
|
3998
|
+
return values.map(this.dehancer);
|
|
3999
|
+
}
|
|
4000
|
+
|
|
3603
4001
|
return values;
|
|
3604
4002
|
};
|
|
3605
4003
|
|
|
@@ -3635,9 +4033,15 @@ var ObservableArrayAdministration = /*#__PURE__*/function () {
|
|
|
3635
4033
|
};
|
|
3636
4034
|
|
|
3637
4035
|
_proto.setArrayLength_ = function setArrayLength_(newLength) {
|
|
3638
|
-
if (typeof newLength !== "number" || isNaN(newLength) || newLength < 0)
|
|
4036
|
+
if (typeof newLength !== "number" || isNaN(newLength) || newLength < 0) {
|
|
4037
|
+
die("Out of range: " + newLength);
|
|
4038
|
+
}
|
|
4039
|
+
|
|
3639
4040
|
var currentLength = this.values_.length;
|
|
3640
|
-
|
|
4041
|
+
|
|
4042
|
+
if (newLength === currentLength) {
|
|
4043
|
+
return;
|
|
4044
|
+
} else if (newLength > currentLength) {
|
|
3641
4045
|
var newItems = new Array(newLength - currentLength);
|
|
3642
4046
|
|
|
3643
4047
|
for (var i = 0; i < newLength - currentLength; i++) {
|
|
@@ -3646,13 +4050,21 @@ var ObservableArrayAdministration = /*#__PURE__*/function () {
|
|
|
3646
4050
|
|
|
3647
4051
|
|
|
3648
4052
|
this.spliceWithArray_(currentLength, 0, newItems);
|
|
3649
|
-
} else
|
|
4053
|
+
} else {
|
|
4054
|
+
this.spliceWithArray_(newLength, currentLength - newLength);
|
|
4055
|
+
}
|
|
3650
4056
|
};
|
|
3651
4057
|
|
|
3652
4058
|
_proto.updateArrayLength_ = function updateArrayLength_(oldLength, delta) {
|
|
3653
|
-
if (oldLength !== this.lastKnownLength_)
|
|
4059
|
+
if (oldLength !== this.lastKnownLength_) {
|
|
4060
|
+
die(16);
|
|
4061
|
+
}
|
|
4062
|
+
|
|
3654
4063
|
this.lastKnownLength_ += delta;
|
|
3655
|
-
|
|
4064
|
+
|
|
4065
|
+
if (this.legacyMode_ && delta > 0) {
|
|
4066
|
+
reserveArrayBuffer(oldLength + delta + 1);
|
|
4067
|
+
}
|
|
3656
4068
|
};
|
|
3657
4069
|
|
|
3658
4070
|
_proto.spliceWithArray_ = function spliceWithArray_(index, deleteCount, newItems) {
|
|
@@ -3660,9 +4072,26 @@ var ObservableArrayAdministration = /*#__PURE__*/function () {
|
|
|
3660
4072
|
|
|
3661
4073
|
checkIfStateModificationsAreAllowed(this.atom_);
|
|
3662
4074
|
var length = this.values_.length;
|
|
3663
|
-
|
|
3664
|
-
if (
|
|
3665
|
-
|
|
4075
|
+
|
|
4076
|
+
if (index === undefined) {
|
|
4077
|
+
index = 0;
|
|
4078
|
+
} else if (index > length) {
|
|
4079
|
+
index = length;
|
|
4080
|
+
} else if (index < 0) {
|
|
4081
|
+
index = Math.max(0, length + index);
|
|
4082
|
+
}
|
|
4083
|
+
|
|
4084
|
+
if (arguments.length === 1) {
|
|
4085
|
+
deleteCount = length - index;
|
|
4086
|
+
} else if (deleteCount === undefined || deleteCount === null) {
|
|
4087
|
+
deleteCount = 0;
|
|
4088
|
+
} else {
|
|
4089
|
+
deleteCount = Math.max(0, Math.min(deleteCount, length - index));
|
|
4090
|
+
}
|
|
4091
|
+
|
|
4092
|
+
if (newItems === undefined) {
|
|
4093
|
+
newItems = EMPTY_ARRAY;
|
|
4094
|
+
}
|
|
3666
4095
|
|
|
3667
4096
|
if (hasInterceptors(this)) {
|
|
3668
4097
|
var change = interceptChange(this, {
|
|
@@ -3672,7 +4101,11 @@ var ObservableArrayAdministration = /*#__PURE__*/function () {
|
|
|
3672
4101
|
removedCount: deleteCount,
|
|
3673
4102
|
added: newItems
|
|
3674
4103
|
});
|
|
3675
|
-
|
|
4104
|
+
|
|
4105
|
+
if (!change) {
|
|
4106
|
+
return EMPTY_ARRAY;
|
|
4107
|
+
}
|
|
4108
|
+
|
|
3676
4109
|
deleteCount = change.removedCount;
|
|
3677
4110
|
newItems = change.added;
|
|
3678
4111
|
}
|
|
@@ -3687,7 +4120,11 @@ var ObservableArrayAdministration = /*#__PURE__*/function () {
|
|
|
3687
4120
|
}
|
|
3688
4121
|
|
|
3689
4122
|
var res = this.spliceItemsIntoValues_(index, deleteCount, newItems);
|
|
3690
|
-
|
|
4123
|
+
|
|
4124
|
+
if (deleteCount !== 0 || newItems.length !== 0) {
|
|
4125
|
+
this.notifyArraySplice_(index, newItems, res);
|
|
4126
|
+
}
|
|
4127
|
+
|
|
3691
4128
|
return this.dehanceValues_(res);
|
|
3692
4129
|
};
|
|
3693
4130
|
|
|
@@ -3730,10 +4167,19 @@ var ObservableArrayAdministration = /*#__PURE__*/function () {
|
|
|
3730
4167
|
} : 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
|
|
3731
4168
|
// cause any runtime overhead in development mode without NODE_ENV set, unless spying is enabled
|
|
3732
4169
|
|
|
3733
|
-
if ( notifySpy)
|
|
4170
|
+
if ( notifySpy) {
|
|
4171
|
+
spyReportStart(change);
|
|
4172
|
+
}
|
|
4173
|
+
|
|
3734
4174
|
this.atom_.reportChanged();
|
|
3735
|
-
|
|
3736
|
-
if (
|
|
4175
|
+
|
|
4176
|
+
if (notify) {
|
|
4177
|
+
notifyListeners(this, change);
|
|
4178
|
+
}
|
|
4179
|
+
|
|
4180
|
+
if ( notifySpy) {
|
|
4181
|
+
spyReportEnd();
|
|
4182
|
+
}
|
|
3737
4183
|
};
|
|
3738
4184
|
|
|
3739
4185
|
_proto.notifyArraySplice_ = function notifyArraySplice_(index, added, removed) {
|
|
@@ -3750,11 +4196,20 @@ var ObservableArrayAdministration = /*#__PURE__*/function () {
|
|
|
3750
4196
|
removedCount: removed.length,
|
|
3751
4197
|
addedCount: added.length
|
|
3752
4198
|
} : null;
|
|
3753
|
-
|
|
4199
|
+
|
|
4200
|
+
if ( notifySpy) {
|
|
4201
|
+
spyReportStart(change);
|
|
4202
|
+
}
|
|
4203
|
+
|
|
3754
4204
|
this.atom_.reportChanged(); // conform: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/observe
|
|
3755
4205
|
|
|
3756
|
-
if (notify)
|
|
3757
|
-
|
|
4206
|
+
if (notify) {
|
|
4207
|
+
notifyListeners(this, change);
|
|
4208
|
+
}
|
|
4209
|
+
|
|
4210
|
+
if ( notifySpy) {
|
|
4211
|
+
spyReportEnd();
|
|
4212
|
+
}
|
|
3758
4213
|
};
|
|
3759
4214
|
|
|
3760
4215
|
_proto.get_ = function get_(index) {
|
|
@@ -3781,7 +4236,11 @@ var ObservableArrayAdministration = /*#__PURE__*/function () {
|
|
|
3781
4236
|
index: index,
|
|
3782
4237
|
newValue: newValue
|
|
3783
4238
|
});
|
|
3784
|
-
|
|
4239
|
+
|
|
4240
|
+
if (!change) {
|
|
4241
|
+
return;
|
|
4242
|
+
}
|
|
4243
|
+
|
|
3785
4244
|
newValue = change.newValue;
|
|
3786
4245
|
}
|
|
3787
4246
|
|
|
@@ -4065,7 +4524,10 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4065
4524
|
_proto.has = function has(key) {
|
|
4066
4525
|
var _this2 = this;
|
|
4067
4526
|
|
|
4068
|
-
if (!globalState.trackingDerivation)
|
|
4527
|
+
if (!globalState.trackingDerivation) {
|
|
4528
|
+
return this.has_(key);
|
|
4529
|
+
}
|
|
4530
|
+
|
|
4069
4531
|
var entry = this.hasMap_.get(key);
|
|
4070
4532
|
|
|
4071
4533
|
if (!entry) {
|
|
@@ -4089,7 +4551,11 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4089
4551
|
newValue: value,
|
|
4090
4552
|
name: key
|
|
4091
4553
|
});
|
|
4092
|
-
|
|
4554
|
+
|
|
4555
|
+
if (!change) {
|
|
4556
|
+
return this;
|
|
4557
|
+
}
|
|
4558
|
+
|
|
4093
4559
|
value = change.newValue;
|
|
4094
4560
|
}
|
|
4095
4561
|
|
|
@@ -4113,7 +4579,10 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4113
4579
|
object: this,
|
|
4114
4580
|
name: key
|
|
4115
4581
|
});
|
|
4116
|
-
|
|
4582
|
+
|
|
4583
|
+
if (!change) {
|
|
4584
|
+
return false;
|
|
4585
|
+
}
|
|
4117
4586
|
}
|
|
4118
4587
|
|
|
4119
4588
|
if (this.has_(key)) {
|
|
@@ -4129,7 +4598,10 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4129
4598
|
name: key
|
|
4130
4599
|
} : null;
|
|
4131
4600
|
|
|
4132
|
-
if ( notifySpy)
|
|
4601
|
+
if ( notifySpy) {
|
|
4602
|
+
spyReportStart(_change);
|
|
4603
|
+
} // TODO fix type
|
|
4604
|
+
|
|
4133
4605
|
|
|
4134
4606
|
transaction(function () {
|
|
4135
4607
|
var _this3$hasMap_$get;
|
|
@@ -4144,8 +4616,15 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4144
4616
|
|
|
4145
4617
|
_this3.data_["delete"](key);
|
|
4146
4618
|
});
|
|
4147
|
-
|
|
4148
|
-
if (
|
|
4619
|
+
|
|
4620
|
+
if (notify) {
|
|
4621
|
+
notifyListeners(this, _change);
|
|
4622
|
+
}
|
|
4623
|
+
|
|
4624
|
+
if ( notifySpy) {
|
|
4625
|
+
spyReportEnd();
|
|
4626
|
+
}
|
|
4627
|
+
|
|
4149
4628
|
return true;
|
|
4150
4629
|
}
|
|
4151
4630
|
|
|
@@ -4168,11 +4647,21 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4168
4647
|
name: key,
|
|
4169
4648
|
newValue: newValue
|
|
4170
4649
|
} : null;
|
|
4171
|
-
|
|
4650
|
+
|
|
4651
|
+
if ( notifySpy) {
|
|
4652
|
+
spyReportStart(change);
|
|
4653
|
+
} // TODO fix type
|
|
4654
|
+
|
|
4172
4655
|
|
|
4173
4656
|
observable.setNewValue_(newValue);
|
|
4174
|
-
|
|
4175
|
-
if (
|
|
4657
|
+
|
|
4658
|
+
if (notify) {
|
|
4659
|
+
notifyListeners(this, change);
|
|
4660
|
+
}
|
|
4661
|
+
|
|
4662
|
+
if ( notifySpy) {
|
|
4663
|
+
spyReportEnd();
|
|
4664
|
+
}
|
|
4176
4665
|
}
|
|
4177
4666
|
};
|
|
4178
4667
|
|
|
@@ -4203,14 +4692,26 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4203
4692
|
name: key,
|
|
4204
4693
|
newValue: newValue
|
|
4205
4694
|
} : null;
|
|
4206
|
-
if ( notifySpy) spyReportStart(change); // TODO fix type
|
|
4207
4695
|
|
|
4208
|
-
if (
|
|
4209
|
-
|
|
4696
|
+
if ( notifySpy) {
|
|
4697
|
+
spyReportStart(change);
|
|
4698
|
+
} // TODO fix type
|
|
4699
|
+
|
|
4700
|
+
|
|
4701
|
+
if (notify) {
|
|
4702
|
+
notifyListeners(this, change);
|
|
4703
|
+
}
|
|
4704
|
+
|
|
4705
|
+
if ( notifySpy) {
|
|
4706
|
+
spyReportEnd();
|
|
4707
|
+
}
|
|
4210
4708
|
};
|
|
4211
4709
|
|
|
4212
4710
|
_proto.get = function get(key) {
|
|
4213
|
-
if (this.has(key))
|
|
4711
|
+
if (this.has(key)) {
|
|
4712
|
+
return this.dehanceValue_(this.data_.get(key).get());
|
|
4713
|
+
}
|
|
4714
|
+
|
|
4214
4715
|
return this.dehanceValue_(undefined);
|
|
4215
4716
|
};
|
|
4216
4717
|
|
|
@@ -4284,18 +4785,27 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4284
4785
|
}
|
|
4285
4786
|
|
|
4286
4787
|
transaction(function () {
|
|
4287
|
-
if (isPlainObject(other))
|
|
4288
|
-
|
|
4289
|
-
|
|
4290
|
-
|
|
4291
|
-
|
|
4292
|
-
|
|
4293
|
-
|
|
4294
|
-
|
|
4788
|
+
if (isPlainObject(other)) {
|
|
4789
|
+
getPlainObjectKeys(other).forEach(function (key) {
|
|
4790
|
+
return _this5.set(key, other[key]);
|
|
4791
|
+
});
|
|
4792
|
+
} else if (Array.isArray(other)) {
|
|
4793
|
+
other.forEach(function (_ref) {
|
|
4794
|
+
var key = _ref[0],
|
|
4795
|
+
value = _ref[1];
|
|
4796
|
+
return _this5.set(key, value);
|
|
4797
|
+
});
|
|
4798
|
+
} else if (isES6Map(other)) {
|
|
4799
|
+
if (other.constructor !== Map) {
|
|
4800
|
+
die(19, other);
|
|
4801
|
+
}
|
|
4802
|
+
|
|
4295
4803
|
other.forEach(function (value, key) {
|
|
4296
4804
|
return _this5.set(key, value);
|
|
4297
4805
|
});
|
|
4298
|
-
} else if (other !== null && other !== undefined)
|
|
4806
|
+
} else if (other !== null && other !== undefined) {
|
|
4807
|
+
die(20, other);
|
|
4808
|
+
}
|
|
4299
4809
|
});
|
|
4300
4810
|
return this;
|
|
4301
4811
|
};
|
|
@@ -4426,7 +4936,10 @@ var ObservableMap = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4426
4936
|
* for callback details
|
|
4427
4937
|
*/
|
|
4428
4938
|
_proto.observe_ = function observe_(listener, fireImmediately) {
|
|
4429
|
-
if ( fireImmediately === true)
|
|
4939
|
+
if ( fireImmediately === true) {
|
|
4940
|
+
die("`observe` doesn't support fireImmediately=true in combination with maps.");
|
|
4941
|
+
}
|
|
4942
|
+
|
|
4430
4943
|
return registerListener(this, listener);
|
|
4431
4944
|
};
|
|
4432
4945
|
|
|
@@ -4551,8 +5064,12 @@ var ObservableSet = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4551
5064
|
object: this,
|
|
4552
5065
|
newValue: value
|
|
4553
5066
|
});
|
|
4554
|
-
|
|
5067
|
+
|
|
5068
|
+
if (!change) {
|
|
5069
|
+
return this;
|
|
5070
|
+
} // ideally, value = change.value would be done here, so that values can be
|
|
4555
5071
|
// changed by interceptor. Same applies for other Set and Map api's.
|
|
5072
|
+
|
|
4556
5073
|
}
|
|
4557
5074
|
|
|
4558
5075
|
if (!this.has(value)) {
|
|
@@ -4572,9 +5089,17 @@ var ObservableSet = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4572
5089
|
newValue: value
|
|
4573
5090
|
} : null;
|
|
4574
5091
|
|
|
4575
|
-
if (notifySpy && "development" !== "production")
|
|
4576
|
-
|
|
4577
|
-
|
|
5092
|
+
if (notifySpy && "development" !== "production") {
|
|
5093
|
+
spyReportStart(_change);
|
|
5094
|
+
}
|
|
5095
|
+
|
|
5096
|
+
if (notify) {
|
|
5097
|
+
notifyListeners(this, _change);
|
|
5098
|
+
}
|
|
5099
|
+
|
|
5100
|
+
if (notifySpy && "development" !== "production") {
|
|
5101
|
+
spyReportEnd();
|
|
5102
|
+
}
|
|
4578
5103
|
}
|
|
4579
5104
|
|
|
4580
5105
|
return this;
|
|
@@ -4589,7 +5114,10 @@ var ObservableSet = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4589
5114
|
object: this,
|
|
4590
5115
|
oldValue: value
|
|
4591
5116
|
});
|
|
4592
|
-
|
|
5117
|
+
|
|
5118
|
+
if (!change) {
|
|
5119
|
+
return false;
|
|
5120
|
+
}
|
|
4593
5121
|
}
|
|
4594
5122
|
|
|
4595
5123
|
if (this.has(value)) {
|
|
@@ -4604,14 +5132,24 @@ var ObservableSet = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4604
5132
|
oldValue: value
|
|
4605
5133
|
} : null;
|
|
4606
5134
|
|
|
4607
|
-
if (notifySpy && "development" !== "production")
|
|
5135
|
+
if (notifySpy && "development" !== "production") {
|
|
5136
|
+
spyReportStart(_change2);
|
|
5137
|
+
}
|
|
5138
|
+
|
|
4608
5139
|
transaction(function () {
|
|
4609
5140
|
_this3.atom_.reportChanged();
|
|
4610
5141
|
|
|
4611
5142
|
_this3.data_["delete"](value);
|
|
4612
5143
|
});
|
|
4613
|
-
|
|
4614
|
-
if (
|
|
5144
|
+
|
|
5145
|
+
if (notify) {
|
|
5146
|
+
notifyListeners(this, _change2);
|
|
5147
|
+
}
|
|
5148
|
+
|
|
5149
|
+
if (notifySpy && "development" !== "production") {
|
|
5150
|
+
spyReportEnd();
|
|
5151
|
+
}
|
|
5152
|
+
|
|
4615
5153
|
return true;
|
|
4616
5154
|
}
|
|
4617
5155
|
|
|
@@ -4691,7 +5229,10 @@ var ObservableSet = /*#__PURE__*/function (_Symbol$iterator2, _Symbol$toStringTa
|
|
|
4691
5229
|
|
|
4692
5230
|
_proto.observe_ = function observe_(listener, fireImmediately) {
|
|
4693
5231
|
// ... 'fireImmediately' could also be true?
|
|
4694
|
-
if ( fireImmediately === true)
|
|
5232
|
+
if ( fireImmediately === true) {
|
|
5233
|
+
die("`observe` doesn't support fireImmediately=true in combination with sets.");
|
|
5234
|
+
}
|
|
5235
|
+
|
|
4695
5236
|
return registerListener(this, listener);
|
|
4696
5237
|
};
|
|
4697
5238
|
|
|
@@ -4793,7 +5334,11 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
4793
5334
|
name: key,
|
|
4794
5335
|
newValue: newValue
|
|
4795
5336
|
});
|
|
4796
|
-
|
|
5337
|
+
|
|
5338
|
+
if (!change) {
|
|
5339
|
+
return null;
|
|
5340
|
+
}
|
|
5341
|
+
|
|
4797
5342
|
newValue = change.newValue;
|
|
4798
5343
|
}
|
|
4799
5344
|
|
|
@@ -4813,10 +5358,18 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
4813
5358
|
newValue: newValue
|
|
4814
5359
|
} : null;
|
|
4815
5360
|
|
|
4816
|
-
if ( notifySpy)
|
|
5361
|
+
if ( notifySpy) {
|
|
5362
|
+
spyReportStart(_change);
|
|
5363
|
+
}
|
|
4817
5364
|
observable.setNewValue_(newValue);
|
|
4818
|
-
|
|
4819
|
-
if (
|
|
5365
|
+
|
|
5366
|
+
if (notify) {
|
|
5367
|
+
notifyListeners(this, _change);
|
|
5368
|
+
}
|
|
5369
|
+
|
|
5370
|
+
if ( notifySpy) {
|
|
5371
|
+
spyReportEnd();
|
|
5372
|
+
}
|
|
4820
5373
|
}
|
|
4821
5374
|
|
|
4822
5375
|
return true;
|
|
@@ -4925,12 +5478,18 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
4925
5478
|
|
|
4926
5479
|
if (descriptor) {
|
|
4927
5480
|
var outcome = annotation.make_(this, key, descriptor, source);
|
|
5481
|
+
|
|
4928
5482
|
if (outcome === 0
|
|
4929
5483
|
/* Cancel */
|
|
4930
|
-
)
|
|
5484
|
+
) {
|
|
5485
|
+
return;
|
|
5486
|
+
}
|
|
5487
|
+
|
|
4931
5488
|
if (outcome === 1
|
|
4932
5489
|
/* Break */
|
|
4933
|
-
)
|
|
5490
|
+
) {
|
|
5491
|
+
break;
|
|
5492
|
+
}
|
|
4934
5493
|
}
|
|
4935
5494
|
|
|
4936
5495
|
source = Object.getPrototypeOf(source);
|
|
@@ -5000,7 +5559,11 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
5000
5559
|
type: ADD,
|
|
5001
5560
|
newValue: descriptor.value
|
|
5002
5561
|
});
|
|
5003
|
-
|
|
5562
|
+
|
|
5563
|
+
if (!change) {
|
|
5564
|
+
return null;
|
|
5565
|
+
}
|
|
5566
|
+
|
|
5004
5567
|
var newValue = change.newValue;
|
|
5005
5568
|
|
|
5006
5569
|
if (descriptor.value !== newValue) {
|
|
@@ -5052,7 +5615,11 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
5052
5615
|
type: ADD,
|
|
5053
5616
|
newValue: value
|
|
5054
5617
|
});
|
|
5055
|
-
|
|
5618
|
+
|
|
5619
|
+
if (!change) {
|
|
5620
|
+
return null;
|
|
5621
|
+
}
|
|
5622
|
+
|
|
5056
5623
|
value = change.newValue;
|
|
5057
5624
|
}
|
|
5058
5625
|
|
|
@@ -5107,7 +5674,10 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
5107
5674
|
type: ADD,
|
|
5108
5675
|
newValue: undefined
|
|
5109
5676
|
});
|
|
5110
|
-
|
|
5677
|
+
|
|
5678
|
+
if (!change) {
|
|
5679
|
+
return null;
|
|
5680
|
+
}
|
|
5111
5681
|
}
|
|
5112
5682
|
|
|
5113
5683
|
options.name || (options.name = "development" !== "production" ? this.name_ + "." + key.toString() : "ObservableObject.key");
|
|
@@ -5163,7 +5733,9 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
5163
5733
|
type: REMOVE
|
|
5164
5734
|
}); // Cancelled
|
|
5165
5735
|
|
|
5166
|
-
if (!change)
|
|
5736
|
+
if (!change) {
|
|
5737
|
+
return null;
|
|
5738
|
+
}
|
|
5167
5739
|
} // Delete
|
|
5168
5740
|
|
|
5169
5741
|
|
|
@@ -5224,9 +5796,18 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
5224
5796
|
oldValue: value,
|
|
5225
5797
|
name: key
|
|
5226
5798
|
};
|
|
5227
|
-
|
|
5228
|
-
if (
|
|
5229
|
-
|
|
5799
|
+
|
|
5800
|
+
if ("development" !== "production" && notifySpy) {
|
|
5801
|
+
spyReportStart(_change2);
|
|
5802
|
+
}
|
|
5803
|
+
|
|
5804
|
+
if (notify) {
|
|
5805
|
+
notifyListeners(this, _change2);
|
|
5806
|
+
}
|
|
5807
|
+
|
|
5808
|
+
if ("development" !== "production" && notifySpy) {
|
|
5809
|
+
spyReportEnd();
|
|
5810
|
+
}
|
|
5230
5811
|
}
|
|
5231
5812
|
} finally {
|
|
5232
5813
|
endBatch();
|
|
@@ -5242,7 +5823,10 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
5242
5823
|
;
|
|
5243
5824
|
|
|
5244
5825
|
_proto.observe_ = function observe_(callback, fireImmediately) {
|
|
5245
|
-
if ( fireImmediately === true)
|
|
5826
|
+
if ( fireImmediately === true) {
|
|
5827
|
+
die("`observe` doesn't support the fire immediately property for observable objects.");
|
|
5828
|
+
}
|
|
5829
|
+
|
|
5246
5830
|
return registerListener(this, callback);
|
|
5247
5831
|
};
|
|
5248
5832
|
|
|
@@ -5265,9 +5849,18 @@ var ObservableObjectAdministration = /*#__PURE__*/function () {
|
|
|
5265
5849
|
name: key,
|
|
5266
5850
|
newValue: value
|
|
5267
5851
|
} : null;
|
|
5268
|
-
|
|
5269
|
-
if (
|
|
5270
|
-
|
|
5852
|
+
|
|
5853
|
+
if ( notifySpy) {
|
|
5854
|
+
spyReportStart(change);
|
|
5855
|
+
}
|
|
5856
|
+
|
|
5857
|
+
if (notify) {
|
|
5858
|
+
notifyListeners(this, change);
|
|
5859
|
+
}
|
|
5860
|
+
|
|
5861
|
+
if ( notifySpy) {
|
|
5862
|
+
spyReportEnd();
|
|
5863
|
+
}
|
|
5271
5864
|
}
|
|
5272
5865
|
|
|
5273
5866
|
(_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
|
|
@@ -5308,7 +5901,10 @@ function asObservableObject(target, options) {
|
|
|
5308
5901
|
return target;
|
|
5309
5902
|
}
|
|
5310
5903
|
|
|
5311
|
-
if ( !Object.isExtensible(target))
|
|
5904
|
+
if ( !Object.isExtensible(target)) {
|
|
5905
|
+
die("Cannot make the designated object observable; it is not extensible");
|
|
5906
|
+
}
|
|
5907
|
+
|
|
5312
5908
|
var name = (_options$name = options == null ? void 0 : options.name) != null ? _options$name : (isPlainObject(target) ? "ObservableObject" : target.constructor.name) + "@" + getNextId() ;
|
|
5313
5909
|
var adm = new ObservableObjectAdministration(target, new Map(), String(name), getAnnotationFromOptions(options));
|
|
5314
5910
|
addHiddenProp(target, $mobx, adm);
|
|
@@ -5465,7 +6061,6 @@ var LegacyObservableArray = /*#__PURE__*/function (_StubArray, _Symbol$toStringT
|
|
|
5465
6061
|
var nextIndex = 0;
|
|
5466
6062
|
return makeIterable({
|
|
5467
6063
|
next: function next() {
|
|
5468
|
-
// @ts-ignore
|
|
5469
6064
|
return nextIndex < self.length ? {
|
|
5470
6065
|
value: self[nextIndex++],
|
|
5471
6066
|
done: false
|
|
@@ -5498,7 +6093,10 @@ var LegacyObservableArray = /*#__PURE__*/function (_StubArray, _Symbol$toStringT
|
|
|
5498
6093
|
Object.entries(arrayExtensions).forEach(function (_ref) {
|
|
5499
6094
|
var prop = _ref[0],
|
|
5500
6095
|
fn = _ref[1];
|
|
5501
|
-
|
|
6096
|
+
|
|
6097
|
+
if (prop !== "concat") {
|
|
6098
|
+
addHiddenProp(LegacyObservableArray.prototype, prop, fn);
|
|
6099
|
+
}
|
|
5502
6100
|
});
|
|
5503
6101
|
|
|
5504
6102
|
function createArrayEntryDescriptor(index) {
|
|
@@ -5535,7 +6133,10 @@ function createLegacyArray(initialValues, enhancer, name) {
|
|
|
5535
6133
|
function getAtom(thing, property) {
|
|
5536
6134
|
if (typeof thing === "object" && thing !== null) {
|
|
5537
6135
|
if (isObservableArray(thing)) {
|
|
5538
|
-
if (property !== undefined)
|
|
6136
|
+
if (property !== undefined) {
|
|
6137
|
+
die(23);
|
|
6138
|
+
}
|
|
6139
|
+
|
|
5539
6140
|
return thing[$mobx].atom_;
|
|
5540
6141
|
}
|
|
5541
6142
|
|
|
@@ -5544,18 +6145,31 @@ function getAtom(thing, property) {
|
|
|
5544
6145
|
}
|
|
5545
6146
|
|
|
5546
6147
|
if (isObservableMap(thing)) {
|
|
5547
|
-
if (property === undefined)
|
|
6148
|
+
if (property === undefined) {
|
|
6149
|
+
return thing.keysAtom_;
|
|
6150
|
+
}
|
|
6151
|
+
|
|
5548
6152
|
var observable = thing.data_.get(property) || thing.hasMap_.get(property);
|
|
5549
|
-
|
|
6153
|
+
|
|
6154
|
+
if (!observable) {
|
|
6155
|
+
die(25, property, getDebugName(thing));
|
|
6156
|
+
}
|
|
6157
|
+
|
|
5550
6158
|
return observable;
|
|
5551
6159
|
}
|
|
5552
6160
|
|
|
6161
|
+
|
|
5553
6162
|
if (isObservableObject(thing)) {
|
|
5554
|
-
if (!property)
|
|
6163
|
+
if (!property) {
|
|
6164
|
+
return die(26);
|
|
6165
|
+
}
|
|
5555
6166
|
|
|
5556
6167
|
var _observable = thing[$mobx].values_.get(property);
|
|
5557
6168
|
|
|
5558
|
-
if (!_observable)
|
|
6169
|
+
if (!_observable) {
|
|
6170
|
+
die(27, property, getDebugName(thing));
|
|
6171
|
+
}
|
|
6172
|
+
|
|
5559
6173
|
return _observable;
|
|
5560
6174
|
}
|
|
5561
6175
|
|
|
@@ -5572,11 +6186,26 @@ function getAtom(thing, property) {
|
|
|
5572
6186
|
die(28);
|
|
5573
6187
|
}
|
|
5574
6188
|
function getAdministration(thing, property) {
|
|
5575
|
-
if (!thing)
|
|
5576
|
-
|
|
5577
|
-
|
|
5578
|
-
|
|
5579
|
-
if (
|
|
6189
|
+
if (!thing) {
|
|
6190
|
+
die(29);
|
|
6191
|
+
}
|
|
6192
|
+
|
|
6193
|
+
if (property !== undefined) {
|
|
6194
|
+
return getAdministration(getAtom(thing, property));
|
|
6195
|
+
}
|
|
6196
|
+
|
|
6197
|
+
if (isAtom(thing) || isComputedValue(thing) || isReaction(thing)) {
|
|
6198
|
+
return thing;
|
|
6199
|
+
}
|
|
6200
|
+
|
|
6201
|
+
if (isObservableMap(thing) || isObservableSet(thing)) {
|
|
6202
|
+
return thing;
|
|
6203
|
+
}
|
|
6204
|
+
|
|
6205
|
+
if (thing[$mobx]) {
|
|
6206
|
+
return thing[$mobx];
|
|
6207
|
+
}
|
|
6208
|
+
|
|
5580
6209
|
die(24, thing);
|
|
5581
6210
|
}
|
|
5582
6211
|
function getDebugName(thing, property) {
|
|
@@ -5609,17 +6238,33 @@ function deepEqual(a, b, depth) {
|
|
|
5609
6238
|
function eq(a, b, depth, aStack, bStack) {
|
|
5610
6239
|
// Identical objects are equal. `0 === -0`, but they aren't identical.
|
|
5611
6240
|
// See the [Harmony `egal` proposal](http://wiki.ecmascript.org/doku.php?id=harmony:egal).
|
|
5612
|
-
if (a === b)
|
|
6241
|
+
if (a === b) {
|
|
6242
|
+
return a !== 0 || 1 / a === 1 / b;
|
|
6243
|
+
} // `null` or `undefined` only equal to itself (strict comparison).
|
|
6244
|
+
|
|
6245
|
+
|
|
6246
|
+
if (a == null || b == null) {
|
|
6247
|
+
return false;
|
|
6248
|
+
} // `NaN`s are equivalent, but non-reflexive.
|
|
6249
|
+
|
|
5613
6250
|
|
|
5614
|
-
if (a
|
|
6251
|
+
if (a !== a) {
|
|
6252
|
+
return b !== b;
|
|
6253
|
+
} // Exhaust primitive checks
|
|
5615
6254
|
|
|
5616
|
-
if (a !== a) return b !== b; // Exhaust primitive checks
|
|
5617
6255
|
|
|
5618
6256
|
var type = typeof a;
|
|
5619
|
-
|
|
6257
|
+
|
|
6258
|
+
if (type !== "function" && type !== "object" && typeof b != "object") {
|
|
6259
|
+
return false;
|
|
6260
|
+
} // Compare `[[Class]]` names.
|
|
6261
|
+
|
|
5620
6262
|
|
|
5621
6263
|
var className = toString.call(a);
|
|
5622
|
-
|
|
6264
|
+
|
|
6265
|
+
if (className !== toString.call(b)) {
|
|
6266
|
+
return false;
|
|
6267
|
+
}
|
|
5623
6268
|
|
|
5624
6269
|
switch (className) {
|
|
5625
6270
|
// Strings, numbers, regular expressions, dates, and booleans are compared by value.
|
|
@@ -5633,7 +6278,10 @@ function eq(a, b, depth, aStack, bStack) {
|
|
|
5633
6278
|
case "[object Number]":
|
|
5634
6279
|
// `NaN`s are equivalent, but non-reflexive.
|
|
5635
6280
|
// Object(NaN) is equivalent to NaN.
|
|
5636
|
-
if (+a !== +a)
|
|
6281
|
+
if (+a !== +a) {
|
|
6282
|
+
return +b !== +b;
|
|
6283
|
+
} // An `egal` comparison is performed for other numeric values.
|
|
6284
|
+
|
|
5637
6285
|
|
|
5638
6286
|
return +a === 0 ? 1 / +a === 1 / b : +a === +b;
|
|
5639
6287
|
|
|
@@ -5664,9 +6312,12 @@ function eq(a, b, depth, aStack, bStack) {
|
|
|
5664
6312
|
var areArrays = className === "[object Array]";
|
|
5665
6313
|
|
|
5666
6314
|
if (!areArrays) {
|
|
5667
|
-
if (typeof a != "object" || typeof b != "object")
|
|
6315
|
+
if (typeof a != "object" || typeof b != "object") {
|
|
6316
|
+
return false;
|
|
6317
|
+
} // Objects with different constructors are not equivalent, but `Object`s or `Array`s
|
|
5668
6318
|
// from different frames are.
|
|
5669
6319
|
|
|
6320
|
+
|
|
5670
6321
|
var aCtor = a.constructor,
|
|
5671
6322
|
bCtor = b.constructor;
|
|
5672
6323
|
|
|
@@ -5692,7 +6343,9 @@ function eq(a, b, depth, aStack, bStack) {
|
|
|
5692
6343
|
while (length--) {
|
|
5693
6344
|
// Linear search. Performance is inversely proportional to the number of
|
|
5694
6345
|
// unique nested structures.
|
|
5695
|
-
if (aStack[length] === a)
|
|
6346
|
+
if (aStack[length] === a) {
|
|
6347
|
+
return bStack[length] === b;
|
|
6348
|
+
}
|
|
5696
6349
|
} // Add the first object to the stack of traversed objects.
|
|
5697
6350
|
|
|
5698
6351
|
|
|
@@ -5702,10 +6355,16 @@ function eq(a, b, depth, aStack, bStack) {
|
|
|
5702
6355
|
if (areArrays) {
|
|
5703
6356
|
// Compare array lengths to determine if a deep comparison is necessary.
|
|
5704
6357
|
length = a.length;
|
|
5705
|
-
|
|
6358
|
+
|
|
6359
|
+
if (length !== b.length) {
|
|
6360
|
+
return false;
|
|
6361
|
+
} // Deep compare the contents, ignoring non-numeric properties.
|
|
6362
|
+
|
|
5706
6363
|
|
|
5707
6364
|
while (length--) {
|
|
5708
|
-
if (!eq(a[length], b[length], depth - 1, aStack, bStack))
|
|
6365
|
+
if (!eq(a[length], b[length], depth - 1, aStack, bStack)) {
|
|
6366
|
+
return false;
|
|
6367
|
+
}
|
|
5709
6368
|
}
|
|
5710
6369
|
} else {
|
|
5711
6370
|
// Deep compare objects.
|
|
@@ -5713,12 +6372,17 @@ function eq(a, b, depth, aStack, bStack) {
|
|
|
5713
6372
|
var key;
|
|
5714
6373
|
length = keys.length; // Ensure that both objects contain the same number of properties before comparing deep equality.
|
|
5715
6374
|
|
|
5716
|
-
if (Object.keys(b).length !== length)
|
|
6375
|
+
if (Object.keys(b).length !== length) {
|
|
6376
|
+
return false;
|
|
6377
|
+
}
|
|
5717
6378
|
|
|
5718
6379
|
while (length--) {
|
|
5719
6380
|
// Deep compare each member
|
|
5720
6381
|
key = keys[length];
|
|
5721
|
-
|
|
6382
|
+
|
|
6383
|
+
if (!(hasProp(b, key) && eq(a[key], b[key], depth - 1, aStack, bStack))) {
|
|
6384
|
+
return false;
|
|
6385
|
+
}
|
|
5722
6386
|
}
|
|
5723
6387
|
} // Remove the first object from the stack of traversed objects.
|
|
5724
6388
|
|
|
@@ -5729,9 +6393,18 @@ function eq(a, b, depth, aStack, bStack) {
|
|
|
5729
6393
|
}
|
|
5730
6394
|
|
|
5731
6395
|
function unwrap(a) {
|
|
5732
|
-
if (isObservableArray(a))
|
|
5733
|
-
|
|
5734
|
-
|
|
6396
|
+
if (isObservableArray(a)) {
|
|
6397
|
+
return a.slice();
|
|
6398
|
+
}
|
|
6399
|
+
|
|
6400
|
+
if (isES6Map(a) || isObservableMap(a)) {
|
|
6401
|
+
return Array.from(a.entries());
|
|
6402
|
+
}
|
|
6403
|
+
|
|
6404
|
+
if (isES6Set(a) || isObservableSet(a)) {
|
|
6405
|
+
return Array.from(a.entries());
|
|
6406
|
+
}
|
|
6407
|
+
|
|
5735
6408
|
return a;
|
|
5736
6409
|
}
|
|
5737
6410
|
|