@jbrowse/mobx-state-tree 5.11.1 → 5.11.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/README.md +85 -12
- package/dist/index.d.ts +1 -47
- package/dist/mobx-state-tree.cjs +79 -84
- package/dist/mobx-state-tree.cjs.map +1 -1
- package/dist/mobx-state-tree.mjs +80 -84
- package/dist/mobx-state-tree.mjs.map +1 -1
- package/package.json +6 -1
package/dist/mobx-state-tree.mjs
CHANGED
|
@@ -1116,6 +1116,21 @@ class ScalarNode extends BaseNode {
|
|
|
1116
1116
|
ScalarNode.prototype.die = action(ScalarNode.prototype.die);
|
|
1117
1117
|
|
|
1118
1118
|
let nextNodeId = 1;
|
|
1119
|
+
var ObservableInstanceLifecycle;
|
|
1120
|
+
(function (ObservableInstanceLifecycle) {
|
|
1121
|
+
// the actual observable instance has not been created yet
|
|
1122
|
+
ObservableInstanceLifecycle[ObservableInstanceLifecycle["UNINITIALIZED"] = 0] = "UNINITIALIZED";
|
|
1123
|
+
// the actual observable instance is being created
|
|
1124
|
+
ObservableInstanceLifecycle[ObservableInstanceLifecycle["CREATING"] = 1] = "CREATING";
|
|
1125
|
+
// the actual observable instance has been created
|
|
1126
|
+
ObservableInstanceLifecycle[ObservableInstanceLifecycle["CREATED"] = 2] = "CREATED";
|
|
1127
|
+
})(ObservableInstanceLifecycle || (ObservableInstanceLifecycle = {}));
|
|
1128
|
+
var InternalEvents;
|
|
1129
|
+
(function (InternalEvents) {
|
|
1130
|
+
InternalEvents["Dispose"] = "dispose";
|
|
1131
|
+
InternalEvents["Patch"] = "patch";
|
|
1132
|
+
InternalEvents["Snapshot"] = "snapshot";
|
|
1133
|
+
})(InternalEvents || (InternalEvents = {}));
|
|
1119
1134
|
const snapshotReactionOptions = {
|
|
1120
1135
|
onError(e) {
|
|
1121
1136
|
throw e;
|
|
@@ -1147,7 +1162,7 @@ class ObjectNode extends BaseNode {
|
|
|
1147
1162
|
_autoUnbox = true; // unboxing is disabled when reading child nodes
|
|
1148
1163
|
_isRunningAction = false; // only relevant for root
|
|
1149
1164
|
_hasSnapshotReaction = false;
|
|
1150
|
-
_observableInstanceState =
|
|
1165
|
+
_observableInstanceState = ObservableInstanceLifecycle.UNINITIALIZED;
|
|
1151
1166
|
_childNodes;
|
|
1152
1167
|
_initialSnapshot;
|
|
1153
1168
|
_cachedInitialSnapshot;
|
|
@@ -1192,7 +1207,7 @@ class ObjectNode extends BaseNode {
|
|
|
1192
1207
|
}
|
|
1193
1208
|
createObservableInstanceIfNeeded(fireHooks = true) {
|
|
1194
1209
|
if (this._observableInstanceState ===
|
|
1195
|
-
|
|
1210
|
+
ObservableInstanceLifecycle.UNINITIALIZED) {
|
|
1196
1211
|
this.createObservableInstance(fireHooks);
|
|
1197
1212
|
}
|
|
1198
1213
|
}
|
|
@@ -1203,7 +1218,7 @@ class ObjectNode extends BaseNode {
|
|
|
1203
1218
|
throw fail("assertion failed: the creation of the observable instance must be done on the initializing phase");
|
|
1204
1219
|
}
|
|
1205
1220
|
}
|
|
1206
|
-
this._observableInstanceState =
|
|
1221
|
+
this._observableInstanceState = ObservableInstanceLifecycle.CREATING;
|
|
1207
1222
|
// make sure the parent chain is created as well
|
|
1208
1223
|
// array with parent chain from parent to child
|
|
1209
1224
|
const parentChain = [];
|
|
@@ -1213,7 +1228,7 @@ class ObjectNode extends BaseNode {
|
|
|
1213
1228
|
// this is done to avoid traversing the whole tree to the root when using
|
|
1214
1229
|
// the same reference again
|
|
1215
1230
|
while (parent?._observableInstanceState ===
|
|
1216
|
-
|
|
1231
|
+
ObservableInstanceLifecycle.UNINITIALIZED) {
|
|
1217
1232
|
parentChain.unshift(parent);
|
|
1218
1233
|
parent = parent.parent;
|
|
1219
1234
|
}
|
|
@@ -1238,7 +1253,7 @@ class ObjectNode extends BaseNode {
|
|
|
1238
1253
|
finally {
|
|
1239
1254
|
this._isRunningAction = false;
|
|
1240
1255
|
}
|
|
1241
|
-
this._observableInstanceState =
|
|
1256
|
+
this._observableInstanceState = ObservableInstanceLifecycle.CREATED;
|
|
1242
1257
|
this._snapshotComputed.trackAndCompute();
|
|
1243
1258
|
if (this.isRoot) {
|
|
1244
1259
|
this._addSnapshotReaction();
|
|
@@ -1352,7 +1367,7 @@ class ObjectNode extends BaseNode {
|
|
|
1352
1367
|
if (!this.isAlive) {
|
|
1353
1368
|
return this._snapshotUponDeath;
|
|
1354
1369
|
}
|
|
1355
|
-
return this._observableInstanceState ===
|
|
1370
|
+
return this._observableInstanceState === ObservableInstanceLifecycle.CREATED
|
|
1356
1371
|
? this._getActualSnapshot()
|
|
1357
1372
|
: this._getCachedInitialSnapshot();
|
|
1358
1373
|
}
|
|
@@ -1415,7 +1430,7 @@ class ObjectNode extends BaseNode {
|
|
|
1415
1430
|
this._autoUnbox = false;
|
|
1416
1431
|
try {
|
|
1417
1432
|
return this._observableInstanceState ===
|
|
1418
|
-
|
|
1433
|
+
ObservableInstanceLifecycle.CREATED
|
|
1419
1434
|
? this.type.getChildNode(this, subpath)
|
|
1420
1435
|
: this._childNodes[subpath];
|
|
1421
1436
|
}
|
|
@@ -1428,7 +1443,7 @@ class ObjectNode extends BaseNode {
|
|
|
1428
1443
|
this._autoUnbox = false;
|
|
1429
1444
|
try {
|
|
1430
1445
|
return this._observableInstanceState ===
|
|
1431
|
-
|
|
1446
|
+
ObservableInstanceLifecycle.CREATED
|
|
1432
1447
|
? this.type.getChildren(this)
|
|
1433
1448
|
: convertChildNodesToArray(this._childNodes);
|
|
1434
1449
|
}
|
|
@@ -1514,7 +1529,7 @@ class ObjectNode extends BaseNode {
|
|
|
1514
1529
|
}
|
|
1515
1530
|
aboutToDie() {
|
|
1516
1531
|
if (this._observableInstanceState ===
|
|
1517
|
-
|
|
1532
|
+
ObservableInstanceLifecycle.UNINITIALIZED) {
|
|
1518
1533
|
return;
|
|
1519
1534
|
}
|
|
1520
1535
|
this.getChildren().forEach(node => {
|
|
@@ -1523,8 +1538,8 @@ class ObjectNode extends BaseNode {
|
|
|
1523
1538
|
// beforeDestroy should run before the disposers since else we could end up in a situation where
|
|
1524
1539
|
// a disposer added with addDisposer at this stage (beforeDestroy) is actually never released
|
|
1525
1540
|
this.baseAboutToDie();
|
|
1526
|
-
this._internalEventsEmit(
|
|
1527
|
-
this._internalEventsClear(
|
|
1541
|
+
this._internalEventsEmit(InternalEvents.Dispose);
|
|
1542
|
+
this._internalEventsClear(InternalEvents.Dispose);
|
|
1528
1543
|
}
|
|
1529
1544
|
finalizeDeath() {
|
|
1530
1545
|
// invariant: not called directly but from "die"
|
|
@@ -1540,42 +1555,42 @@ class ObjectNode extends BaseNode {
|
|
|
1540
1555
|
}
|
|
1541
1556
|
onSnapshot(onChange) {
|
|
1542
1557
|
this._addSnapshotReaction();
|
|
1543
|
-
return this._internalEventsRegister(
|
|
1558
|
+
return this._internalEventsRegister(InternalEvents.Snapshot, onChange);
|
|
1544
1559
|
}
|
|
1545
1560
|
emitSnapshot(snapshot) {
|
|
1546
|
-
this._internalEventsEmit(
|
|
1561
|
+
this._internalEventsEmit(InternalEvents.Snapshot, snapshot);
|
|
1547
1562
|
}
|
|
1548
1563
|
onPatch(handler) {
|
|
1549
|
-
return this._internalEventsRegister(
|
|
1564
|
+
return this._internalEventsRegister(InternalEvents.Patch, handler);
|
|
1550
1565
|
}
|
|
1551
1566
|
emitPatch(basePatch, source) {
|
|
1552
|
-
if (this._internalEventsHasSubscribers(
|
|
1567
|
+
if (this._internalEventsHasSubscribers(InternalEvents.Patch)) {
|
|
1553
1568
|
const localizedPatch = {
|
|
1554
1569
|
...basePatch,
|
|
1555
|
-
path: `${source.path.
|
|
1570
|
+
path: `${source.path.slice(this.path.length)}/${basePatch.path}` // calculate the relative path of the patch
|
|
1556
1571
|
};
|
|
1557
1572
|
const [patch, reversePatch] = splitPatch(localizedPatch);
|
|
1558
|
-
this._internalEventsEmit(
|
|
1573
|
+
this._internalEventsEmit(InternalEvents.Patch, patch, reversePatch);
|
|
1559
1574
|
}
|
|
1560
1575
|
if (this.parent) {
|
|
1561
1576
|
this.parent.emitPatch(basePatch, source);
|
|
1562
1577
|
}
|
|
1563
1578
|
}
|
|
1564
1579
|
hasDisposer(disposer) {
|
|
1565
|
-
return this._internalEventsHas(
|
|
1580
|
+
return this._internalEventsHas(InternalEvents.Dispose, disposer);
|
|
1566
1581
|
}
|
|
1567
1582
|
addDisposer(disposer) {
|
|
1568
1583
|
if (!this.hasDisposer(disposer)) {
|
|
1569
|
-
this._internalEventsRegister(
|
|
1584
|
+
this._internalEventsRegister(InternalEvents.Dispose, disposer, true);
|
|
1570
1585
|
return;
|
|
1571
1586
|
}
|
|
1572
1587
|
throw fail("cannot add a disposer when it is already registered for execution");
|
|
1573
1588
|
}
|
|
1574
1589
|
removeDisposer(disposer) {
|
|
1575
|
-
if (!this._internalEventsHas(
|
|
1590
|
+
if (!this._internalEventsHas(InternalEvents.Dispose, disposer)) {
|
|
1576
1591
|
throw fail("cannot remove a disposer which was never registered for execution");
|
|
1577
1592
|
}
|
|
1578
|
-
this._internalEventsUnregister(
|
|
1593
|
+
this._internalEventsUnregister(InternalEvents.Dispose, disposer);
|
|
1579
1594
|
}
|
|
1580
1595
|
removeMiddleware(middleware) {
|
|
1581
1596
|
if (this.middlewares) {
|
|
@@ -2565,22 +2580,47 @@ function isActionContextThisOrChildOf(actionContext, parentOrThis) {
|
|
|
2565
2580
|
}
|
|
2566
2581
|
|
|
2567
2582
|
const MAX_STRINGIFY_DEPTH = 3;
|
|
2583
|
+
const MAX_STRINGIFY_ARRAY_ITEMS = 10;
|
|
2584
|
+
const MAX_STRINGIFY_OBJECT_KEYS = 20;
|
|
2585
|
+
const MAX_STRINGIFY_STRING_LENGTH = 100;
|
|
2586
|
+
// Recursively cap depth, array length, object key count, and string length so a
|
|
2587
|
+
// huge offending snapshot degrades into readable, bounded context instead of a
|
|
2588
|
+
// wall of text that then gets sliced mid-structure. The depth cap also bounds
|
|
2589
|
+
// recursion on circular structures.
|
|
2590
|
+
function truncateForStringify(value, depth) {
|
|
2591
|
+
if (typeof value === "string") {
|
|
2592
|
+
return value.length > MAX_STRINGIFY_STRING_LENGTH
|
|
2593
|
+
? `${value.substring(0, MAX_STRINGIFY_STRING_LENGTH)}… (${value.length - MAX_STRINGIFY_STRING_LENGTH} more characters)`
|
|
2594
|
+
: value;
|
|
2595
|
+
}
|
|
2596
|
+
if (value === null || typeof value !== "object") {
|
|
2597
|
+
return value;
|
|
2598
|
+
}
|
|
2599
|
+
if (depth >= MAX_STRINGIFY_DEPTH) {
|
|
2600
|
+
return Array.isArray(value) ? "[…]" : "{…}";
|
|
2601
|
+
}
|
|
2602
|
+
if (Array.isArray(value)) {
|
|
2603
|
+
const items = value
|
|
2604
|
+
.slice(0, MAX_STRINGIFY_ARRAY_ITEMS)
|
|
2605
|
+
.map(item => truncateForStringify(item, depth + 1));
|
|
2606
|
+
if (value.length > MAX_STRINGIFY_ARRAY_ITEMS) {
|
|
2607
|
+
items.push(`… ${value.length - MAX_STRINGIFY_ARRAY_ITEMS} more items`);
|
|
2608
|
+
}
|
|
2609
|
+
return items;
|
|
2610
|
+
}
|
|
2611
|
+
const keys = Object.keys(value);
|
|
2612
|
+
const result = {};
|
|
2613
|
+
for (const key of keys.slice(0, MAX_STRINGIFY_OBJECT_KEYS)) {
|
|
2614
|
+
result[key] = truncateForStringify(value[key], depth + 1);
|
|
2615
|
+
}
|
|
2616
|
+
if (keys.length > MAX_STRINGIFY_OBJECT_KEYS) {
|
|
2617
|
+
result["…"] = `${keys.length - MAX_STRINGIFY_OBJECT_KEYS} more keys`;
|
|
2618
|
+
}
|
|
2619
|
+
return result;
|
|
2620
|
+
}
|
|
2568
2621
|
function safeStringify(value) {
|
|
2569
2622
|
try {
|
|
2570
|
-
|
|
2571
|
-
return JSON.stringify(value, function (_key, val) {
|
|
2572
|
-
if (val !== null && typeof val === "object") {
|
|
2573
|
-
while (ancestors.length > 0 &&
|
|
2574
|
-
ancestors[ancestors.length - 1] !== this) {
|
|
2575
|
-
ancestors.pop();
|
|
2576
|
-
}
|
|
2577
|
-
if (ancestors.length >= MAX_STRINGIFY_DEPTH) {
|
|
2578
|
-
return Array.isArray(val) ? "[…]" : "{…}";
|
|
2579
|
-
}
|
|
2580
|
-
ancestors.push(val);
|
|
2581
|
-
}
|
|
2582
|
-
return val;
|
|
2583
|
-
});
|
|
2623
|
+
return JSON.stringify(truncateForStringify(value, 0));
|
|
2584
2624
|
}
|
|
2585
2625
|
catch (e) {
|
|
2586
2626
|
// istanbul ignore next
|
|
@@ -3011,31 +3051,6 @@ function convertChildNodesToArray(childNodes) {
|
|
|
3011
3051
|
return result;
|
|
3012
3052
|
}
|
|
3013
3053
|
|
|
3014
|
-
// based on: https://github.com/mobxjs/mobx-utils/blob/master/src/async-action.ts
|
|
3015
|
-
/*
|
|
3016
|
-
All contents of this file are deprecated.
|
|
3017
|
-
|
|
3018
|
-
The term `process` has been replaced with `flow` to avoid conflicts with the
|
|
3019
|
-
global `process` object.
|
|
3020
|
-
|
|
3021
|
-
Refer to `flow.ts` for any further changes to this implementation.
|
|
3022
|
-
*/
|
|
3023
|
-
const DEPRECATION_MESSAGE = "See https://github.com/mobxjs/mobx-state-tree/issues/399 for more information. " +
|
|
3024
|
-
"Note that the middleware event types starting with `process` now start with `flow`.";
|
|
3025
|
-
/**
|
|
3026
|
-
* @hidden
|
|
3027
|
-
*
|
|
3028
|
-
* @deprecated has been renamed to `flow()`.
|
|
3029
|
-
* See https://github.com/mobxjs/mobx-state-tree/issues/399 for more information.
|
|
3030
|
-
* Note that the middleware event types starting with `process` now start with `flow`.
|
|
3031
|
-
*
|
|
3032
|
-
* @returns {Promise}
|
|
3033
|
-
*/
|
|
3034
|
-
function process$1(asyncAction) {
|
|
3035
|
-
deprecated("process", `\`process()\` has been renamed to \`flow()\`. ${DEPRECATION_MESSAGE}`);
|
|
3036
|
-
return flow(asyncAction);
|
|
3037
|
-
}
|
|
3038
|
-
|
|
3039
3054
|
const plainObjectString = Object.toString();
|
|
3040
3055
|
/**
|
|
3041
3056
|
* @internal
|
|
@@ -3326,25 +3341,6 @@ class EventHandlers {
|
|
|
3326
3341
|
}
|
|
3327
3342
|
}
|
|
3328
3343
|
}
|
|
3329
|
-
/**
|
|
3330
|
-
* @internal
|
|
3331
|
-
* @hidden
|
|
3332
|
-
*/
|
|
3333
|
-
const deprecated = function (id, message) {
|
|
3334
|
-
// skip if running production
|
|
3335
|
-
if (!devMode()) {
|
|
3336
|
-
return;
|
|
3337
|
-
}
|
|
3338
|
-
// warn if hasn't been warned before
|
|
3339
|
-
if (deprecated.ids && !deprecated.ids.hasOwnProperty(id)) {
|
|
3340
|
-
warnError(`Deprecation warning: ${message}`);
|
|
3341
|
-
}
|
|
3342
|
-
// mark as warned to avoid duplicate warn message
|
|
3343
|
-
if (deprecated.ids) {
|
|
3344
|
-
deprecated.ids[id] = true;
|
|
3345
|
-
}
|
|
3346
|
-
};
|
|
3347
|
-
deprecated.ids = {};
|
|
3348
3344
|
/**
|
|
3349
3345
|
* @internal
|
|
3350
3346
|
* @hidden
|
|
@@ -4297,9 +4293,9 @@ class ArrayType extends ComplexType {
|
|
|
4297
4293
|
return node.storedValue.slice();
|
|
4298
4294
|
}
|
|
4299
4295
|
getChildNode(node, key) {
|
|
4300
|
-
const
|
|
4301
|
-
if (
|
|
4302
|
-
return
|
|
4296
|
+
const child = node.storedValue[Number(key)];
|
|
4297
|
+
if (child) {
|
|
4298
|
+
return child;
|
|
4303
4299
|
}
|
|
4304
4300
|
throw fail(`Not a child: ${key}`);
|
|
4305
4301
|
}
|
|
@@ -4466,7 +4462,7 @@ function reconcileArrayChildren(parent, childType, oldNodes, newValues, newPaths
|
|
|
4466
4462
|
// both are empty, end
|
|
4467
4463
|
break;
|
|
4468
4464
|
}
|
|
4469
|
-
else if (!hasNewNode) {
|
|
4465
|
+
else if (oldNode && !hasNewNode) {
|
|
4470
4466
|
// new one does not exists
|
|
4471
4467
|
nothingChanged = false;
|
|
4472
4468
|
oldNodes.splice(i, 1);
|
|
@@ -7006,5 +7002,5 @@ const types = {
|
|
|
7006
7002
|
resilient
|
|
7007
7003
|
};
|
|
7008
7004
|
|
|
7009
|
-
export { addDisposer, addMiddleware, applyAction, applyPatch, applySnapshot, cast, castFlowReturn, castToReferenceSnapshot, castToSnapshot, clone, createActionTrackingMiddleware, createActionTrackingMiddleware2, decorate, destroy, detach, escapeJsonPath, flow, getChildType, getEnv, getIdentifier, getLivelinessChecking, getMembers, getNodeId, getParent, getParentOfType, getPath, getPathParts, getPropertyMembers, getRelativePath, getRoot, getRunningActionContext, getSnapshot, getType, getUnionSubtypes, hasParent, hasParentOfType, isActionContextChildOf, isActionContextThisOrChildOf, isAlive, isArrayType, isFrozenType, isIdentifierType, isLateType, isLiteralType, isMapType, isModelType, isOptionalType, isPrimitiveType, isProtected, isReferenceType, isRefinementType, isRoot, isStateTreeNode, isType, isUnionType, isValidReference, joinJsonPath, onAction, onPatch, onSnapshot,
|
|
7005
|
+
export { addDisposer, addMiddleware, applyAction, applyPatch, applySnapshot, cast, castFlowReturn, castToReferenceSnapshot, castToSnapshot, clone, createActionTrackingMiddleware, createActionTrackingMiddleware2, decorate, destroy, detach, escapeJsonPath, flow, getChildType, getEnv, getIdentifier, getLivelinessChecking, getMembers, getNodeId, getParent, getParentOfType, getPath, getPathParts, getPropertyMembers, getRelativePath, getRoot, getRunningActionContext, getSnapshot, getType, getUnionSubtypes, hasParent, hasParentOfType, isActionContextChildOf, isActionContextThisOrChildOf, isAlive, isArrayType, isFrozenType, isIdentifierType, isLateType, isLiteralType, isMapType, isModelType, isOptionalType, isPrimitiveType, isProtected, isReferenceType, isRefinementType, isRoot, isStateTreeNode, isType, isUnionType, isValidReference, joinJsonPath, onAction, onPatch, onSnapshot, protect, recordActions, recordPatches, resolveIdentifier, resolvePath, setDevMode, setLivelinessChecking, setLivelynessChecking, setTypeChecking, splitJsonPath, types as t, toGenerator, toGeneratorFunction, tryReference, tryResolve, typecheck, types, unescapeJsonPath, unprotect, walk };
|
|
7010
7006
|
//# sourceMappingURL=mobx-state-tree.mjs.map
|