@amodx/ncs 0.0.24 → 0.0.27
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/Components/Component.types.d.ts +2 -1
- package/Components/ComponentArray.d.ts +4 -2
- package/Components/ComponentArray.js +15 -15
- package/Components/ComponentCursor.d.ts +8 -3
- package/Components/ComponentCursor.js +27 -9
- package/Contexts/ContextArray.d.ts +1 -1
- package/Contexts/ContextArray.js +6 -2
- package/Contexts/ContextCursor.d.ts +2 -1
- package/Contexts/ContextCursor.js +9 -1
- package/Data/serializeComponent.js +1 -1
- package/Data/serializeNode.js +4 -0
- package/Functional.d.ts +3 -3
- package/Functional.js +3 -3
- package/Graphs/Graph.d.ts +2 -1
- package/Graphs/Graph.js +14 -11
- package/Graphs/GraphClock.d.ts +8 -0
- package/Graphs/GraphClock.js +18 -0
- package/NCS.d.ts +10 -1
- package/Nodes/Node.types.d.ts +2 -2
- package/Nodes/NodeArray.d.ts +1 -0
- package/Nodes/NodeArray.js +6 -3
- package/Nodes/NodeComponents.d.ts +3 -3
- package/Nodes/NodeComponents.js +34 -13
- package/Nodes/NodeContext.js +6 -6
- package/Nodes/NodeCursor.d.ts +1 -1
- package/Nodes/NodeCursor.js +22 -11
- package/Nodes/NodeTags.js +2 -0
- package/Register/registerComponent.d.ts +12 -2
- package/Register/registerComponent.js +71 -14
- package/Schema/Functions/createSchemaBinaryObjectCursorClass.js +4 -4
- package/Schema/Functions/createSchemaObjectCursorClass.js +4 -4
- package/Schema/Functions/createSchemaTypedArrayCursorClass.js +4 -4
- package/Schema/Schema.js +6 -8
- package/Schema/SchemaArrayCursor.d.ts +1 -2
- package/Schema/SchemaArrayCursor.js +2 -6
- package/Schema/SchemaView.d.ts +3 -0
- package/Schema/SchemaView.js +16 -14
- package/Systems/System.types.d.ts +2 -1
- package/Systems/SystemInstance.d.ts +2 -1
- package/Systems/SystemInstance.js +2 -2
- package/Tags/Tag.js +1 -1
- package/Tags/TagArray.js +1 -1
- package/Util/ItemPool.js +1 -1
- package/package.json +1 -1
package/Nodes/NodeComponents.js
CHANGED
|
@@ -24,7 +24,7 @@ export class NodeComponents {
|
|
|
24
24
|
const components = this.components;
|
|
25
25
|
const tempCursor = ComponentCursor.Get();
|
|
26
26
|
for (let i = 0; i < components.length; i += 2) {
|
|
27
|
-
tempCursor.setInstance(this.node, components[i], components[i + 1]);
|
|
27
|
+
tempCursor.setInstance(this.node.index, this.node.graph, components[i], components[i + 1]);
|
|
28
28
|
tempCursor.dispose();
|
|
29
29
|
}
|
|
30
30
|
tempCursor.returnCursor();
|
|
@@ -66,7 +66,7 @@ export class NodeComponents {
|
|
|
66
66
|
compArray.observers.nodeAdded.notify(this.node.index);
|
|
67
67
|
const temp = ComponentCursor.Get();
|
|
68
68
|
if (this.node.hasObservers) {
|
|
69
|
-
temp.setInstance(this.node, typeId, componentIndex);
|
|
69
|
+
temp.setInstance(this.node.index, this.node.graph, typeId, componentIndex);
|
|
70
70
|
this.node.observers.isComponentAddedSet &&
|
|
71
71
|
this.node.observers.componentAdded.notify(temp);
|
|
72
72
|
this.node.observers.isComponentsUpdatedSet &&
|
|
@@ -92,7 +92,7 @@ export class NodeComponents {
|
|
|
92
92
|
if (removeIndex == -1)
|
|
93
93
|
return;
|
|
94
94
|
const temp = ComponentCursor.Get();
|
|
95
|
-
temp.setInstance(this.node, numberId, removeComponentIndex);
|
|
95
|
+
temp.setInstance(this.node.index, this.node.graph, numberId, removeComponentIndex);
|
|
96
96
|
this.components.splice(removeIndex, 2);
|
|
97
97
|
if (this.node.hasObservers) {
|
|
98
98
|
this.node.observers.isComponentRemovedSet &&
|
|
@@ -116,18 +116,24 @@ export class NodeComponents {
|
|
|
116
116
|
}
|
|
117
117
|
return false;
|
|
118
118
|
}
|
|
119
|
-
get(type, cursor =
|
|
119
|
+
get(type, cursor = null) {
|
|
120
120
|
const components = this.components;
|
|
121
121
|
if (!components)
|
|
122
122
|
return null;
|
|
123
|
+
let usedTemp = false;
|
|
124
|
+
if (!cursor) {
|
|
125
|
+
cursor = ComponentCursor.Get();
|
|
126
|
+
usedTemp = true;
|
|
127
|
+
}
|
|
123
128
|
const numberId = NCSRegister.components.idPalette.getNumberId(type);
|
|
124
129
|
for (let i = 0; i < components.length; i += 2) {
|
|
125
130
|
if (components[i] == numberId) {
|
|
126
|
-
|
|
127
|
-
cursor.setInstance(nodeCursor, numberId, components[i + 1]);
|
|
131
|
+
cursor.setInstance(this.node.index, this.node.graph, numberId, components[i + 1]);
|
|
128
132
|
return cursor;
|
|
129
133
|
}
|
|
130
134
|
}
|
|
135
|
+
if (usedTemp)
|
|
136
|
+
cursor.returnCursor();
|
|
131
137
|
return null;
|
|
132
138
|
}
|
|
133
139
|
getAll(type) {
|
|
@@ -139,7 +145,7 @@ export class NodeComponents {
|
|
|
139
145
|
for (let i = 0; i < components.length; i += 2) {
|
|
140
146
|
if (components[i] == numberId) {
|
|
141
147
|
const cursor = ComponentCursor.Get();
|
|
142
|
-
cursor.setInstance(this.node, components[i], components[i + 1]);
|
|
148
|
+
cursor.setInstance(this.node.index, this.node.graph, components[i], components[i + 1]);
|
|
143
149
|
cursors.push(cursor);
|
|
144
150
|
}
|
|
145
151
|
}
|
|
@@ -153,7 +159,7 @@ export class NodeComponents {
|
|
|
153
159
|
const tempCursor = ComponentCursor.Get();
|
|
154
160
|
for (let i = components.length; i > 0; i -= 2) {
|
|
155
161
|
if (components[i] == numberId) {
|
|
156
|
-
tempCursor.setInstance(this.node, components[i], components[i + 1]);
|
|
162
|
+
tempCursor.setInstance(this.node.index, this.node.graph, components[i], components[i + 1]);
|
|
157
163
|
this.components.splice(i, 2);
|
|
158
164
|
if (this.node.hasObservers) {
|
|
159
165
|
this.node.observers.isComponentRemovedSet &&
|
|
@@ -166,32 +172,47 @@ export class NodeComponents {
|
|
|
166
172
|
tempCursor.returnCursor();
|
|
167
173
|
return true;
|
|
168
174
|
}
|
|
169
|
-
getChild(type, cursor =
|
|
175
|
+
getChild(type, cursor = null) {
|
|
176
|
+
let usedTemp = false;
|
|
177
|
+
if (!cursor) {
|
|
178
|
+
cursor = ComponentCursor.Get();
|
|
179
|
+
usedTemp = true;
|
|
180
|
+
}
|
|
170
181
|
const tempCursor = NodeCursor.Get();
|
|
171
182
|
for (const child of this.node.traverseChildren(tempCursor)) {
|
|
172
183
|
if (!child.components)
|
|
173
184
|
continue;
|
|
174
|
-
|
|
175
|
-
const found = child.components.get(type, cursor, nodeCursor);
|
|
185
|
+
const found = child.components.get(type, cursor);
|
|
176
186
|
if (found) {
|
|
177
187
|
tempCursor.returnCursor();
|
|
178
188
|
return found;
|
|
179
189
|
}
|
|
180
190
|
}
|
|
191
|
+
if (usedTemp) {
|
|
192
|
+
cursor.returnCursor();
|
|
193
|
+
}
|
|
181
194
|
tempCursor.returnCursor();
|
|
182
195
|
return null;
|
|
183
196
|
}
|
|
184
|
-
getParent(type, cursor =
|
|
197
|
+
getParent(type, cursor = null) {
|
|
198
|
+
let usedTemp = false;
|
|
199
|
+
if (!cursor) {
|
|
200
|
+
cursor = ComponentCursor.Get();
|
|
201
|
+
usedTemp = true;
|
|
202
|
+
}
|
|
185
203
|
const tempCursor = NodeCursor.Get();
|
|
186
204
|
for (const parent of this.node.traverseParents(tempCursor)) {
|
|
187
205
|
if (!parent.components)
|
|
188
206
|
continue;
|
|
189
|
-
const found = parent.components.get(type, cursor
|
|
207
|
+
const found = parent.components.get(type, cursor);
|
|
190
208
|
if (found) {
|
|
191
209
|
tempCursor.returnCursor();
|
|
192
210
|
return found;
|
|
193
211
|
}
|
|
194
212
|
}
|
|
213
|
+
if (usedTemp) {
|
|
214
|
+
cursor.returnCursor();
|
|
215
|
+
}
|
|
195
216
|
tempCursor.returnCursor();
|
|
196
217
|
return null;
|
|
197
218
|
}
|
package/Nodes/NodeContext.js
CHANGED
|
@@ -26,7 +26,7 @@ export class NodeContext {
|
|
|
26
26
|
defaultCursor.setContext(this.node, context[i]);
|
|
27
27
|
defaultCursor.dispose();
|
|
28
28
|
}
|
|
29
|
-
|
|
29
|
+
defaultCursor.returnCursor();
|
|
30
30
|
}
|
|
31
31
|
add(contextData) {
|
|
32
32
|
const cursor = ContextCursor.Get();
|
|
@@ -54,7 +54,7 @@ export class NodeContext {
|
|
|
54
54
|
contextData[2] = null;
|
|
55
55
|
contextData[3] = null;
|
|
56
56
|
NCSPools.createContextData.addItem(contextData);
|
|
57
|
-
|
|
57
|
+
cursor.returnCursor();
|
|
58
58
|
return newContext;
|
|
59
59
|
}
|
|
60
60
|
remove(type) {
|
|
@@ -70,11 +70,11 @@ export class NodeContext {
|
|
|
70
70
|
break;
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
|
-
|
|
73
|
+
cursor.returnCursor();
|
|
74
74
|
return true;
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
|
-
|
|
77
|
+
cursor.returnCursor();
|
|
78
78
|
return false;
|
|
79
79
|
}
|
|
80
80
|
get(type) {
|
|
@@ -94,14 +94,14 @@ export class NodeContext {
|
|
|
94
94
|
for (let i = 0; i < context.length; i++) {
|
|
95
95
|
cursor.setContext(parent, context[i]);
|
|
96
96
|
if (cursor.type == type) {
|
|
97
|
-
//@todo add anchor
|
|
98
97
|
cursor.setContext(parent, context[i]);
|
|
99
98
|
return cursor;
|
|
100
99
|
}
|
|
101
100
|
}
|
|
102
101
|
}
|
|
103
102
|
}
|
|
104
|
-
|
|
103
|
+
parentCursor.returnCursor();
|
|
104
|
+
cursor.returnCursor();
|
|
105
105
|
return null;
|
|
106
106
|
}
|
|
107
107
|
}
|
package/Nodes/NodeCursor.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export interface NodeCursor {
|
|
|
10
10
|
}
|
|
11
11
|
export declare class NodeCursor {
|
|
12
12
|
static Get(): NodeCursor;
|
|
13
|
-
static
|
|
13
|
+
static Return(cursor: NodeCursor): void;
|
|
14
14
|
clear(events: boolean, context: boolean, observers: boolean, compoents: boolean, tags: boolean): void;
|
|
15
15
|
get index(): number;
|
|
16
16
|
get id(): bigint | null;
|
package/Nodes/NodeCursor.js
CHANGED
|
@@ -14,7 +14,7 @@ export class NodeCursor {
|
|
|
14
14
|
return new NodeCursor();
|
|
15
15
|
return cursor;
|
|
16
16
|
}
|
|
17
|
-
static
|
|
17
|
+
static Return(cursor) {
|
|
18
18
|
if (cursor.index !== -1) {
|
|
19
19
|
cursor.clear(cursor.hasEvents, cursor.hasContexts, cursor.hasObservers, cursor.hasComponents, cursor.hasTags);
|
|
20
20
|
}
|
|
@@ -175,7 +175,9 @@ export class NodeCursor {
|
|
|
175
175
|
if (!array)
|
|
176
176
|
return false;
|
|
177
177
|
const templChildArray = NCSPools.numberArray.get() || [];
|
|
178
|
-
|
|
178
|
+
const length = array.length;
|
|
179
|
+
templChildArray.length = length;
|
|
180
|
+
for (let i = 0; i < length; i++) {
|
|
179
181
|
templChildArray[i] = array[i];
|
|
180
182
|
}
|
|
181
183
|
let usedTemp = false;
|
|
@@ -183,7 +185,7 @@ export class NodeCursor {
|
|
|
183
185
|
usedTemp = true;
|
|
184
186
|
cursor = NodeCursor.Get();
|
|
185
187
|
}
|
|
186
|
-
for (let i = 0; i <
|
|
188
|
+
for (let i = 0; i < length; i++) {
|
|
187
189
|
cursor.setNode(this.graph, templChildArray[i]);
|
|
188
190
|
yield cursor;
|
|
189
191
|
}
|
|
@@ -204,7 +206,7 @@ export class NodeCursor {
|
|
|
204
206
|
cursor = NodeCursor.Get();
|
|
205
207
|
}
|
|
206
208
|
while (children.length) {
|
|
207
|
-
const childrenArray = children.
|
|
209
|
+
const childrenArray = children.pop();
|
|
208
210
|
if (!childrenArray)
|
|
209
211
|
continue;
|
|
210
212
|
for (let i = 0; i < childrenArray.length; i++) {
|
|
@@ -251,7 +253,7 @@ export class NodeCursor {
|
|
|
251
253
|
cursor = ComponentCursor.Get();
|
|
252
254
|
}
|
|
253
255
|
for (let i = 0; i < components.length; i += 2) {
|
|
254
|
-
yield cursor.setInstance(this, components[i], components[i + 1]);
|
|
256
|
+
yield cursor.setInstance(this.index, this.graph, components[i], components[i + 1]);
|
|
255
257
|
}
|
|
256
258
|
if (usedTemp)
|
|
257
259
|
cursor.returnCursor();
|
|
@@ -277,6 +279,7 @@ export class NodeCursor {
|
|
|
277
279
|
dispose() {
|
|
278
280
|
if (this.isDisposed)
|
|
279
281
|
return;
|
|
282
|
+
this.graph._nodes._beingDisposed[this._index] = true;
|
|
280
283
|
this.hasObservers &&
|
|
281
284
|
this.observers.isDisposedSet &&
|
|
282
285
|
this.observers.disposed.notify(this);
|
|
@@ -289,11 +292,13 @@ export class NodeCursor {
|
|
|
289
292
|
if (this.childrenArray) {
|
|
290
293
|
const templChildArray = NCSPools.numberArray.get() || [];
|
|
291
294
|
const children = this.childrenArray;
|
|
292
|
-
|
|
295
|
+
const length = children.length;
|
|
296
|
+
templChildArray.length = length;
|
|
297
|
+
for (let i = 0; i < length; i++) {
|
|
293
298
|
templChildArray[i] = children[i];
|
|
294
299
|
}
|
|
295
300
|
const tempCursor = NodeCursor.Get();
|
|
296
|
-
for (let i = 0; i <
|
|
301
|
+
for (let i = 0; i < length; i++) {
|
|
297
302
|
tempCursor.setNode(this.graph, templChildArray[i]);
|
|
298
303
|
tempCursor.dispose();
|
|
299
304
|
}
|
|
@@ -307,8 +312,13 @@ export class NodeCursor {
|
|
|
307
312
|
tempCursor.removeChild(tempCursor.getChildIndex(this.index));
|
|
308
313
|
tempCursor.returnCursor();
|
|
309
314
|
}
|
|
315
|
+
const hadEvents = this.hasEvents;
|
|
316
|
+
const hadContexts = this.hasContexts;
|
|
317
|
+
const hadObservers = this.hasObservers;
|
|
318
|
+
const hadComponents = this.hasComponents;
|
|
319
|
+
const hadTags = this.hasTags;
|
|
310
320
|
this.graph.removeNode(this.index);
|
|
311
|
-
this.clear(
|
|
321
|
+
this.clear(hadEvents, hadContexts, hadObservers, hadComponents, hadTags);
|
|
312
322
|
}
|
|
313
323
|
hasChild(node) {
|
|
314
324
|
if (!this.childrenArray)
|
|
@@ -333,7 +343,7 @@ export class NodeCursor {
|
|
|
333
343
|
this.parent = nodeToParentTo.index;
|
|
334
344
|
this.hasObservers &&
|
|
335
345
|
this.observers.isParentedSet &&
|
|
336
|
-
|
|
346
|
+
this.observers.parented.notify(tempCursor);
|
|
337
347
|
tempCursor.returnCursor();
|
|
338
348
|
}
|
|
339
349
|
getChild(index, cursor = NodeCursor.Get()) {
|
|
@@ -371,9 +381,10 @@ export class NodeCursor {
|
|
|
371
381
|
return this.childrenArray.length - 1;
|
|
372
382
|
}
|
|
373
383
|
removeChild(index) {
|
|
374
|
-
if (!this.childrenArray ||
|
|
384
|
+
if (!this.childrenArray || this.childrenArray[index] === undefined)
|
|
375
385
|
return;
|
|
376
386
|
const child = this.childrenArray.splice(index, 1)[0];
|
|
387
|
+
this.arrays._parents[child] = -1;
|
|
377
388
|
const tempCursor = NodeCursor.Get();
|
|
378
389
|
tempCursor.setNode(this.graph, child);
|
|
379
390
|
if (this.hasObservers) {
|
|
@@ -400,7 +411,7 @@ export class NodeCursor {
|
|
|
400
411
|
return id;
|
|
401
412
|
}
|
|
402
413
|
returnCursor() {
|
|
403
|
-
return NodeCursor.
|
|
414
|
+
return NodeCursor.Return(this);
|
|
404
415
|
}
|
|
405
416
|
cloneCursor(cursor) {
|
|
406
417
|
const newCursor = cursor || NodeCursor.Get();
|
package/Nodes/NodeTags.js
CHANGED
|
@@ -77,6 +77,8 @@ export class NodeTags {
|
|
|
77
77
|
get(type, cursor = TagCursor.Get()) {
|
|
78
78
|
const tagId = NCSRegister.tags.idPalette.getNumberId(type);
|
|
79
79
|
const tags = this.tags;
|
|
80
|
+
if (!this.tags)
|
|
81
|
+
return null;
|
|
80
82
|
for (let i = 0; i < tags.length; i += 2) {
|
|
81
83
|
if (tags[i] == tagId) {
|
|
82
84
|
cursor.setTag(this.node, tags[i], tags[i + 1]);
|
|
@@ -4,7 +4,8 @@ import { SerializedNodeData, SerializedComponentData } from "../Data/SerializedD
|
|
|
4
4
|
import { ComponentCursor } from "../Components/ComponentCursor";
|
|
5
5
|
import { SchemaCursor } from "../Schema/Schema.types";
|
|
6
6
|
import { NodeCursor } from "../Nodes/NodeCursor";
|
|
7
|
-
import { Nullable } from "Util/Util.types";
|
|
7
|
+
import { Nullable } from "../Util/Util.types";
|
|
8
|
+
import { CreateNodeData } from "../Nodes/Node.types";
|
|
8
9
|
type RegisteredComponent<ComponentSchema extends object = any, Data extends any = any, Shared extends any = any> = (ComponentRegisterData<ComponentSchema, Data, Shared> & {
|
|
9
10
|
getNodes(grpah: Graph): Generator<NodeCursor>;
|
|
10
11
|
getComponents(grpah: Graph): Generator<ComponentCursor<ComponentSchema, Data, Shared>>;
|
|
@@ -19,12 +20,21 @@ type RegisteredComponent<ComponentSchema extends object = any, Data extends any
|
|
|
19
20
|
getAll(node: NodeCursor): ComponentCursor<ComponentSchema, Data, Shared>[] | null;
|
|
20
21
|
remove(node: NodeCursor): boolean;
|
|
21
22
|
removeAll(node: NodeCursor): boolean;
|
|
22
|
-
|
|
23
|
+
serializedNodeData: {
|
|
23
24
|
get(node: SerializedNodeData): SerializedComponentData<ComponentSchema> | null;
|
|
24
25
|
set(node: SerializedNodeData, componentSchema?: Partial<ComponentSchema>): void;
|
|
25
26
|
getAll(node: SerializedNodeData): SerializedComponentData<ComponentSchema>[] | null;
|
|
26
27
|
remove(node: SerializedNodeData): SerializedComponentData<ComponentSchema> | null;
|
|
27
28
|
removeAll(node: SerializedNodeData): SerializedComponentData<ComponentSchema>[] | null;
|
|
29
|
+
set(node: CreateNodeData, schema: string, schemaViewId?: string | null): SerializedComponentData<ComponentSchema>[] | null;
|
|
30
|
+
};
|
|
31
|
+
nodeData: {
|
|
32
|
+
get(node: CreateNodeData): CreateComponentData<ComponentSchema> | null;
|
|
33
|
+
set(node: CreateNodeData, componentSchema?: Partial<ComponentSchema>): void;
|
|
34
|
+
getAll(node: CreateNodeData): CreateComponentData<ComponentSchema>[] | null;
|
|
35
|
+
remove(node: CreateNodeData): CreateComponentData<ComponentSchema> | null;
|
|
36
|
+
removeAll(node: CreateNodeData): CreateComponentData<ComponentSchema>[] | null;
|
|
37
|
+
set(node: CreateNodeData, schema: string, schemaViewId?: string, remote?: true | null): CreateComponentData<ComponentSchema>[] | null;
|
|
28
38
|
};
|
|
29
39
|
type: string;
|
|
30
40
|
typeId: number;
|
|
@@ -3,12 +3,15 @@ import { ComponentCursor } from "../Components/ComponentCursor";
|
|
|
3
3
|
import { NodeCursor } from "../Nodes/NodeCursor";
|
|
4
4
|
import { NCSPools } from "../Pools/NCSPools";
|
|
5
5
|
export const registerComponent = (data) => {
|
|
6
|
+
if (NCSRegister.components.has(data.type)) {
|
|
7
|
+
console.error(`Component of type: ${data.type} is already registered`);
|
|
8
|
+
}
|
|
6
9
|
const typeId = NCSRegister.components.register(data.type, data);
|
|
7
10
|
data.shared = data.shared || {};
|
|
8
11
|
const createComponent = (schema, schemaView) => {
|
|
9
12
|
const createData = NCSPools.createComponentData.get() || [];
|
|
10
13
|
createData[0] = data.type;
|
|
11
|
-
createData[1] = schema ||
|
|
14
|
+
createData[1] = schema || null;
|
|
12
15
|
createData[2] = schemaView || "default";
|
|
13
16
|
return createData;
|
|
14
17
|
};
|
|
@@ -32,43 +35,43 @@ export const registerComponent = (data) => {
|
|
|
32
35
|
return false;
|
|
33
36
|
for (let i = 0; i < array._disposed.length; i++) {
|
|
34
37
|
nodeCursor.setNode(graph, array._node[i]);
|
|
35
|
-
cursor.setInstance(nodeCursor, typeId, i);
|
|
38
|
+
cursor.setInstance(nodeCursor.index, graph, typeId, i);
|
|
36
39
|
yield cursor;
|
|
37
40
|
}
|
|
38
41
|
return true;
|
|
39
42
|
},
|
|
40
43
|
set(node, schema, schemaView, cursor = ComponentCursor.Get()) {
|
|
41
44
|
const newComponent = node.components.add(createComponent(schema, schemaView));
|
|
42
|
-
cursor.setInstance(node, typeId, newComponent);
|
|
45
|
+
cursor.setInstance(node.index, node.graph, typeId, newComponent);
|
|
43
46
|
node.graph._components[typeId].init(newComponent);
|
|
44
47
|
return cursor;
|
|
45
48
|
},
|
|
46
49
|
has(node) {
|
|
47
50
|
return node.components.has(data.type);
|
|
48
51
|
},
|
|
49
|
-
get(node, cursor
|
|
50
|
-
return node.components.get(data.type, cursor
|
|
52
|
+
get(node, cursor) {
|
|
53
|
+
return node.components.get(data.type, cursor);
|
|
51
54
|
},
|
|
52
|
-
getRequired(node, cursor
|
|
53
|
-
const found = node.components.get(data.type, cursor
|
|
55
|
+
getRequired(node, cursor) {
|
|
56
|
+
const found = node.components.get(data.type, cursor);
|
|
54
57
|
if (!found)
|
|
55
58
|
throw new Error(`NCS: Node [${node.name}] does not have required component [${data.type}].`);
|
|
56
59
|
return found;
|
|
57
60
|
},
|
|
58
61
|
getChild(node, cursor, nodeCursor) {
|
|
59
|
-
return node.components.getChild(data.type, cursor
|
|
62
|
+
return node.components.getChild(data.type, cursor);
|
|
60
63
|
},
|
|
61
64
|
getRequiredChild(node, cursor, nodeCursor) {
|
|
62
|
-
const comp = node.components.getChild(data.type, cursor
|
|
65
|
+
const comp = node.components.getChild(data.type, cursor);
|
|
63
66
|
if (!comp)
|
|
64
67
|
throw new Error(`NCS: Node [${node.name}] does not have a child with required component [${data.type}].`);
|
|
65
68
|
return comp;
|
|
66
69
|
},
|
|
67
70
|
getParent(node, cursor, nodeCursor) {
|
|
68
|
-
return node.components.getParent(data.type, cursor
|
|
71
|
+
return node.components.getParent(data.type, cursor);
|
|
69
72
|
},
|
|
70
73
|
getRequiredParent(node, cursor, nodeCursor) {
|
|
71
|
-
const comp = node.components.getParent(data.type, cursor
|
|
74
|
+
const comp = node.components.getParent(data.type, cursor);
|
|
72
75
|
if (!comp)
|
|
73
76
|
throw new Error(`NCS: Node [${node.name}] does not have a parent with required component [${data.type}].`);
|
|
74
77
|
return comp;
|
|
@@ -82,7 +85,7 @@ export const registerComponent = (data) => {
|
|
|
82
85
|
remove(node) {
|
|
83
86
|
return node.components.remove(data.type);
|
|
84
87
|
},
|
|
85
|
-
|
|
88
|
+
serializedNodeData: {
|
|
86
89
|
get: (node) => node.components?.find((_) => _.type == data.type) || null,
|
|
87
90
|
getAll: (node) => node.components?.filter((_) => _.type == data.type),
|
|
88
91
|
remove: (node) => node.components?.splice(node.components?.findIndex((_) => _.type == data.type))[0] || null,
|
|
@@ -91,13 +94,67 @@ export const registerComponent = (data) => {
|
|
|
91
94
|
node.components = node.components?.filter((_) => _.type != data.type);
|
|
92
95
|
return all?.length ? all : null;
|
|
93
96
|
},
|
|
94
|
-
set: (node, schema) => {
|
|
97
|
+
set: (node, schema, schemaViewId = null) => {
|
|
95
98
|
node.components ??= [];
|
|
96
99
|
node.components.push({
|
|
97
100
|
type: data.type,
|
|
98
|
-
schema: {},
|
|
101
|
+
...(schema ? { schema } : {}),
|
|
102
|
+
...(schemaViewId ? { schemaViewId: schemaViewId } : {}),
|
|
99
103
|
});
|
|
100
104
|
},
|
|
101
105
|
},
|
|
106
|
+
nodeData: {
|
|
107
|
+
get: (node) => {
|
|
108
|
+
if (!node[2])
|
|
109
|
+
return null;
|
|
110
|
+
for (const comp of node[2]) {
|
|
111
|
+
if (!comp)
|
|
112
|
+
continue;
|
|
113
|
+
if (comp[0] == data.type)
|
|
114
|
+
return comp;
|
|
115
|
+
}
|
|
116
|
+
return null;
|
|
117
|
+
},
|
|
118
|
+
getAll: (node) => {
|
|
119
|
+
const comps = [];
|
|
120
|
+
if (!node[2])
|
|
121
|
+
return comps;
|
|
122
|
+
for (const comp of node[2]) {
|
|
123
|
+
if (!comp)
|
|
124
|
+
continue;
|
|
125
|
+
if (comp[0] == data.type) {
|
|
126
|
+
comps.push(comp);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return comps;
|
|
130
|
+
},
|
|
131
|
+
remove: (node) => {
|
|
132
|
+
if (!node[2])
|
|
133
|
+
return null;
|
|
134
|
+
for (let i = 0; i < node[2].length; i++) {
|
|
135
|
+
const comp = node[2][i];
|
|
136
|
+
if (!comp)
|
|
137
|
+
continue;
|
|
138
|
+
return node[2].splice(i, 1)[0];
|
|
139
|
+
}
|
|
140
|
+
return null;
|
|
141
|
+
},
|
|
142
|
+
removeAll(node) {
|
|
143
|
+
if (!node[2])
|
|
144
|
+
return null;
|
|
145
|
+
for (let i = node[2].length - 1; i >= 0; i--) {
|
|
146
|
+
const comp = node[2][i];
|
|
147
|
+
if (!comp)
|
|
148
|
+
continue;
|
|
149
|
+
if (comp[0] == data.type) {
|
|
150
|
+
node[2].splice(i, 1)[0];
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return null;
|
|
154
|
+
},
|
|
155
|
+
set: (node, schema, schemaViewId = "default", remote = null) => {
|
|
156
|
+
node[2]?.push([data.type, schema, schemaViewId, remote]);
|
|
157
|
+
},
|
|
158
|
+
},
|
|
102
159
|
});
|
|
103
160
|
};
|
|
@@ -75,7 +75,7 @@ function traverse(parent, properties) {
|
|
|
75
75
|
if (this.__cursor.hasProxy(index)) {
|
|
76
76
|
return this.__cursor.fetchProxyData(index);
|
|
77
77
|
}
|
|
78
|
-
return getBinaryObjectData(this.__cursor.
|
|
78
|
+
return getBinaryObjectData(this.__cursor._cachedData, this.__view.meta[index], this.__view.byteOffset[index]);
|
|
79
79
|
},
|
|
80
80
|
set(value) {
|
|
81
81
|
let obs = this.__cursor.getObserver(index);
|
|
@@ -83,9 +83,9 @@ function traverse(parent, properties) {
|
|
|
83
83
|
if (obs) {
|
|
84
84
|
const oldVale = proxy
|
|
85
85
|
? this.__cursor.fetchProxyData(index)
|
|
86
|
-
: getBinaryObjectData(this.__cursor.
|
|
86
|
+
: getBinaryObjectData(this.__cursor._cachedData, this.__view.meta[index], this.__view.byteOffset[index]);
|
|
87
87
|
if (oldVale != value) {
|
|
88
|
-
setBinaryObjectData(this.__cursor.
|
|
88
|
+
setBinaryObjectData(this.__cursor._cachedData, this.__view.meta[index], this.__view.byteOffset[index], value);
|
|
89
89
|
if (proxy) {
|
|
90
90
|
this.__cursor.setProxyData(index, value);
|
|
91
91
|
}
|
|
@@ -93,7 +93,7 @@ function traverse(parent, properties) {
|
|
|
93
93
|
return;
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
|
-
setBinaryObjectData(this.__cursor.
|
|
96
|
+
setBinaryObjectData(this.__cursor._cachedData, this.__view.meta[index], this.__view.byteOffset[index], value);
|
|
97
97
|
if (proxy) {
|
|
98
98
|
this.__cursor.setProxyData(index, value);
|
|
99
99
|
}
|
|
@@ -9,7 +9,7 @@ function traverse(parent, properties) {
|
|
|
9
9
|
if (this.__cursor.hasProxy(index)) {
|
|
10
10
|
return this.__cursor.fetchProxyData(index);
|
|
11
11
|
}
|
|
12
|
-
return this.__cursor.
|
|
12
|
+
return this.__cursor._cachedData[index];
|
|
13
13
|
},
|
|
14
14
|
set(value) {
|
|
15
15
|
let obs = this.__cursor.getObserver(index);
|
|
@@ -17,9 +17,9 @@ function traverse(parent, properties) {
|
|
|
17
17
|
if (obs) {
|
|
18
18
|
const oldVale = proxy
|
|
19
19
|
? this.__cursor.fetchProxyData(index)
|
|
20
|
-
: this.__cursor.
|
|
20
|
+
: this.__cursor._cachedData[index];
|
|
21
21
|
if (oldVale != value) {
|
|
22
|
-
this.__cursor.
|
|
22
|
+
this.__cursor._cachedData[index] = value;
|
|
23
23
|
if (proxy) {
|
|
24
24
|
this.__cursor.setProxyData(index, value);
|
|
25
25
|
}
|
|
@@ -27,7 +27,7 @@ function traverse(parent, properties) {
|
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
this.__cursor.
|
|
30
|
+
this.__cursor._cachedData[index] = value;
|
|
31
31
|
if (proxy) {
|
|
32
32
|
this.__cursor.setProxyData(index, value);
|
|
33
33
|
}
|
|
@@ -9,7 +9,7 @@ function traverse(parent, properties) {
|
|
|
9
9
|
if (this.__cursor.hasProxy(index)) {
|
|
10
10
|
return this.__cursor.fetchProxyData(index);
|
|
11
11
|
}
|
|
12
|
-
return this.__cursor.
|
|
12
|
+
return this.__cursor._cachedData[index];
|
|
13
13
|
},
|
|
14
14
|
set(value) {
|
|
15
15
|
let obs = this.__cursor.getObserver(index);
|
|
@@ -17,9 +17,9 @@ function traverse(parent, properties) {
|
|
|
17
17
|
if (obs) {
|
|
18
18
|
const oldVale = proxy
|
|
19
19
|
? this.__cursor.fetchProxyData(index)
|
|
20
|
-
: this.__cursor.
|
|
20
|
+
: this.__cursor._cachedData[index];
|
|
21
21
|
if (oldVale != value) {
|
|
22
|
-
this.__cursor.
|
|
22
|
+
this.__cursor._cachedData[index] = value;
|
|
23
23
|
if (proxy) {
|
|
24
24
|
this.__cursor.setProxyData(index, value);
|
|
25
25
|
}
|
|
@@ -27,7 +27,7 @@ function traverse(parent, properties) {
|
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
this.__cursor.
|
|
30
|
+
this.__cursor._cachedData[index] = value;
|
|
31
31
|
if (proxy) {
|
|
32
32
|
this.__cursor.setProxyData(index, value);
|
|
33
33
|
}
|
package/Schema/Schema.js
CHANGED
|
@@ -12,12 +12,13 @@ const traverseCreate = (parent, properties, index) => {
|
|
|
12
12
|
for (let i = 0; i < properties.length; i++) {
|
|
13
13
|
const data = properties[i];
|
|
14
14
|
if (typeof data.value == "object" &&
|
|
15
|
+
data.value !== null &&
|
|
15
16
|
!data.children?.length &&
|
|
16
17
|
!Array.isArray(data.value)) {
|
|
17
18
|
data.children ??= [];
|
|
18
19
|
for (const key in data.value) {
|
|
19
20
|
const value = data.value[key];
|
|
20
|
-
const meta =
|
|
21
|
+
const meta = data.meta || {};
|
|
21
22
|
meta.child = true;
|
|
22
23
|
data.children.push({
|
|
23
24
|
id: key,
|
|
@@ -62,8 +63,8 @@ const traverseArray = (parent, data, meta) => {
|
|
|
62
63
|
for (let i = 0; i < parent.children.length; i++) {
|
|
63
64
|
const property = parent.children[i];
|
|
64
65
|
if (!property.children) {
|
|
65
|
-
data[Number(property.index)] =
|
|
66
|
-
property.meta && (meta[property.index] =
|
|
66
|
+
data[Number(property.index)] = property.value;
|
|
67
|
+
property.meta && (meta[property.index] = property.meta);
|
|
67
68
|
}
|
|
68
69
|
else {
|
|
69
70
|
traverseArray(property, data, meta);
|
|
@@ -83,7 +84,7 @@ function buildMeta(data, meta, metaOverrides) {
|
|
|
83
84
|
function traverseCreateFromObject(object, property) {
|
|
84
85
|
for (const id in object) {
|
|
85
86
|
const value = object[id];
|
|
86
|
-
if (typeof value == "object") {
|
|
87
|
+
if (typeof value == "object" && value !== null) {
|
|
87
88
|
property.children.push(traverseCreateFromObject(value, {
|
|
88
89
|
id,
|
|
89
90
|
value: {},
|
|
@@ -161,10 +162,7 @@ export class Schema {
|
|
|
161
162
|
}
|
|
162
163
|
createData(newData = [], overrides) {
|
|
163
164
|
for (let i = 0; i < this._data.length; i++) {
|
|
164
|
-
newData[i] =
|
|
165
|
-
typeof this._data[i] == "object"
|
|
166
|
-
? structuredClone(this._data[i])
|
|
167
|
-
: this._data[i];
|
|
165
|
+
newData[i] = this._data[i];
|
|
168
166
|
}
|
|
169
167
|
traverseCreateData(this.root, newData, overrides);
|
|
170
168
|
return newData;
|
|
@@ -3,8 +3,7 @@ import { SchemaArray } from "./SchemaArray";
|
|
|
3
3
|
export declare class SchemaArrayCursor {
|
|
4
4
|
schemaArray: SchemaArray;
|
|
5
5
|
constructor(schemaArray: SchemaArray);
|
|
6
|
-
|
|
7
|
-
set data(value: any);
|
|
6
|
+
_cachedData: any | null;
|
|
8
7
|
_index: number;
|
|
9
8
|
setIndex(index: number): void;
|
|
10
9
|
getObserver(propertyIndex: number): Observable<any> | null;
|
|
@@ -5,15 +5,11 @@ export class SchemaArrayCursor {
|
|
|
5
5
|
constructor(schemaArray) {
|
|
6
6
|
this.schemaArray = schemaArray;
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
return this.schemaArray._data[this._index];
|
|
10
|
-
}
|
|
11
|
-
set data(value) {
|
|
12
|
-
this.schemaArray._data[this._index] = value;
|
|
13
|
-
}
|
|
8
|
+
_cachedData = null;
|
|
14
9
|
_index = 0;
|
|
15
10
|
setIndex(index) {
|
|
16
11
|
this._index = index;
|
|
12
|
+
this._cachedData = this.schemaArray._data[index] ?? null;
|
|
17
13
|
}
|
|
18
14
|
getObserver(propertyIndex) {
|
|
19
15
|
return this.schemaArray.getObserver(propertyIndex, this._index);
|
package/Schema/SchemaView.d.ts
CHANGED
|
@@ -12,8 +12,11 @@ export declare class SchemaView<Shape extends {} = any> {
|
|
|
12
12
|
_createData: SchemaCreateData;
|
|
13
13
|
private _cursorClass;
|
|
14
14
|
_dataPool: ItemPool<unknown>;
|
|
15
|
+
_cursorPool: ItemPool<SchemaCursor<Shape>>;
|
|
16
|
+
private _tempData;
|
|
15
17
|
constructor(schema: Schema<Shape>, id: string, meta: PropertyMetaData[], byteOffset: number[], byteSize: number, _createData: SchemaCreateData, _cursorClass: any);
|
|
16
18
|
returnData(returnData: any): void;
|
|
19
|
+
returnCursor(cursor: SchemaCursor): void;
|
|
17
20
|
createData(overrides?: RecursivePartial<Shape> | null): any;
|
|
18
21
|
createCursor(): SchemaCursor<Shape>;
|
|
19
22
|
/** Converts data for use of remote components */
|