@jbrowse/mobx-state-tree 5.6.0 → 5.6.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 +18 -0
- package/dist/core/action.d.ts +1 -1
- package/dist/core/action.js +228 -0
- package/dist/core/action.js.map +1 -1
- package/dist/core/actionContext.js +42 -0
- package/dist/core/actionContext.js.map +1 -1
- package/dist/core/flow.d.ts +1 -1
- package/dist/core/flow.js +180 -0
- package/dist/core/flow.js.map +1 -1
- package/dist/core/json-patch.js +133 -0
- package/dist/core/json-patch.js.map +1 -1
- package/dist/core/mst-operations.js +885 -0
- package/dist/core/mst-operations.js.map +1 -1
- package/dist/core/node/BaseNode.js +152 -0
- package/dist/core/node/BaseNode.js.map +1 -1
- package/dist/core/node/Hook.js +15 -0
- package/dist/core/node/Hook.js.map +1 -1
- package/dist/core/node/create-node.js +41 -0
- package/dist/core/node/create-node.js.map +1 -1
- package/dist/core/node/identifier-cache.js +115 -0
- package/dist/core/node/identifier-cache.js.map +1 -1
- package/dist/core/node/livelinessChecking.js +38 -0
- package/dist/core/node/livelinessChecking.js.map +1 -1
- package/dist/core/node/node-utils.js +165 -0
- package/dist/core/node/node-utils.js.map +1 -1
- package/dist/core/node/object-node.js +545 -0
- package/dist/core/node/object-node.js.map +1 -1
- package/dist/core/node/scalar-node.js +89 -0
- package/dist/core/node/scalar-node.js.map +1 -1
- package/dist/core/process.d.ts +1 -1
- package/dist/core/process.js +39 -0
- package/dist/core/process.js.map +1 -1
- package/dist/core/type/type-checker.js +154 -0
- package/dist/core/type/type-checker.js.map +1 -1
- package/dist/core/type/type.d.ts +1 -1
- package/dist/core/type/type.js +251 -0
- package/dist/core/type/type.js.map +1 -1
- package/dist/index.js +85 -0
- package/dist/index.js.map +1 -1
- package/dist/internal.js +60 -0
- package/dist/internal.js.map +1 -1
- package/dist/middlewares/create-action-tracking-middleware.js +81 -0
- package/dist/middlewares/create-action-tracking-middleware.js.map +1 -1
- package/dist/middlewares/createActionTrackingMiddleware2.js +133 -0
- package/dist/middlewares/createActionTrackingMiddleware2.js.map +1 -1
- package/dist/middlewares/on-action.js +215 -0
- package/dist/middlewares/on-action.js.map +1 -1
- package/dist/mobx-state-tree.js +83 -6867
- package/dist/mobx-state-tree.module.js +83 -6789
- package/dist/types/complex-types/array.d.ts +1 -1
- package/dist/types/complex-types/array.js +352 -0
- package/dist/types/complex-types/array.js.map +1 -1
- package/dist/types/complex-types/map.d.ts +1 -1
- package/dist/types/complex-types/map.js +361 -0
- package/dist/types/complex-types/map.js.map +1 -1
- package/dist/types/complex-types/model.js +477 -0
- package/dist/types/complex-types/model.js.map +1 -1
- package/dist/types/index.js +38 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/primitives.js +182 -0
- package/dist/types/primitives.js.map +1 -1
- package/dist/types/utility-types/custom.js +110 -0
- package/dist/types/utility-types/custom.js.map +1 -1
- package/dist/types/utility-types/enumeration.js +34 -0
- package/dist/types/utility-types/enumeration.js.map +1 -1
- package/dist/types/utility-types/frozen.js +97 -0
- package/dist/types/utility-types/frozen.js.map +1 -1
- package/dist/types/utility-types/identifier.js +129 -0
- package/dist/types/utility-types/identifier.js.map +1 -1
- package/dist/types/utility-types/late.js +109 -0
- package/dist/types/utility-types/late.js.map +1 -1
- package/dist/types/utility-types/lazy.js +76 -0
- package/dist/types/utility-types/lazy.js.map +1 -1
- package/dist/types/utility-types/literal.js +63 -0
- package/dist/types/utility-types/literal.js.map +1 -1
- package/dist/types/utility-types/maybe.js +30 -0
- package/dist/types/utility-types/maybe.js.map +1 -1
- package/dist/types/utility-types/optional.js +140 -0
- package/dist/types/utility-types/optional.js.map +1 -1
- package/dist/types/utility-types/reference.d.ts +2 -2
- package/dist/types/utility-types/reference.js +392 -0
- package/dist/types/utility-types/reference.js.map +1 -1
- package/dist/types/utility-types/refinement.js +85 -0
- package/dist/types/utility-types/refinement.js.map +1 -1
- package/dist/types/utility-types/resilient.js +120 -0
- package/dist/types/utility-types/resilient.js.map +1 -1
- package/dist/types/utility-types/snapshotProcessor.js +161 -0
- package/dist/types/utility-types/snapshotProcessor.js.map +1 -1
- package/dist/types/utility-types/union.d.ts +1 -0
- package/dist/types/utility-types/union.js +245 -0
- package/dist/types/utility-types/union.js.map +1 -1
- package/dist/utils.js +483 -0
- package/dist/utils.js.map +1 -1
- package/package.json +25 -24
- package/changelog.md +0 -677
- package/dist/mobx-state-tree.umd.js +0 -6873
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CustomReferenceType = exports.IdentifierReferenceType = exports.BaseReferenceType = exports.InvalidReferenceError = void 0;
|
|
4
|
+
exports.reference = reference;
|
|
5
|
+
exports.isReferenceType = isReferenceType;
|
|
6
|
+
exports.safeReference = safeReference;
|
|
7
|
+
const internal_ts_1 = require("../../internal.js");
|
|
8
|
+
function getInvalidationCause(hook) {
|
|
9
|
+
switch (hook) {
|
|
10
|
+
case internal_ts_1.Hook.beforeDestroy:
|
|
11
|
+
return "destroy";
|
|
12
|
+
case internal_ts_1.Hook.beforeDetach:
|
|
13
|
+
return "detach";
|
|
14
|
+
default:
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
class StoredReference {
|
|
19
|
+
targetType;
|
|
20
|
+
identifier;
|
|
21
|
+
node;
|
|
22
|
+
resolvedReference;
|
|
23
|
+
constructor(value, targetType) {
|
|
24
|
+
this.targetType = targetType;
|
|
25
|
+
if ((0, internal_ts_1.isValidIdentifier)(value)) {
|
|
26
|
+
this.identifier = value;
|
|
27
|
+
}
|
|
28
|
+
else if ((0, internal_ts_1.isStateTreeNode)(value)) {
|
|
29
|
+
const targetNode = (0, internal_ts_1.getStateTreeNode)(value);
|
|
30
|
+
if (!targetNode.identifierAttribute) {
|
|
31
|
+
throw (0, internal_ts_1.fail)(`Can only store references with a defined identifier attribute.`);
|
|
32
|
+
}
|
|
33
|
+
const id = targetNode.unnormalizedIdentifier;
|
|
34
|
+
if (id === null || id === undefined) {
|
|
35
|
+
throw (0, internal_ts_1.fail)(`Can only store references to tree nodes with a defined identifier.`);
|
|
36
|
+
}
|
|
37
|
+
this.identifier = id;
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
throw (0, internal_ts_1.fail)(`Can only store references to tree nodes or identifiers, got: '${value}'`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
updateResolvedReference(node) {
|
|
44
|
+
const normalizedId = (0, internal_ts_1.normalizeIdentifier)(this.identifier);
|
|
45
|
+
const root = node.root;
|
|
46
|
+
const lastCacheModification = root.identifierCache.getLastCacheModificationPerId(normalizedId);
|
|
47
|
+
if (!this.resolvedReference ||
|
|
48
|
+
this.resolvedReference.lastCacheModification !== lastCacheModification) {
|
|
49
|
+
const { targetType } = this;
|
|
50
|
+
// reference was initialized with the identifier of the target
|
|
51
|
+
const target = root.identifierCache.resolve(targetType, normalizedId);
|
|
52
|
+
if (!target) {
|
|
53
|
+
throw new InvalidReferenceError(`[mobx-state-tree] Failed to resolve reference '${this.identifier}' to type '${this.targetType.name}' (from node: ${node.path})`);
|
|
54
|
+
}
|
|
55
|
+
this.resolvedReference = {
|
|
56
|
+
node: target,
|
|
57
|
+
lastCacheModification: lastCacheModification
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
get resolvedValue() {
|
|
62
|
+
this.updateResolvedReference(this.node);
|
|
63
|
+
return this.resolvedReference.node.value;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* @internal
|
|
68
|
+
* @hidden
|
|
69
|
+
*/
|
|
70
|
+
class InvalidReferenceError extends Error {
|
|
71
|
+
constructor(m) {
|
|
72
|
+
super(m);
|
|
73
|
+
Object.setPrototypeOf(this, InvalidReferenceError.prototype);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.InvalidReferenceError = InvalidReferenceError;
|
|
77
|
+
/**
|
|
78
|
+
* @internal
|
|
79
|
+
* @hidden
|
|
80
|
+
*/
|
|
81
|
+
class BaseReferenceType extends internal_ts_1.SimpleType {
|
|
82
|
+
targetType;
|
|
83
|
+
onInvalidated;
|
|
84
|
+
flags = internal_ts_1.TypeFlags.Reference;
|
|
85
|
+
constructor(targetType, onInvalidated) {
|
|
86
|
+
super(`reference(${targetType.name})`);
|
|
87
|
+
this.targetType = targetType;
|
|
88
|
+
this.onInvalidated = onInvalidated;
|
|
89
|
+
}
|
|
90
|
+
describe() {
|
|
91
|
+
return this.name;
|
|
92
|
+
}
|
|
93
|
+
isAssignableFrom(type) {
|
|
94
|
+
return this.targetType.isAssignableFrom(type);
|
|
95
|
+
}
|
|
96
|
+
isValidSnapshot(value, context) {
|
|
97
|
+
return (0, internal_ts_1.isValidIdentifier)(value)
|
|
98
|
+
? (0, internal_ts_1.typeCheckSuccess)()
|
|
99
|
+
: (0, internal_ts_1.typeCheckFailure)(context, value, "Value is not a valid identifier, which is a string or a number");
|
|
100
|
+
}
|
|
101
|
+
fireInvalidated(cause, storedRefNode, referenceId, refTargetNode) {
|
|
102
|
+
// to actually invalidate a reference we need an alive parent,
|
|
103
|
+
// since it is a scalar value (immutable-ish) and we need to change it
|
|
104
|
+
// from the parent
|
|
105
|
+
const storedRefParentNode = storedRefNode.parent;
|
|
106
|
+
if (!storedRefParentNode || !storedRefParentNode.isAlive) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const storedRefParentValue = storedRefParentNode.storedValue;
|
|
110
|
+
if (!storedRefParentValue) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
this.onInvalidated({
|
|
114
|
+
cause,
|
|
115
|
+
parent: storedRefParentValue,
|
|
116
|
+
invalidTarget: refTargetNode ? refTargetNode.storedValue : undefined,
|
|
117
|
+
invalidId: referenceId,
|
|
118
|
+
replaceRef(newRef) {
|
|
119
|
+
(0, internal_ts_1.applyPatch)(storedRefNode.root.storedValue, {
|
|
120
|
+
op: "replace",
|
|
121
|
+
value: newRef,
|
|
122
|
+
path: storedRefNode.path
|
|
123
|
+
});
|
|
124
|
+
},
|
|
125
|
+
removeRef() {
|
|
126
|
+
if ((0, internal_ts_1.isModelType)(storedRefParentNode.type)) {
|
|
127
|
+
this.replaceRef(undefined);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
(0, internal_ts_1.applyPatch)(storedRefNode.root.storedValue, {
|
|
131
|
+
op: "remove",
|
|
132
|
+
path: storedRefNode.path
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
addTargetNodeWatcher(storedRefNode, referenceId) {
|
|
139
|
+
// this will make sure the target node becomes created
|
|
140
|
+
const refTargetValue = this.getValue(storedRefNode);
|
|
141
|
+
if (!refTargetValue) {
|
|
142
|
+
return undefined;
|
|
143
|
+
}
|
|
144
|
+
const refTargetNode = (0, internal_ts_1.getStateTreeNode)(refTargetValue);
|
|
145
|
+
const hookHandler = (_, refTargetNodeHook) => {
|
|
146
|
+
const cause = getInvalidationCause(refTargetNodeHook);
|
|
147
|
+
if (!cause) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
this.fireInvalidated(cause, storedRefNode, referenceId, refTargetNode);
|
|
151
|
+
};
|
|
152
|
+
const refTargetDetachHookDisposer = refTargetNode.registerHook(internal_ts_1.Hook.beforeDetach, hookHandler);
|
|
153
|
+
const refTargetDestroyHookDisposer = refTargetNode.registerHook(internal_ts_1.Hook.beforeDestroy, hookHandler);
|
|
154
|
+
return () => {
|
|
155
|
+
refTargetDetachHookDisposer();
|
|
156
|
+
refTargetDestroyHookDisposer();
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
watchTargetNodeForInvalidations(storedRefNode, identifier, customGetSet) {
|
|
160
|
+
if (!this.onInvalidated) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
let onRefTargetDestroyedHookDisposer;
|
|
164
|
+
// get rid of the watcher hook when the stored ref node is destroyed
|
|
165
|
+
// detached is ignored since scalar nodes (where the reference resides) cannot be detached
|
|
166
|
+
storedRefNode.registerHook(internal_ts_1.Hook.beforeDestroy, () => {
|
|
167
|
+
if (onRefTargetDestroyedHookDisposer) {
|
|
168
|
+
onRefTargetDestroyedHookDisposer();
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
const startWatching = (sync) => {
|
|
172
|
+
// re-create hook in case the stored ref gets reattached
|
|
173
|
+
if (onRefTargetDestroyedHookDisposer) {
|
|
174
|
+
onRefTargetDestroyedHookDisposer();
|
|
175
|
+
}
|
|
176
|
+
// make sure the target node is actually there and initialized
|
|
177
|
+
const storedRefParentNode = storedRefNode.parent;
|
|
178
|
+
const storedRefParentValue = storedRefParentNode && storedRefParentNode.storedValue;
|
|
179
|
+
if (storedRefParentNode &&
|
|
180
|
+
storedRefParentNode.isAlive &&
|
|
181
|
+
storedRefParentValue) {
|
|
182
|
+
let refTargetNodeExists;
|
|
183
|
+
if (customGetSet) {
|
|
184
|
+
refTargetNodeExists = !!customGetSet.get(identifier, storedRefParentValue);
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
refTargetNodeExists = storedRefNode.root.identifierCache.has(this.targetType, (0, internal_ts_1.normalizeIdentifier)(identifier));
|
|
188
|
+
}
|
|
189
|
+
if (!refTargetNodeExists) {
|
|
190
|
+
// we cannot change the reference in sync mode
|
|
191
|
+
// since we are in the middle of a reconciliation/instantiation and the change would be overwritten
|
|
192
|
+
// for those cases just let the wrong reference be assigned and fail upon usage
|
|
193
|
+
// (like current references do)
|
|
194
|
+
// this means that effectively this code will only run when it is created from a snapshot
|
|
195
|
+
if (!sync) {
|
|
196
|
+
this.fireInvalidated("invalidSnapshotReference", storedRefNode, identifier, null);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
onRefTargetDestroyedHookDisposer = this.addTargetNodeWatcher(storedRefNode, identifier);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
if (storedRefNode.state === internal_ts_1.NodeLifeCycle.FINALIZED) {
|
|
205
|
+
// already attached, so the whole tree is ready
|
|
206
|
+
startWatching(true);
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
if (!storedRefNode.isRoot) {
|
|
210
|
+
// start watching once the whole tree is ready
|
|
211
|
+
storedRefNode.root.registerHook(internal_ts_1.Hook.afterCreationFinalization, () => {
|
|
212
|
+
// make sure to attach it so it can start listening
|
|
213
|
+
if (storedRefNode.parent) {
|
|
214
|
+
storedRefNode.parent.createObservableInstanceIfNeeded();
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
// start watching once the node is attached somewhere / parent changes
|
|
219
|
+
storedRefNode.registerHook(internal_ts_1.Hook.afterAttach, () => {
|
|
220
|
+
startWatching(false);
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
exports.BaseReferenceType = BaseReferenceType;
|
|
226
|
+
/**
|
|
227
|
+
* @internal
|
|
228
|
+
* @hidden
|
|
229
|
+
*/
|
|
230
|
+
class IdentifierReferenceType extends BaseReferenceType {
|
|
231
|
+
constructor(targetType, onInvalidated) {
|
|
232
|
+
super(targetType, onInvalidated);
|
|
233
|
+
}
|
|
234
|
+
getValue(storedRefNode) {
|
|
235
|
+
if (!storedRefNode.isAlive) {
|
|
236
|
+
return undefined;
|
|
237
|
+
}
|
|
238
|
+
const storedRef = storedRefNode.storedValue;
|
|
239
|
+
return storedRef.resolvedValue;
|
|
240
|
+
}
|
|
241
|
+
getSnapshot(storedRefNode) {
|
|
242
|
+
const ref = storedRefNode.storedValue;
|
|
243
|
+
return ref.identifier;
|
|
244
|
+
}
|
|
245
|
+
instantiate(parent, subpath, environment, initialValue) {
|
|
246
|
+
const identifier = (0, internal_ts_1.isStateTreeNode)(initialValue)
|
|
247
|
+
? (0, internal_ts_1.getIdentifier)(initialValue)
|
|
248
|
+
: initialValue;
|
|
249
|
+
const storedRef = new StoredReference(initialValue, this.targetType);
|
|
250
|
+
const storedRefNode = (0, internal_ts_1.createScalarNode)(this, parent, subpath, environment, storedRef);
|
|
251
|
+
storedRef.node = storedRefNode;
|
|
252
|
+
this.watchTargetNodeForInvalidations(storedRefNode, identifier, undefined);
|
|
253
|
+
return storedRefNode;
|
|
254
|
+
}
|
|
255
|
+
reconcile(current, newValue, parent, subpath) {
|
|
256
|
+
if (!current.isDetaching && current.type === this) {
|
|
257
|
+
const compareByValue = (0, internal_ts_1.isStateTreeNode)(newValue);
|
|
258
|
+
const ref = current.storedValue;
|
|
259
|
+
if ((!compareByValue && ref.identifier === newValue) ||
|
|
260
|
+
(compareByValue && ref.resolvedValue === newValue)) {
|
|
261
|
+
current.setParent(parent, subpath);
|
|
262
|
+
return current;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
const newNode = this.instantiate(parent, subpath, undefined, newValue);
|
|
266
|
+
current.die(); // noop if detaching
|
|
267
|
+
return newNode;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
exports.IdentifierReferenceType = IdentifierReferenceType;
|
|
271
|
+
/**
|
|
272
|
+
* @internal
|
|
273
|
+
* @hidden
|
|
274
|
+
*/
|
|
275
|
+
class CustomReferenceType extends BaseReferenceType {
|
|
276
|
+
options;
|
|
277
|
+
constructor(targetType, options, onInvalidated) {
|
|
278
|
+
super(targetType, onInvalidated);
|
|
279
|
+
this.options = options;
|
|
280
|
+
}
|
|
281
|
+
getValue(storedRefNode) {
|
|
282
|
+
if (!storedRefNode.isAlive) {
|
|
283
|
+
return undefined;
|
|
284
|
+
}
|
|
285
|
+
const referencedNode = this.options.get(storedRefNode.storedValue, storedRefNode.parent ? storedRefNode.parent.storedValue : null);
|
|
286
|
+
return referencedNode;
|
|
287
|
+
}
|
|
288
|
+
getSnapshot(storedRefNode) {
|
|
289
|
+
return storedRefNode.storedValue;
|
|
290
|
+
}
|
|
291
|
+
instantiate(parent, subpath, environment, newValue) {
|
|
292
|
+
const identifier = (0, internal_ts_1.isStateTreeNode)(newValue)
|
|
293
|
+
? this.options.set(newValue, parent ? parent.storedValue : null)
|
|
294
|
+
: newValue;
|
|
295
|
+
const storedRefNode = (0, internal_ts_1.createScalarNode)(this, parent, subpath, environment, identifier);
|
|
296
|
+
this.watchTargetNodeForInvalidations(storedRefNode, identifier, this.options);
|
|
297
|
+
return storedRefNode;
|
|
298
|
+
}
|
|
299
|
+
reconcile(current, newValue, parent, subpath) {
|
|
300
|
+
const newIdentifier = (0, internal_ts_1.isStateTreeNode)(newValue)
|
|
301
|
+
? this.options.set(newValue, current ? current.storedValue : null)
|
|
302
|
+
: newValue;
|
|
303
|
+
if (!current.isDetaching &&
|
|
304
|
+
current.type === this &&
|
|
305
|
+
current.storedValue === newIdentifier) {
|
|
306
|
+
current.setParent(parent, subpath);
|
|
307
|
+
return current;
|
|
308
|
+
}
|
|
309
|
+
const newNode = this.instantiate(parent, subpath, undefined, newIdentifier);
|
|
310
|
+
current.die(); // noop if detaching
|
|
311
|
+
return newNode;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
exports.CustomReferenceType = CustomReferenceType;
|
|
315
|
+
/**
|
|
316
|
+
* `types.reference` - Creates a reference to another type, which should have defined an identifier.
|
|
317
|
+
* See also the [reference and identifiers](https://github.com/mobxjs/mobx-state-tree#references-and-identifiers) section.
|
|
318
|
+
*/
|
|
319
|
+
function reference(subType, options) {
|
|
320
|
+
(0, internal_ts_1.assertIsType)(subType, 1);
|
|
321
|
+
if ((0, internal_ts_1.devMode)()) {
|
|
322
|
+
if (options && typeof options === "string") {
|
|
323
|
+
// istanbul ignore next
|
|
324
|
+
throw (0, internal_ts_1.fail)("References with base path are no longer supported. Please remove the base path.");
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
const getSetOptions = options
|
|
328
|
+
? options
|
|
329
|
+
: undefined;
|
|
330
|
+
const onInvalidated = options
|
|
331
|
+
? options.onInvalidated
|
|
332
|
+
: undefined;
|
|
333
|
+
if (getSetOptions && (getSetOptions.get || getSetOptions.set)) {
|
|
334
|
+
if ((0, internal_ts_1.devMode)()) {
|
|
335
|
+
if (!getSetOptions.get || !getSetOptions.set) {
|
|
336
|
+
throw (0, internal_ts_1.fail)("reference options must either contain both a 'get' and a 'set' method or none of them");
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
return new CustomReferenceType(subType, {
|
|
340
|
+
get: getSetOptions.get,
|
|
341
|
+
set: getSetOptions.set
|
|
342
|
+
}, onInvalidated);
|
|
343
|
+
}
|
|
344
|
+
else {
|
|
345
|
+
return new IdentifierReferenceType(subType, onInvalidated);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Returns if a given value represents a reference type.
|
|
350
|
+
*
|
|
351
|
+
* @param type
|
|
352
|
+
* @returns
|
|
353
|
+
*/
|
|
354
|
+
function isReferenceType(type) {
|
|
355
|
+
return (type.flags & internal_ts_1.TypeFlags.Reference) > 0;
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* `types.safeReference` - A safe reference is like a standard reference, except that it accepts the undefined value by default
|
|
359
|
+
* and automatically sets itself to undefined (when the parent is a model) / removes itself from arrays and maps
|
|
360
|
+
* when the reference it is pointing to gets detached/destroyed.
|
|
361
|
+
*
|
|
362
|
+
* The optional options parameter object accepts a parameter named `acceptsUndefined`, which is set to true by default, so it is suitable
|
|
363
|
+
* for model properties.
|
|
364
|
+
* When used inside collections (arrays/maps), it is recommended to set this option to false so it can't take undefined as value,
|
|
365
|
+
* which is usually the desired in those cases.
|
|
366
|
+
* Additionally, the optional options parameter object accepts a parameter named `onInvalidated`, which will be called when the reference target node that the reference is pointing to is about to be detached/destroyed
|
|
367
|
+
*
|
|
368
|
+
* Strictly speaking it is a `types.maybe(types.reference(X))` (when `acceptsUndefined` is set to true, the default) and
|
|
369
|
+
* `types.reference(X)` (when `acceptsUndefined` is set to false), both of them with a customized `onInvalidated` option.
|
|
370
|
+
*
|
|
371
|
+
* @param subType
|
|
372
|
+
* @param options
|
|
373
|
+
* @returns
|
|
374
|
+
*/
|
|
375
|
+
function safeReference(subType, options) {
|
|
376
|
+
const refType = reference(subType, {
|
|
377
|
+
...options,
|
|
378
|
+
onInvalidated(ev) {
|
|
379
|
+
if (options && options.onInvalidated) {
|
|
380
|
+
options.onInvalidated(ev);
|
|
381
|
+
}
|
|
382
|
+
ev.removeRef();
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
if (options && options.acceptsUndefined === false) {
|
|
386
|
+
return refType;
|
|
387
|
+
}
|
|
388
|
+
else {
|
|
389
|
+
return (0, internal_ts_1.maybe)(refType);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
//# sourceMappingURL=reference.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reference.js","sourceRoot":"","sources":["../../../src/types/utility-types/reference.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,IAAI,EAUJ,aAAa,EAEb,UAAU,EACV,SAAS,EACT,UAAU,EACV,YAAY,EACZ,gBAAgB,EAChB,OAAO,EACP,IAAI,EACJ,aAAa,EACb,gBAAgB,EAChB,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,KAAK,EACL,mBAAmB,EACnB,gBAAgB,EAChB,gBAAgB,EACjB,MAAM,mBAAmB,CAAA;AAe1B,SAAS,oBAAoB,CAAC,IAAU;IACtC,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,IAAI,CAAC,aAAa;YACrB,OAAO,SAAS,CAAA;QAClB,KAAK,IAAI,CAAC,YAAY;YACpB,OAAO,QAAQ,CAAA;QACjB;YACE,OAAO,SAAS,CAAA;IACpB,CAAC;AACH,CAAC;AAMD,MAAM,eAAe;IAWA;IAVV,UAAU,CAAsB;IACzC,IAAI,CAAU;IAEN,iBAAiB,CAGxB;IAED,YACE,KAA2C,EAC1B,UAAc;QAAd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;GAiBG;AACH,MAAM,UAAU,aAAa,CAC3B,OAAW,EACX,OAGC;IAED,MAAM,OAAO,GAAG,SAAS,CAAC,OAAO,EAAE;QACjC,GAAG,OAAO;QACV,aAAa,CAAC,EAAE;YACd,IAAI,OAAO,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;gBACrC,OAAO,CAAC,aAAa,CAAC,EAAE,CAAC,CAAA;YAC3B,CAAC;YACD,EAAE,CAAC,SAAS,EAAE,CAAA;QAChB,CAAC;KACF,CAAC,CAAA;IAEF,IAAI,OAAO,IAAI,OAAO,CAAC,gBAAgB,KAAK,KAAK,EAAE,CAAC;QAClD,OAAO,OAAO,CAAA;IAChB,CAAC;SAAM,CAAC;QACN,OAAO,KAAK,CAAC,OAAO,CAAC,CAAA;IACvB,CAAC;AACH,CAAC"}
|
|
1
|
+
{"version":3,"file":"reference.js","sourceRoot":"","sources":["../../../src/types/utility-types/reference.ts"],"names":[],"mappings":";;;AAuhBA,8BAyCC;AAQD,0CAIC;AAkCD,sCAsBC;AApoBD,mDA+B0B;AAe1B,SAAS,oBAAoB,CAAC,IAAU;IACtC,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,kBAAI,CAAC,aAAa;YACrB,OAAO,SAAS,CAAA;QAClB,KAAK,kBAAI,CAAC,YAAY;YACpB,OAAO,QAAQ,CAAA;QACjB;YACE,OAAO,SAAS,CAAA;IACpB,CAAC;AACH,CAAC;AAMD,MAAM,eAAe;IAWA;IAVV,UAAU,CAAsB;IACzC,IAAI,CAAU;IAEN,iBAAiB,CAGxB;IAED,YACE,KAA2C,EAC1B,UAAc;QAAd,eAAU,GAAV,UAAU,CAAI;QAE/B,IAAI,IAAA,+BAAiB,EAAC,KAAK,CAAC,EAAE,CAAC;YAC7B,IAAI,CAAC,UAAU,GAAG,KAAK,CAAA;QACzB,CAAC;aAAM,IAAI,IAAA,6BAAe,EAAC,KAAK,CAAC,EAAE,CAAC;YAClC,MAAM,UAAU,GAAG,IAAA,8BAAgB,EA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,OAAO,GAAG,SAAS,CAAC,OAAO,EAAE;QACjC,GAAG,OAAO;QACV,aAAa,CAAC,EAAE;YACd,IAAI,OAAO,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;gBACrC,OAAO,CAAC,aAAa,CAAC,EAAE,CAAC,CAAA;YAC3B,CAAC;YACD,EAAE,CAAC,SAAS,EAAE,CAAA;QAChB,CAAC;KACF,CAAC,CAAA;IAEF,IAAI,OAAO,IAAI,OAAO,CAAC,gBAAgB,KAAK,KAAK,EAAE,CAAC;QAClD,OAAO,OAAO,CAAA;IAChB,CAAC;SAAM,CAAC;QACN,OAAO,IAAA,mBAAK,EAAC,OAAO,CAAC,CAAA;IACvB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.refinement = refinement;
|
|
4
|
+
exports.isRefinementType = isRefinementType;
|
|
5
|
+
const internal_ts_1 = require("../../internal.js");
|
|
6
|
+
const utils_ts_1 = require("../../utils.js");
|
|
7
|
+
class Refinement extends internal_ts_1.BaseType {
|
|
8
|
+
_subtype;
|
|
9
|
+
_predicate;
|
|
10
|
+
_message;
|
|
11
|
+
get flags() {
|
|
12
|
+
return this._subtype.flags | internal_ts_1.TypeFlags.Refinement;
|
|
13
|
+
}
|
|
14
|
+
constructor(name, _subtype, _predicate, _message) {
|
|
15
|
+
super(name);
|
|
16
|
+
this._subtype = _subtype;
|
|
17
|
+
this._predicate = _predicate;
|
|
18
|
+
this._message = _message;
|
|
19
|
+
}
|
|
20
|
+
describe() {
|
|
21
|
+
return this.name;
|
|
22
|
+
}
|
|
23
|
+
instantiate(parent, subpath, environment, initialValue) {
|
|
24
|
+
// create the child type
|
|
25
|
+
return this._subtype.instantiate(parent, subpath, environment, initialValue);
|
|
26
|
+
}
|
|
27
|
+
isAssignableFrom(type) {
|
|
28
|
+
return this._subtype.isAssignableFrom(type);
|
|
29
|
+
}
|
|
30
|
+
isValidSnapshot(value, context) {
|
|
31
|
+
const subtypeErrors = this._subtype.validate(value, context);
|
|
32
|
+
if (subtypeErrors.length > 0) {
|
|
33
|
+
return subtypeErrors;
|
|
34
|
+
}
|
|
35
|
+
const snapshot = (0, internal_ts_1.isStateTreeNode)(value)
|
|
36
|
+
? (0, internal_ts_1.getStateTreeNode)(value).snapshot
|
|
37
|
+
: value;
|
|
38
|
+
if (!this._predicate(snapshot)) {
|
|
39
|
+
return (0, internal_ts_1.typeCheckFailure)(context, value, this._message(value));
|
|
40
|
+
}
|
|
41
|
+
return (0, internal_ts_1.typeCheckSuccess)();
|
|
42
|
+
}
|
|
43
|
+
reconcile(current, newValue, parent, subpath) {
|
|
44
|
+
return this._subtype.reconcile(current, newValue, parent, subpath);
|
|
45
|
+
}
|
|
46
|
+
getSubTypes() {
|
|
47
|
+
return this._subtype;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* `types.refinement` - Creates a type that is more specific than the base type, e.g. `types.refinement(types.string, value => value.length > 5)` to create a type of strings that can only be longer then 5.
|
|
52
|
+
*
|
|
53
|
+
* @param name
|
|
54
|
+
* @param type
|
|
55
|
+
* @param predicate
|
|
56
|
+
* @returns
|
|
57
|
+
*/
|
|
58
|
+
function refinement(...args) {
|
|
59
|
+
const name = typeof args[0] === "string"
|
|
60
|
+
? args.shift()
|
|
61
|
+
: (0, internal_ts_1.isType)(args[0])
|
|
62
|
+
? args[0].name
|
|
63
|
+
: null;
|
|
64
|
+
const type = args[0];
|
|
65
|
+
const predicate = args[1];
|
|
66
|
+
const message = args[2]
|
|
67
|
+
? args[2]
|
|
68
|
+
: (_v) => "Value does not respect the refinement predicate";
|
|
69
|
+
// ensures all parameters are correct
|
|
70
|
+
(0, internal_ts_1.assertIsType)(type, [1, 2]);
|
|
71
|
+
(0, utils_ts_1.assertIsString)(name, 1);
|
|
72
|
+
(0, utils_ts_1.assertIsFunction)(predicate, [2, 3]);
|
|
73
|
+
(0, utils_ts_1.assertIsFunction)(message, [3, 4]);
|
|
74
|
+
return new Refinement(name, type, predicate, message);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Returns if a given value is a refinement type.
|
|
78
|
+
*
|
|
79
|
+
* @param type
|
|
80
|
+
* @returns
|
|
81
|
+
*/
|
|
82
|
+
function isRefinementType(type) {
|
|
83
|
+
return (type.flags & internal_ts_1.TypeFlags.Refinement) > 0;
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=refinement.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refinement.js","sourceRoot":"","sources":["../../../src/types/utility-types/refinement.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"refinement.js","sourceRoot":"","sources":["../../../src/types/utility-types/refinement.ts"],"names":[],"mappings":";;AAiHA,gCAmBC;AAQD,4CAEC;AA9ID,mDAc0B;AAC1B,6CAAiE;AAEjE,MAAM,UAAgC,SAAQ,sBAK7C;IAOoB;IACA;IACA;IARnB,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,GAAG,uBAAS,CAAC,UAAU,CAAA;IACnD,CAAC;IAED,YACE,IAAY,EACK,QAAY,EACZ,UAA8C,EAC9C,QAA2C;QAE5D,KAAK,CAAC,IAAI,CAAC,CAAA;QAJM,aAAQ,GAAR,QAAQ,CAAI;QACZ,eAAU,GAAV,UAAU,CAAoC;QAC9C,aAAQ,GAAR,QAAQ,CAAmC;IAG9D,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,IAAI,CAAA;IAClB,CAAC;IAED,WAAW,CACT,MAA4B,EAC5B,OAAe,EACf,WAAgB,EAChB,YAAmC;QAEnC,wBAAwB;QACxB,OAAO,IAAI,CAAC,QAAQ,CAAC,WAAW,CAC9B,MAAM,EACN,OAAO,EACP,WAAW,EACX,YAAY,CACN,CAAA;IACV,CAAC;IAED,gBAAgB,CAAC,IAAc;QAC7B,OAAO,IAAI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IACZ,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA;IACpB,MAAM,SAAS,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA;IACzB,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC;QACrB,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;QACT,CAAC,CAAC,CAAC,EAAO,EAAE,EAAE,CAAC,iDAAiD,CAAA;IAClE,qCAAqC;IACrC,IAAA,0BAAY,EAAC,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IAC1B,IAAA,yBAAc,EAAC,IAAI,EAAE,CAAC,CAAC,CAAA;IACvB,IAAA,2BAAgB,EAAC,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IACnC,IAAA,2BAAgB,EAAC,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IAEjC,OAAO,IAAI,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC,CAAA;AACvD,CAAC;AAED;;;;;GAKG;AACH,SAAgB,gBAAgB,CAAsB,IAAQ;IAC5D,OAAO,CAAC,IAAI,CAAC,KAAK,GAAG,uBAAS,CAAC,UAAU,CAAC,GAAG,CAAC,CAAA;AAChD,CAAC"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resilient = resilient;
|
|
4
|
+
const internal_ts_1 = require("../../internal.js");
|
|
5
|
+
class Resilient extends internal_ts_1.BaseType {
|
|
6
|
+
_subtype;
|
|
7
|
+
_fallbackType;
|
|
8
|
+
_createFallbackSnapshot;
|
|
9
|
+
get flags() {
|
|
10
|
+
return this._subtype.flags;
|
|
11
|
+
}
|
|
12
|
+
constructor(_subtype, _fallbackType, _createFallbackSnapshot) {
|
|
13
|
+
super(`resilient(${_subtype.name})`);
|
|
14
|
+
this._subtype = _subtype;
|
|
15
|
+
this._fallbackType = _fallbackType;
|
|
16
|
+
this._createFallbackSnapshot = _createFallbackSnapshot;
|
|
17
|
+
}
|
|
18
|
+
describe() {
|
|
19
|
+
return `resilient(${this._subtype.describe()})`;
|
|
20
|
+
}
|
|
21
|
+
_instantiateFallback(parent, subpath, environment, originalSnapshot, originalError) {
|
|
22
|
+
let fallbackSnapshot;
|
|
23
|
+
try {
|
|
24
|
+
fallbackSnapshot = this._createFallbackSnapshot(originalError, originalSnapshot);
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
throw (0, internal_ts_1.fail)(`resilient: createFallbackSnapshot threw while handling error for '${this._subtype.name}': ${originalError}. createFallbackSnapshot error: ${e}`);
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
return this._fallbackType.instantiate(parent, subpath, environment, fallbackSnapshot);
|
|
31
|
+
}
|
|
32
|
+
catch (e) {
|
|
33
|
+
throw (0, internal_ts_1.fail)(`resilient: fallback type '${this._fallbackType.name}' failed to instantiate while handling error for '${this._subtype.name}': ${originalError}. Fallback error: ${e}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
instantiate(parent, subpath, environment, initialValue) {
|
|
37
|
+
if ((0, internal_ts_1.isStateTreeNode)(initialValue)) {
|
|
38
|
+
return this._subtype.instantiate(parent, subpath, environment, initialValue);
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
return this._subtype.instantiate(parent, subpath, environment, initialValue);
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
return this._instantiateFallback(parent, subpath, environment, initialValue, e);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
reconcile(current, newValue, parent, subpath) {
|
|
48
|
+
if ((0, internal_ts_1.isStateTreeNode)(newValue)) {
|
|
49
|
+
return this._subtype.reconcile(current, newValue, parent, subpath);
|
|
50
|
+
}
|
|
51
|
+
if (this._fallbackType.isAssignableFrom(current.type)) {
|
|
52
|
+
try {
|
|
53
|
+
return this._subtype.instantiate(parent, subpath, undefined, newValue);
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
return this._fallbackType.reconcile(current, this._createFallbackSnapshot(e, newValue), parent, subpath);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
return this._subtype.reconcile(current, newValue, parent, subpath);
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
current.die();
|
|
64
|
+
return this._instantiateFallback(parent, subpath, undefined, newValue, e);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
isValidSnapshot(_value, _context) {
|
|
68
|
+
return (0, internal_ts_1.typeCheckSuccess)();
|
|
69
|
+
}
|
|
70
|
+
is(thing) {
|
|
71
|
+
if ((0, internal_ts_1.isType)(thing)) {
|
|
72
|
+
return (this._subtype.isAssignableFrom(thing) ||
|
|
73
|
+
this._fallbackType.isAssignableFrom(thing));
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
if (this._subtype.is(thing)) {
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
catch (_e) {
|
|
81
|
+
// subtype.is() may throw (e.g. union dispatcher)
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
return this._fallbackType.is(thing);
|
|
85
|
+
}
|
|
86
|
+
catch (_e) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
isAssignableFrom(type) {
|
|
91
|
+
return (this._subtype.isAssignableFrom(type) ||
|
|
92
|
+
this._fallbackType.isAssignableFrom(type));
|
|
93
|
+
}
|
|
94
|
+
getSubTypes() {
|
|
95
|
+
return [this._subtype, this._fallbackType];
|
|
96
|
+
}
|
|
97
|
+
getSnapshot(node) {
|
|
98
|
+
return node.snapshot;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* `types.resilient` - Wraps a type so that instantiation errors are caught
|
|
103
|
+
* and a fallback type is used instead. This is useful for loading data that
|
|
104
|
+
* may contain unknown or invalid subtrees (e.g., plugin types that are not
|
|
105
|
+
* installed) without crashing the entire state tree.
|
|
106
|
+
*
|
|
107
|
+
* The `createFallbackSnapshot` callback receives the caught error and the
|
|
108
|
+
* original snapshot, and must return a valid snapshot for the fallback type.
|
|
109
|
+
*
|
|
110
|
+
* @param type The type to wrap.
|
|
111
|
+
* @param fallbackType The fallback type to use when instantiation fails.
|
|
112
|
+
* @param createFallbackSnapshot Callback that produces a fallback snapshot from the error and original snapshot.
|
|
113
|
+
* @returns A resilient type.
|
|
114
|
+
*/
|
|
115
|
+
function resilient(type, fallbackType, createFallbackSnapshot) {
|
|
116
|
+
(0, internal_ts_1.assertIsType)(type, 1);
|
|
117
|
+
(0, internal_ts_1.assertIsType)(fallbackType, 2);
|
|
118
|
+
return new Resilient(type, fallbackType, createFallbackSnapshot);
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=resilient.js.map
|