@jbrowse/mobx-state-tree 5.6.3 → 5.6.6
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/dist/core/action.d.ts +87 -0
- package/dist/core/action.js +228 -0
- package/dist/core/action.js.map +1 -0
- package/dist/core/actionContext.d.ts +27 -0
- package/dist/core/actionContext.js +42 -0
- package/dist/core/actionContext.js.map +1 -0
- package/dist/core/flow.d.ts +69 -0
- package/dist/core/flow.js +180 -0
- package/dist/core/flow.js.map +1 -0
- package/dist/core/json-patch.d.ts +46 -0
- package/dist/core/json-patch.js +133 -0
- package/dist/core/json-patch.js.map +1 -0
- package/dist/core/mst-operations.d.ts +459 -0
- package/dist/core/mst-operations.js +885 -0
- package/dist/core/mst-operations.js.map +1 -0
- package/dist/core/node/BaseNode.d.ts +62 -0
- package/dist/core/node/BaseNode.js +152 -0
- package/dist/core/node/BaseNode.js.map +1 -0
- package/dist/core/node/Hook.d.ts +17 -0
- package/dist/core/node/Hook.js +15 -0
- package/dist/core/node/Hook.js.map +1 -0
- package/dist/core/node/create-node.d.ts +16 -0
- package/dist/core/node/create-node.js +41 -0
- package/dist/core/node/create-node.js.map +1 -0
- package/dist/core/node/identifier-cache.d.ts +19 -0
- package/dist/core/node/identifier-cache.js +115 -0
- package/dist/core/node/identifier-cache.js.map +1 -0
- package/dist/core/node/livelinessChecking.d.ts +37 -0
- package/dist/core/node/livelinessChecking.js +38 -0
- package/dist/core/node/livelinessChecking.js.map +1 -0
- package/dist/core/node/node-utils.d.ts +83 -0
- package/dist/core/node/node-utils.js +165 -0
- package/dist/core/node/node-utils.js.map +1 -0
- package/dist/core/node/object-node.d.ts +99 -0
- package/dist/core/node/object-node.js +545 -0
- package/dist/core/node/object-node.js.map +1 -0
- package/dist/core/node/scalar-node.d.ts +19 -0
- package/dist/core/node/scalar-node.js +89 -0
- package/dist/core/node/scalar-node.js.map +1 -0
- package/dist/core/process.d.ts +50 -0
- package/dist/core/process.js +39 -0
- package/dist/core/process.js.map +1 -0
- package/dist/core/type/type-checker.d.ts +69 -0
- package/dist/core/type/type-checker.js +154 -0
- package/dist/core/type/type-checker.js.map +1 -0
- package/dist/core/type/type.d.ts +317 -0
- package/dist/core/type/type.js +251 -0
- package/dist/core/type/type.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +85 -0
- package/dist/index.js.map +1 -0
- package/dist/internal.d.ts +39 -0
- package/dist/internal.js +60 -0
- package/dist/internal.js.map +1 -0
- package/dist/middlewares/create-action-tracking-middleware.d.ts +24 -0
- package/dist/middlewares/create-action-tracking-middleware.js +81 -0
- package/dist/middlewares/create-action-tracking-middleware.js.map +1 -0
- package/dist/middlewares/createActionTrackingMiddleware2.d.ts +34 -0
- package/dist/middlewares/createActionTrackingMiddleware2.js +133 -0
- package/dist/middlewares/createActionTrackingMiddleware2.js.map +1 -0
- package/dist/middlewares/on-action.d.ts +87 -0
- package/dist/middlewares/on-action.js +215 -0
- package/dist/middlewares/on-action.js.map +1 -0
- package/dist/mobx-state-tree.js +85 -0
- package/dist/mobx-state-tree.module.js +83 -0
- package/dist/types/complex-types/array.d.ts +80 -0
- package/dist/types/complex-types/array.js +352 -0
- package/dist/types/complex-types/array.js.map +1 -0
- package/dist/types/complex-types/map.d.ts +110 -0
- package/dist/types/complex-types/map.js +361 -0
- package/dist/types/complex-types/map.js.map +1 -0
- package/dist/types/complex-types/model.d.ts +192 -0
- package/dist/types/complex-types/model.js +477 -0
- package/dist/types/complex-types/model.js.map +1 -0
- package/dist/types/index.d.ts +33 -0
- package/dist/types/index.js +38 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/primitives.d.ts +124 -0
- package/dist/types/primitives.js +182 -0
- package/dist/types/primitives.js.map +1 -0
- package/dist/types/utility-types/custom.d.ts +74 -0
- package/dist/types/utility-types/custom.js +110 -0
- package/dist/types/utility-types/custom.js.map +1 -0
- package/dist/types/utility-types/enumeration.d.ts +5 -0
- package/dist/types/utility-types/enumeration.js +34 -0
- package/dist/types/utility-types/enumeration.js.map +1 -0
- package/dist/types/utility-types/frozen.d.ts +23 -0
- package/dist/types/utility-types/frozen.js +97 -0
- package/dist/types/utility-types/frozen.js.map +1 -0
- package/dist/types/utility-types/identifier.d.ts +86 -0
- package/dist/types/utility-types/identifier.js +129 -0
- package/dist/types/utility-types/identifier.js.map +1 -0
- package/dist/types/utility-types/late.d.ts +10 -0
- package/dist/types/utility-types/late.js +109 -0
- package/dist/types/utility-types/late.js.map +1 -0
- package/dist/types/utility-types/lazy.d.ts +22 -0
- package/dist/types/utility-types/lazy.js +76 -0
- package/dist/types/utility-types/lazy.js.map +1 -0
- package/dist/types/utility-types/literal.d.ts +37 -0
- package/dist/types/utility-types/literal.js +63 -0
- package/dist/types/utility-types/literal.js.map +1 -0
- package/dist/types/utility-types/maybe.d.ts +26 -0
- package/dist/types/utility-types/maybe.js +30 -0
- package/dist/types/utility-types/maybe.js.map +1 -0
- package/dist/types/utility-types/optional.d.ts +41 -0
- package/dist/types/utility-types/optional.js +140 -0
- package/dist/types/utility-types/optional.js.map +1 -0
- package/dist/types/utility-types/reference.d.ts +89 -0
- package/dist/types/utility-types/reference.js +392 -0
- package/dist/types/utility-types/reference.js.map +1 -0
- package/dist/types/utility-types/refinement.d.ts +10 -0
- package/dist/types/utility-types/refinement.js +85 -0
- package/dist/types/utility-types/refinement.js.map +1 -0
- package/dist/types/utility-types/resilient.d.ts +18 -0
- package/dist/types/utility-types/resilient.js +120 -0
- package/dist/types/utility-types/resilient.js.map +1 -0
- package/dist/types/utility-types/snapshotProcessor.d.ts +63 -0
- package/dist/types/utility-types/snapshotProcessor.js +161 -0
- package/dist/types/utility-types/snapshotProcessor.js.map +1 -0
- package/dist/types/utility-types/union.d.ts +77 -0
- package/dist/types/utility-types/union.js +245 -0
- package/dist/types/utility-types/union.js.map +1 -0
- package/dist/utils.d.ts +230 -0
- package/dist/utils.js +483 -0
- package/dist/utils.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ArrayType = void 0;
|
|
4
|
+
exports.array = array;
|
|
5
|
+
exports.isArrayType = isArrayType;
|
|
6
|
+
const mobx_1 = require("mobx");
|
|
7
|
+
const internal_ts_1 = require("../../internal.js");
|
|
8
|
+
/**
|
|
9
|
+
* @internal
|
|
10
|
+
* @hidden
|
|
11
|
+
*/
|
|
12
|
+
class ArrayType extends internal_ts_1.ComplexType {
|
|
13
|
+
_subType;
|
|
14
|
+
flags = internal_ts_1.TypeFlags.Array;
|
|
15
|
+
hookInitializers = [];
|
|
16
|
+
constructor(name, _subType, hookInitializers = []) {
|
|
17
|
+
super(name);
|
|
18
|
+
this._subType = _subType;
|
|
19
|
+
this.hookInitializers = hookInitializers;
|
|
20
|
+
}
|
|
21
|
+
hooks(hooks) {
|
|
22
|
+
const hookInitializers = this.hookInitializers.length > 0
|
|
23
|
+
? this.hookInitializers.concat(hooks)
|
|
24
|
+
: [hooks];
|
|
25
|
+
return new ArrayType(this.name, this._subType, hookInitializers);
|
|
26
|
+
}
|
|
27
|
+
instantiate(parent, subpath, environment, initialValue) {
|
|
28
|
+
return (0, internal_ts_1.createObjectNode)(this, parent, subpath, environment, initialValue);
|
|
29
|
+
}
|
|
30
|
+
initializeChildNodes(objNode, snapshot = []) {
|
|
31
|
+
const subType = objNode.type._subType;
|
|
32
|
+
const result = {};
|
|
33
|
+
snapshot.forEach((item, index) => {
|
|
34
|
+
const subpath = "" + index;
|
|
35
|
+
result[subpath] = subType.instantiate(objNode, subpath, undefined, item);
|
|
36
|
+
});
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
createNewInstance(childNodes) {
|
|
40
|
+
const options = { ...internal_ts_1.mobxShallow, name: this.name };
|
|
41
|
+
return mobx_1.observable.array((0, internal_ts_1.convertChildNodesToArray)(childNodes), options);
|
|
42
|
+
}
|
|
43
|
+
finalizeNewInstance(node, instance) {
|
|
44
|
+
(0, mobx_1._getAdministration)(instance).dehancer = node.unbox;
|
|
45
|
+
const type = node.type;
|
|
46
|
+
type.hookInitializers.forEach(initializer => {
|
|
47
|
+
const hooks = initializer(instance);
|
|
48
|
+
Object.keys(hooks).forEach(name => {
|
|
49
|
+
const hook = hooks[name];
|
|
50
|
+
const actionInvoker = (0, internal_ts_1.createActionInvoker)(instance, name, hook);
|
|
51
|
+
(!(0, internal_ts_1.devMode)() ? internal_ts_1.addHiddenFinalProp : internal_ts_1.addHiddenWritableProp)(instance, name, actionInvoker);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
(0, mobx_1.intercept)(instance, this.willChange);
|
|
55
|
+
(0, mobx_1.observe)(instance, this.didChange);
|
|
56
|
+
}
|
|
57
|
+
describe() {
|
|
58
|
+
return this.name;
|
|
59
|
+
}
|
|
60
|
+
getChildren(node) {
|
|
61
|
+
return node.storedValue.slice();
|
|
62
|
+
}
|
|
63
|
+
getChildNode(node, key) {
|
|
64
|
+
const index = Number(key);
|
|
65
|
+
if (index < node.storedValue.length) {
|
|
66
|
+
return node.storedValue[index];
|
|
67
|
+
}
|
|
68
|
+
throw (0, internal_ts_1.fail)("Not a child: " + key);
|
|
69
|
+
}
|
|
70
|
+
willChange(change) {
|
|
71
|
+
const node = (0, internal_ts_1.getStateTreeNode)(change.object);
|
|
72
|
+
node.assertWritable({ subpath: "" + change.index });
|
|
73
|
+
const subType = node.type._subType;
|
|
74
|
+
const childNodes = node.getChildren();
|
|
75
|
+
switch (change.type) {
|
|
76
|
+
case "update":
|
|
77
|
+
{
|
|
78
|
+
if (change.newValue === change.object[change.index]) {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
const updatedNodes = reconcileArrayChildren(node, subType, [childNodes[change.index]], [change.newValue], [change.index]);
|
|
82
|
+
if (!updatedNodes) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
change.newValue = updatedNodes[0];
|
|
86
|
+
}
|
|
87
|
+
break;
|
|
88
|
+
case "splice":
|
|
89
|
+
{
|
|
90
|
+
const { index, removedCount, added } = change;
|
|
91
|
+
const addedNodes = reconcileArrayChildren(node, subType, childNodes.slice(index, index + removedCount), added, added.map((_, i) => index + i));
|
|
92
|
+
if (!addedNodes) {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
change.added = addedNodes;
|
|
96
|
+
// update paths of remaining items
|
|
97
|
+
for (let i = index + removedCount; i < childNodes.length; i++) {
|
|
98
|
+
childNodes[i].setParent(node, "" + (i + added.length - removedCount));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
return change;
|
|
104
|
+
}
|
|
105
|
+
getSnapshot(node) {
|
|
106
|
+
return node.getChildren().map(childNode => childNode.snapshot);
|
|
107
|
+
}
|
|
108
|
+
processInitialSnapshot(childNodes) {
|
|
109
|
+
const processed = [];
|
|
110
|
+
Object.keys(childNodes).forEach(key => {
|
|
111
|
+
processed.push(childNodes[key].getSnapshot());
|
|
112
|
+
});
|
|
113
|
+
return processed;
|
|
114
|
+
}
|
|
115
|
+
didChange(change) {
|
|
116
|
+
const node = (0, internal_ts_1.getStateTreeNode)(change.object);
|
|
117
|
+
switch (change.type) {
|
|
118
|
+
case "update":
|
|
119
|
+
return void node.emitPatch({
|
|
120
|
+
op: "replace",
|
|
121
|
+
path: "" + change.index,
|
|
122
|
+
value: change.newValue.snapshot,
|
|
123
|
+
oldValue: change.oldValue ? change.oldValue.snapshot : undefined
|
|
124
|
+
}, node);
|
|
125
|
+
case "splice":
|
|
126
|
+
for (let i = change.removedCount - 1; i >= 0; i--) {
|
|
127
|
+
node.emitPatch({
|
|
128
|
+
op: "remove",
|
|
129
|
+
path: "" + (change.index + i),
|
|
130
|
+
oldValue: change.removed[i].snapshot
|
|
131
|
+
}, node);
|
|
132
|
+
}
|
|
133
|
+
for (let i = 0; i < change.addedCount; i++) {
|
|
134
|
+
node.emitPatch({
|
|
135
|
+
op: "add",
|
|
136
|
+
path: "" + (change.index + i),
|
|
137
|
+
value: node.getChildNode("" + (change.index + i)).snapshot,
|
|
138
|
+
oldValue: undefined
|
|
139
|
+
}, node);
|
|
140
|
+
}
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
applyPatchLocally(node, subpath, patch) {
|
|
145
|
+
const target = node.storedValue;
|
|
146
|
+
const index = subpath === "-" ? target.length : Number(subpath);
|
|
147
|
+
switch (patch.op) {
|
|
148
|
+
case "replace":
|
|
149
|
+
target[index] = patch.value;
|
|
150
|
+
break;
|
|
151
|
+
case "add":
|
|
152
|
+
target.splice(index, 0, patch.value);
|
|
153
|
+
break;
|
|
154
|
+
case "remove":
|
|
155
|
+
target.splice(index, 1);
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
applySnapshot(node, snapshot) {
|
|
160
|
+
(0, internal_ts_1.typecheckInternal)(this, snapshot);
|
|
161
|
+
const target = node.storedValue;
|
|
162
|
+
target.replace(snapshot);
|
|
163
|
+
}
|
|
164
|
+
getChildType() {
|
|
165
|
+
return this._subType;
|
|
166
|
+
}
|
|
167
|
+
isValidSnapshot(value, context) {
|
|
168
|
+
if (!(0, internal_ts_1.isArray)(value)) {
|
|
169
|
+
return (0, internal_ts_1.typeCheckFailure)(context, value, "Value is not an array");
|
|
170
|
+
}
|
|
171
|
+
for (let i = 0; i < value.length; i++) {
|
|
172
|
+
(0, internal_ts_1.getContextForPath)(context, "" + i, this._subType);
|
|
173
|
+
const errors = this._subType.validate(value[i], context);
|
|
174
|
+
(0, internal_ts_1.popContext)(context);
|
|
175
|
+
if (errors.length > 0) {
|
|
176
|
+
return errors;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return (0, internal_ts_1.typeCheckSuccess)();
|
|
180
|
+
}
|
|
181
|
+
getDefaultSnapshot() {
|
|
182
|
+
return internal_ts_1.EMPTY_ARRAY;
|
|
183
|
+
}
|
|
184
|
+
removeChild(node, subpath) {
|
|
185
|
+
node.storedValue.splice(Number(subpath), 1);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
exports.ArrayType = ArrayType;
|
|
189
|
+
ArrayType.prototype.applySnapshot = (0, mobx_1.action)(ArrayType.prototype.applySnapshot);
|
|
190
|
+
/**
|
|
191
|
+
* `types.array` - Creates an index based collection type who's children are all of a uniform declared type.
|
|
192
|
+
*
|
|
193
|
+
* This type will always produce [observable arrays](https://mobx.js.org/api.html#observablearray)
|
|
194
|
+
*
|
|
195
|
+
* Example:
|
|
196
|
+
* ```ts
|
|
197
|
+
* const Todo = types.model({
|
|
198
|
+
* task: types.string
|
|
199
|
+
* })
|
|
200
|
+
*
|
|
201
|
+
* const TodoStore = types.model({
|
|
202
|
+
* todos: types.array(Todo)
|
|
203
|
+
* })
|
|
204
|
+
*
|
|
205
|
+
* const s = TodoStore.create({ todos: [] })
|
|
206
|
+
* unprotect(s) // needed to allow modifying outside of an action
|
|
207
|
+
* s.todos.push({ task: "Grab coffee" })
|
|
208
|
+
* console.log(s.todos[0]) // prints: "Grab coffee"
|
|
209
|
+
* ```
|
|
210
|
+
*
|
|
211
|
+
* @param subtype
|
|
212
|
+
* @returns
|
|
213
|
+
*/
|
|
214
|
+
function array(subtype) {
|
|
215
|
+
(0, internal_ts_1.assertIsType)(subtype, 1);
|
|
216
|
+
return new ArrayType(`${subtype.name}[]`, subtype);
|
|
217
|
+
}
|
|
218
|
+
function reconcileArrayChildren(parent, childType, oldNodes, newValues, newPaths) {
|
|
219
|
+
let nothingChanged = true;
|
|
220
|
+
for (let i = 0;; i++) {
|
|
221
|
+
const hasNewNode = i <= newValues.length - 1;
|
|
222
|
+
const oldNode = oldNodes[i];
|
|
223
|
+
let newValue = hasNewNode ? newValues[i] : undefined;
|
|
224
|
+
const newPath = "" + newPaths[i];
|
|
225
|
+
// for some reason, instead of newValue we got a node, fallback to the storedValue
|
|
226
|
+
// TODO: https://github.com/mobxjs/mobx-state-tree/issues/340#issuecomment-325581681
|
|
227
|
+
if ((0, internal_ts_1.isNode)(newValue)) {
|
|
228
|
+
newValue = newValue.storedValue;
|
|
229
|
+
}
|
|
230
|
+
if (!oldNode && !hasNewNode) {
|
|
231
|
+
// both are empty, end
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
else if (!hasNewNode) {
|
|
235
|
+
// new one does not exists
|
|
236
|
+
nothingChanged = false;
|
|
237
|
+
oldNodes.splice(i, 1);
|
|
238
|
+
if (oldNode instanceof internal_ts_1.ObjectNode) {
|
|
239
|
+
// since it is going to be returned by pop/splice/shift better create it before killing it
|
|
240
|
+
// so it doesn't end up in an undead state
|
|
241
|
+
oldNode.createObservableInstanceIfNeeded();
|
|
242
|
+
}
|
|
243
|
+
oldNode.die();
|
|
244
|
+
i--;
|
|
245
|
+
}
|
|
246
|
+
else if (!oldNode) {
|
|
247
|
+
// there is no old node, create it
|
|
248
|
+
// check if already belongs to the same parent. if so, avoid pushing item in. only swapping can occur.
|
|
249
|
+
if ((0, internal_ts_1.isStateTreeNode)(newValue) &&
|
|
250
|
+
(0, internal_ts_1.getStateTreeNode)(newValue).parent === parent) {
|
|
251
|
+
// this node is owned by this parent, but not in the reconcilable set, so it must be double
|
|
252
|
+
throw (0, internal_ts_1.fail)(`Cannot add an object to a state tree if it is already part of the same or another state tree. Tried to assign an object to '${parent.path}/${newPath}', but it lives already at '${(0, internal_ts_1.getStateTreeNode)(newValue).path}'`);
|
|
253
|
+
}
|
|
254
|
+
nothingChanged = false;
|
|
255
|
+
const newNode = valueAsNode(childType, parent, newPath, newValue);
|
|
256
|
+
oldNodes.splice(i, 0, newNode);
|
|
257
|
+
}
|
|
258
|
+
else if (areSame(oldNode, newValue)) {
|
|
259
|
+
// both are the same, reconcile
|
|
260
|
+
oldNodes[i] = valueAsNode(childType, parent, newPath, newValue, oldNode);
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
// nothing to do, try to reorder
|
|
264
|
+
let oldMatch = undefined;
|
|
265
|
+
// find a possible candidate to reuse
|
|
266
|
+
for (let j = i; j < oldNodes.length; j++) {
|
|
267
|
+
if (areSame(oldNodes[j], newValue)) {
|
|
268
|
+
oldMatch = oldNodes.splice(j, 1)[0];
|
|
269
|
+
break;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
nothingChanged = false;
|
|
273
|
+
const newNode = valueAsNode(childType, parent, newPath, newValue, oldMatch);
|
|
274
|
+
oldNodes.splice(i, 0, newNode);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return nothingChanged ? null : oldNodes;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Convert a value to a node at given parent and subpath. Attempts to reuse old node if possible and given.
|
|
281
|
+
*/
|
|
282
|
+
function valueAsNode(childType, parent, subpath, newValue, oldNode) {
|
|
283
|
+
// ensure the value is valid-ish
|
|
284
|
+
(0, internal_ts_1.typecheckInternal)(childType, newValue);
|
|
285
|
+
function getNewNode() {
|
|
286
|
+
// the new value has a MST node
|
|
287
|
+
if ((0, internal_ts_1.isStateTreeNode)(newValue)) {
|
|
288
|
+
const childNode = (0, internal_ts_1.getStateTreeNode)(newValue);
|
|
289
|
+
childNode.assertAlive(internal_ts_1.EMPTY_OBJECT);
|
|
290
|
+
// the node lives here
|
|
291
|
+
if (childNode.parent !== null && childNode.parent === parent) {
|
|
292
|
+
childNode.setParent(parent, subpath);
|
|
293
|
+
return childNode;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
// there is old node and new one is a value/snapshot
|
|
297
|
+
if (oldNode) {
|
|
298
|
+
return childType.reconcile(oldNode, newValue, parent, subpath);
|
|
299
|
+
}
|
|
300
|
+
// nothing to do, create from scratch
|
|
301
|
+
return childType.instantiate(parent, subpath, undefined, newValue);
|
|
302
|
+
}
|
|
303
|
+
const newNode = getNewNode();
|
|
304
|
+
if (oldNode && oldNode !== newNode) {
|
|
305
|
+
if (oldNode instanceof internal_ts_1.ObjectNode) {
|
|
306
|
+
// since it is going to be returned by pop/splice/shift better create it before killing it
|
|
307
|
+
// so it doesn't end up in an undead state
|
|
308
|
+
oldNode.createObservableInstanceIfNeeded();
|
|
309
|
+
}
|
|
310
|
+
oldNode.die();
|
|
311
|
+
}
|
|
312
|
+
return newNode;
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Check if a node holds a value.
|
|
316
|
+
*/
|
|
317
|
+
function areSame(oldNode, newValue) {
|
|
318
|
+
// never consider dead old nodes for reconciliation
|
|
319
|
+
if (!oldNode.isAlive) {
|
|
320
|
+
return false;
|
|
321
|
+
}
|
|
322
|
+
// the new value has the same node
|
|
323
|
+
if ((0, internal_ts_1.isStateTreeNode)(newValue)) {
|
|
324
|
+
const newNode = (0, internal_ts_1.getStateTreeNode)(newValue);
|
|
325
|
+
return newNode.isAlive && newNode === oldNode;
|
|
326
|
+
}
|
|
327
|
+
// the provided value is the snapshot of the old node
|
|
328
|
+
if (oldNode.snapshot === newValue) {
|
|
329
|
+
return true;
|
|
330
|
+
}
|
|
331
|
+
// Non object nodes don't get reconciled
|
|
332
|
+
if (!(oldNode instanceof internal_ts_1.ObjectNode)) {
|
|
333
|
+
return false;
|
|
334
|
+
}
|
|
335
|
+
const oldNodeType = oldNode.getReconciliationType();
|
|
336
|
+
// new value is a snapshot with the correct identifier
|
|
337
|
+
return (oldNode.identifier !== null &&
|
|
338
|
+
oldNode.identifierAttribute &&
|
|
339
|
+
(0, internal_ts_1.isPlainObject)(newValue) &&
|
|
340
|
+
oldNodeType.is(newValue) &&
|
|
341
|
+
oldNodeType.isMatchingSnapshotId(oldNode, newValue));
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Returns if a given value represents an array type.
|
|
345
|
+
*
|
|
346
|
+
* @param type
|
|
347
|
+
* @returns `true` if the type is an array type.
|
|
348
|
+
*/
|
|
349
|
+
function isArrayType(type) {
|
|
350
|
+
return (0, internal_ts_1.isType)(type) && (type.flags & internal_ts_1.TypeFlags.Array) > 0;
|
|
351
|
+
}
|
|
352
|
+
//# sourceMappingURL=array.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array.js","sourceRoot":"","sources":["../../../src/types/complex-types/array.ts"],"names":[],"mappings":";;;AA4XA,sBAGC;AA4KD,kCAIC;AA/iBD,+BAWa;AAEb,mDAsC0B;AA2C1B;;;GAGG;AACH,MAAa,SAA+B,SAAQ,yBAInD;IAKoB;IAJV,KAAK,GAAG,uBAAS,CAAC,KAAK,CAAA;IACf,gBAAgB,GAAuC,EAAE,CAAA;IAC1E,YACE,IAAY,EACK,QAAY,EAC7B,mBAAuD,EAAE;QAEzD,KAAK,CAAC,IAAI,CAAC,CAAA;QAHM,aAAQ,GAAR,QAAQ,CAAI;QAI7B,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAA;IAC1C,CAAC;IAED,KAAK,CAAC,KAAkC;QACtC,MAAM,gBAAgB,GACpB,IAAI,CAAC,gBAAgB,CAAC,MAAM,GAAG,CAAC;YAC9B,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,KAAK,CAAC;YACrC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAA;QACb,OAAO,IAAI,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAA;IAClE,CAAC;IAED,WAAW,CACT,MAA4B,EAC5B,OAAe,EACf,WAAgB,EAChB,YAAmC;QAEnC,OAAO,IAAA,8BAAgB,EAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,YAAY,CAAC,CAAA;IAC3E,CAAC;IAED,oBAAoB,CAClB,OAAkB,EAClB,WAAsB,EAAE;QAExB,MAAM,OAAO,GAAI,OAAO,CAAC,IAAa,CAAC,QAAQ,CAAA;QAC/C,MAAM,MAAM,GAAmB,EAAE,CAAA;QACjC,QAAQ,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,KAAK,EA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AAC;IAED,kCAAkC;IAClC,IAAI,IAAA,6BAAe,EAAC,QAAQ,CAAC,EAAE,CAAC;QAC9B,MAAM,OAAO,GAAG,IAAA,8BAAgB,EAAC,QAAQ,CAAC,CAAA;QAC1C,OAAO,OAAO,CAAC,OAAO,IAAI,OAAO,KAAK,OAAO,CAAA;IAC/C,CAAC;IAED,qDAAqD;IACrD,IAAI,OAAO,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAClC,OAAO,IAAI,CAAA;IACb,CAAC;IAED,wCAAwC;IACxC,IAAI,CAAC,CAAC,OAAO,YAAY,wBAAU,CAAC,EAAE,CAAC;QACrC,OAAO,KAAK,CAAA;IACd,CAAC;IAED,MAAM,WAAW,GAAG,OAAO,CAAC,qBAAqB,EAAE,CAAA;IACnD,sDAAsD;IACtD,OAAO,CACL,OAAO,CAAC,UAAU,KAAK,IAAI;QAC3B,OAAO,CAAC,mBAAmB;QAC3B,IAAA,2BAAa,EAAC,QAAQ,CAAC;QACvB,WAAW,CAAC,EAAE,CAAC,QAAQ,CAAC;QACvB,WAAmB,CAAC,oBAAoB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAC7D,CAAA;AACH,CAAC;AAED;;;;;GAKG;AACH,SAAgB,WAAW,CACzB,IAAc;IAEd,OAAO,IAAA,oBAAM,EAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,GAAG,uBAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;AAC3D,CAAC"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { type IInterceptor, type IKeyValueMap, type IMapDidChange, type IMapWillChange, type Lambda, ObservableMap } from "mobx";
|
|
2
|
+
import { type AnyNode, type AnyObjectNode, ComplexType, type ExtractCSTWithSTN, type IAnyType, type IChildNodesMap, type IHooksGetter, type IJsonPatch, type IType, type IValidationContext, type IValidationResult, TypeFlags } from "../../internal.ts";
|
|
3
|
+
/** @hidden */
|
|
4
|
+
export interface IMapType<IT extends IAnyType> extends IType<IKeyValueMap<IT["CreationType"]> | undefined, IKeyValueMap<IT["SnapshotType"]>, IMSTMap<IT>> {
|
|
5
|
+
hooks(hooks: IHooksGetter<IMSTMap<IT>>): IMapType<IT>;
|
|
6
|
+
}
|
|
7
|
+
/** @hidden */
|
|
8
|
+
export interface IMSTMap<IT extends IAnyType> {
|
|
9
|
+
clear(): void;
|
|
10
|
+
delete(key: string): boolean;
|
|
11
|
+
forEach(callbackfn: (value: IT["Type"], key: string | number, map: this) => void, thisArg?: any): void;
|
|
12
|
+
get(key: string | number): IT["Type"] | undefined;
|
|
13
|
+
has(key: string | number): boolean;
|
|
14
|
+
set(key: string | number, value: ExtractCSTWithSTN<IT>): this;
|
|
15
|
+
readonly size: number;
|
|
16
|
+
put(value: ExtractCSTWithSTN<IT>): IT["Type"];
|
|
17
|
+
keys(): IterableIterator<string>;
|
|
18
|
+
values(): IterableIterator<IT["Type"]>;
|
|
19
|
+
entries(): IterableIterator<[string, IT["Type"]]>;
|
|
20
|
+
[Symbol.iterator](): IterableIterator<[string, IT["Type"]]>;
|
|
21
|
+
/** Merge another object into this map, returns self. */
|
|
22
|
+
merge(other: IMSTMap<IType<any, any, IT["TypeWithoutSTN"]>> | IKeyValueMap<ExtractCSTWithSTN<IT>> | any): this;
|
|
23
|
+
replace(values: IMSTMap<IType<any, any, IT["TypeWithoutSTN"]>> | IKeyValueMap<ExtractCSTWithSTN<IT>> | any): this;
|
|
24
|
+
toJSON(): IKeyValueMap<IT["SnapshotType"]>;
|
|
25
|
+
toString(): string;
|
|
26
|
+
[Symbol.toStringTag]: "Map";
|
|
27
|
+
/**
|
|
28
|
+
* Observes this object. Triggers for the events 'add', 'update' and 'delete'.
|
|
29
|
+
* See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/observe
|
|
30
|
+
* for callback details
|
|
31
|
+
*/
|
|
32
|
+
observe(listener: (changes: IMapDidChange<string, IT["Type"]>) => void, fireImmediately?: boolean): Lambda;
|
|
33
|
+
intercept(handler: IInterceptor<IMapWillChange<string, IT["Type"]>>): Lambda;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* @internal
|
|
37
|
+
* @hidden
|
|
38
|
+
*/
|
|
39
|
+
export declare enum MapIdentifierMode {
|
|
40
|
+
UNKNOWN = 0,
|
|
41
|
+
YES = 1,
|
|
42
|
+
NO = 2
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* @internal
|
|
46
|
+
* @hidden
|
|
47
|
+
*/
|
|
48
|
+
export declare class MapType<IT extends IAnyType> extends ComplexType<IKeyValueMap<IT["CreationType"]> | undefined, IKeyValueMap<IT["SnapshotType"]>, IMSTMap<IT>> {
|
|
49
|
+
private readonly _subType;
|
|
50
|
+
identifierMode: MapIdentifierMode;
|
|
51
|
+
mapIdentifierAttribute: string | undefined;
|
|
52
|
+
readonly flags = TypeFlags.Map;
|
|
53
|
+
private readonly hookInitializers;
|
|
54
|
+
constructor(name: string, _subType: IAnyType, hookInitializers?: Array<IHooksGetter<IMSTMap<IT>>>);
|
|
55
|
+
hooks(hooks: IHooksGetter<IMSTMap<IT>>): MapType<IT>;
|
|
56
|
+
instantiate(parent: AnyObjectNode | null, subpath: string, environment: any, initialValue: this["C"] | this["T"]): this["N"];
|
|
57
|
+
private _determineIdentifierMode;
|
|
58
|
+
initializeChildNodes(objNode: this["N"], initialSnapshot?: this["C"]): IChildNodesMap;
|
|
59
|
+
createNewInstance(childNodes: IChildNodesMap): this["T"];
|
|
60
|
+
finalizeNewInstance(node: this["N"], instance: ObservableMap<string, any>): void;
|
|
61
|
+
describe(): string;
|
|
62
|
+
getChildren(node: this["N"]): ReadonlyArray<AnyNode>;
|
|
63
|
+
getChildNode(node: this["N"], key: string): AnyNode;
|
|
64
|
+
willChange(change: IMapWillChange<string, AnyNode>): IMapWillChange<string, AnyNode> | null;
|
|
65
|
+
private processIdentifier;
|
|
66
|
+
getSnapshot(node: this["N"]): this["S"];
|
|
67
|
+
processInitialSnapshot(childNodes: IChildNodesMap): this["S"];
|
|
68
|
+
didChange(change: IMapDidChange<string, AnyNode>): void;
|
|
69
|
+
applyPatchLocally(node: this["N"], subpath: string, patch: IJsonPatch): void;
|
|
70
|
+
applySnapshot(node: this["N"], snapshot: this["C"]): void;
|
|
71
|
+
getChildType(): IAnyType;
|
|
72
|
+
isValidSnapshot(value: this["C"], context: IValidationContext): IValidationResult;
|
|
73
|
+
getDefaultSnapshot(): this["C"];
|
|
74
|
+
removeChild(node: this["N"], subpath: string): void;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* `types.map` - Creates a key based collection type who's children are all of a uniform declared type.
|
|
78
|
+
* If the type stored in a map has an identifier, it is mandatory to store the child under that identifier in the map.
|
|
79
|
+
*
|
|
80
|
+
* This type will always produce [observable maps](https://mobx.js.org/api.html#observablemap)
|
|
81
|
+
*
|
|
82
|
+
* Example:
|
|
83
|
+
* ```ts
|
|
84
|
+
* const Todo = types.model({
|
|
85
|
+
* id: types.identifier,
|
|
86
|
+
* task: types.string
|
|
87
|
+
* })
|
|
88
|
+
*
|
|
89
|
+
* const TodoStore = types.model({
|
|
90
|
+
* todos: types.map(Todo)
|
|
91
|
+
* })
|
|
92
|
+
*
|
|
93
|
+
* const s = TodoStore.create({ todos: {} })
|
|
94
|
+
* unprotect(s)
|
|
95
|
+
* s.todos.set(17, { task: "Grab coffee", id: 17 })
|
|
96
|
+
* s.todos.put({ task: "Grab cookie", id: 18 }) // put will infer key from the identifier
|
|
97
|
+
* console.log(s.todos.get(17).task) // prints: "Grab coffee"
|
|
98
|
+
* ```
|
|
99
|
+
*
|
|
100
|
+
* @param subtype
|
|
101
|
+
* @returns
|
|
102
|
+
*/
|
|
103
|
+
export declare function map<IT extends IAnyType>(subtype: IT): IMapType<IT>;
|
|
104
|
+
/**
|
|
105
|
+
* Returns if a given value represents a map type.
|
|
106
|
+
*
|
|
107
|
+
* @param type
|
|
108
|
+
* @returns `true` if it is a map type.
|
|
109
|
+
*/
|
|
110
|
+
export declare function isMapType<Items extends IAnyType = IAnyType>(type: IAnyType): type is IMapType<Items>;
|