@amodx/ncs 0.0.23 → 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 +6 -1
- package/Components/ComponentArray.d.ts +4 -2
- package/Components/ComponentArray.js +19 -12
- 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 +5 -3
- package/Graphs/Graph.d.ts +2 -1
- package/Graphs/Graph.js +20 -17
- 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/NodeId.d.ts +3 -0
- package/Nodes/NodeId.js +10 -0
- 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 +14 -10
- 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/Schema/Schema.js
CHANGED
|
@@ -11,11 +11,14 @@ const traverseCreate = (parent, properties, index) => {
|
|
|
11
11
|
parent.children ??= [];
|
|
12
12
|
for (let i = 0; i < properties.length; i++) {
|
|
13
13
|
const data = properties[i];
|
|
14
|
-
if (typeof data.value == "object" &&
|
|
14
|
+
if (typeof data.value == "object" &&
|
|
15
|
+
data.value !== null &&
|
|
16
|
+
!data.children?.length &&
|
|
17
|
+
!Array.isArray(data.value)) {
|
|
15
18
|
data.children ??= [];
|
|
16
19
|
for (const key in data.value) {
|
|
17
20
|
const value = data.value[key];
|
|
18
|
-
const meta =
|
|
21
|
+
const meta = data.meta || {};
|
|
19
22
|
meta.child = true;
|
|
20
23
|
data.children.push({
|
|
21
24
|
id: key,
|
|
@@ -60,8 +63,8 @@ const traverseArray = (parent, data, meta) => {
|
|
|
60
63
|
for (let i = 0; i < parent.children.length; i++) {
|
|
61
64
|
const property = parent.children[i];
|
|
62
65
|
if (!property.children) {
|
|
63
|
-
data[Number(property.index)] =
|
|
64
|
-
property.meta && (meta[property.index] =
|
|
66
|
+
data[Number(property.index)] = property.value;
|
|
67
|
+
property.meta && (meta[property.index] = property.meta);
|
|
65
68
|
}
|
|
66
69
|
else {
|
|
67
70
|
traverseArray(property, data, meta);
|
|
@@ -81,7 +84,7 @@ function buildMeta(data, meta, metaOverrides) {
|
|
|
81
84
|
function traverseCreateFromObject(object, property) {
|
|
82
85
|
for (const id in object) {
|
|
83
86
|
const value = object[id];
|
|
84
|
-
if (typeof value == "object") {
|
|
87
|
+
if (typeof value == "object" && value !== null) {
|
|
85
88
|
property.children.push(traverseCreateFromObject(value, {
|
|
86
89
|
id,
|
|
87
90
|
value: {},
|
|
@@ -115,7 +118,11 @@ export class Schema {
|
|
|
115
118
|
const data = [];
|
|
116
119
|
for (const id in shape) {
|
|
117
120
|
const value = shape[id];
|
|
118
|
-
if (typeof value == "object"
|
|
121
|
+
if (typeof value == "object" &&
|
|
122
|
+
value !== null &&
|
|
123
|
+
typeof value !== "undefined" &&
|
|
124
|
+
!Array.isArray(id) &&
|
|
125
|
+
!ArrayBuffer.isView(value)) {
|
|
119
126
|
data.push(traverseCreateFromObject(value, {
|
|
120
127
|
id,
|
|
121
128
|
value: {},
|
|
@@ -155,10 +162,7 @@ export class Schema {
|
|
|
155
162
|
}
|
|
156
163
|
createData(newData = [], overrides) {
|
|
157
164
|
for (let i = 0; i < this._data.length; i++) {
|
|
158
|
-
newData[i] =
|
|
159
|
-
typeof this._data[i] == "object"
|
|
160
|
-
? structuredClone(this._data[i])
|
|
161
|
-
: this._data[i];
|
|
165
|
+
newData[i] = this._data[i];
|
|
162
166
|
}
|
|
163
167
|
traverseCreateData(this.root, newData, overrides);
|
|
164
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 */
|
package/Schema/SchemaView.js
CHANGED
|
@@ -13,7 +13,6 @@ function traverseCreateJSON(parent, target, source) {
|
|
|
13
13
|
}
|
|
14
14
|
return target;
|
|
15
15
|
}
|
|
16
|
-
const tempData = [];
|
|
17
16
|
export class SchemaView {
|
|
18
17
|
schema;
|
|
19
18
|
id;
|
|
@@ -23,6 +22,8 @@ export class SchemaView {
|
|
|
23
22
|
_createData;
|
|
24
23
|
_cursorClass;
|
|
25
24
|
_dataPool = new ItemPool();
|
|
25
|
+
_cursorPool = new ItemPool();
|
|
26
|
+
_tempData = [];
|
|
26
27
|
constructor(schema, id, meta, byteOffset, byteSize, _createData, _cursorClass) {
|
|
27
28
|
this.schema = schema;
|
|
28
29
|
this.id = id;
|
|
@@ -35,20 +36,20 @@ export class SchemaView {
|
|
|
35
36
|
returnData(returnData) {
|
|
36
37
|
this._dataPool.addItem(returnData);
|
|
37
38
|
}
|
|
39
|
+
returnCursor(cursor) {
|
|
40
|
+
this._cursorPool.addItem(cursor);
|
|
41
|
+
}
|
|
38
42
|
createData(overrides) {
|
|
39
43
|
const data = this._createData;
|
|
40
|
-
overrides && (
|
|
44
|
+
overrides && (this._tempData.length = 0);
|
|
41
45
|
let baseData = !overrides
|
|
42
46
|
? this.schema._data
|
|
43
|
-
: this.schema.createData(
|
|
47
|
+
: this.schema.createData(this._tempData, overrides);
|
|
44
48
|
if (this._dataPool.items.length) {
|
|
45
49
|
const newData = this._dataPool.get();
|
|
46
50
|
if (data.type == "object") {
|
|
47
51
|
for (let i = 0; i < baseData.length; i++) {
|
|
48
|
-
newData[i] =
|
|
49
|
-
typeof baseData[i] == "object"
|
|
50
|
-
? structuredClone(baseData[i])
|
|
51
|
-
: baseData[i];
|
|
52
|
+
newData[i] = baseData[i];
|
|
52
53
|
}
|
|
53
54
|
return newData;
|
|
54
55
|
}
|
|
@@ -69,10 +70,7 @@ export class SchemaView {
|
|
|
69
70
|
if (data.type == "object") {
|
|
70
71
|
const newData = new Array(baseData.length);
|
|
71
72
|
for (let i = 0; i < baseData.length; i++) {
|
|
72
|
-
newData[i] =
|
|
73
|
-
typeof baseData[i] == "object"
|
|
74
|
-
? structuredClone(baseData[i])
|
|
75
|
-
: baseData[i];
|
|
73
|
+
newData[i] = baseData[i];
|
|
76
74
|
}
|
|
77
75
|
return newData;
|
|
78
76
|
}
|
|
@@ -106,18 +104,22 @@ export class SchemaView {
|
|
|
106
104
|
throw new Error(`NCS: Invalid create data`);
|
|
107
105
|
}
|
|
108
106
|
createCursor() {
|
|
107
|
+
const pooled = this._cursorPool.get();
|
|
108
|
+
if (pooled) {
|
|
109
|
+
return pooled;
|
|
110
|
+
}
|
|
109
111
|
return new this._cursorClass(this, this.meta, this._createData, this.byteOffset);
|
|
110
112
|
}
|
|
111
113
|
/** Converts data for use of remote components */
|
|
112
114
|
toRemote(cursor) {
|
|
113
115
|
if (this._createData.type == "object") {
|
|
114
|
-
return cursor.__cursor.
|
|
116
|
+
return cursor.__cursor._cachedData;
|
|
115
117
|
}
|
|
116
118
|
if (this._createData.type == "typed-array") {
|
|
117
|
-
return cursor.__cursor.
|
|
119
|
+
return cursor.__cursor._cachedData;
|
|
118
120
|
}
|
|
119
121
|
if (this._createData.type == "binary-object") {
|
|
120
|
-
return cursor.__cursor.
|
|
122
|
+
return cursor.__cursor._cachedData.buffer;
|
|
121
123
|
}
|
|
122
124
|
}
|
|
123
125
|
/** Converts data for remote data to local data*/
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { GraphClock } from "../Graphs/GraphClock";
|
|
1
2
|
import { QueryPrototype } from "../Queries/QueryPrototype";
|
|
2
3
|
import { SystemInstance } from "./SystemInstance";
|
|
3
4
|
export type SystemRegisterData = {
|
|
@@ -12,5 +13,5 @@ export type SystemRegisterData = {
|
|
|
12
13
|
/**
|
|
13
14
|
* The update function of the system.
|
|
14
15
|
*/
|
|
15
|
-
update(system: SystemInstance,
|
|
16
|
+
update(system: SystemInstance, clock: GraphClock): void;
|
|
16
17
|
};
|
|
@@ -2,12 +2,13 @@ import { Graph } from "../Graphs/Graph";
|
|
|
2
2
|
import { SystemRegisterData } from "./System.types";
|
|
3
3
|
import { QueryInstance } from "../Queries/QueryInstance";
|
|
4
4
|
import { NodeCursor } from "../Nodes/NodeCursor";
|
|
5
|
+
import { GraphClock } from "../Graphs/GraphClock";
|
|
5
6
|
export declare class SystemInstance {
|
|
6
7
|
graph: Graph;
|
|
7
8
|
proto: SystemRegisterData;
|
|
8
9
|
queries: QueryInstance[];
|
|
9
10
|
node: NodeCursor;
|
|
10
11
|
constructor(graph: Graph, proto: SystemRegisterData);
|
|
11
|
-
update(
|
|
12
|
+
update(clock: GraphClock): void;
|
|
12
13
|
dispose(): void;
|
|
13
14
|
}
|
|
@@ -12,8 +12,8 @@ export class SystemInstance {
|
|
|
12
12
|
}
|
|
13
13
|
this.graph._systems.push(this);
|
|
14
14
|
}
|
|
15
|
-
update(
|
|
16
|
-
this.proto.update(this,
|
|
15
|
+
update(clock) {
|
|
16
|
+
this.proto.update(this, clock);
|
|
17
17
|
}
|
|
18
18
|
dispose() {
|
|
19
19
|
for (let i = 0; i < this.graph._systems.length; i++) {
|
package/Tags/Tag.js
CHANGED
|
@@ -12,7 +12,7 @@ export class Tag {
|
|
|
12
12
|
*traverseChildren() {
|
|
13
13
|
const children = [...this.children];
|
|
14
14
|
while (children.length) {
|
|
15
|
-
const child = children.
|
|
15
|
+
const child = children.pop();
|
|
16
16
|
yield child;
|
|
17
17
|
if (child.children.length)
|
|
18
18
|
children.push(...child.children);
|
package/Tags/TagArray.js
CHANGED
package/Util/ItemPool.js
CHANGED
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@amodx/ncs","version":"0.0.
|
|
1
|
+
{"name":"@amodx/ncs","version":"0.0.27","module":"index.js","types":"index.d.ts","type":"module","description":"NCS (Node Component System) is a library for the base of any NCS/ECS system.","keywords":[],"scripts":{"build":"mkdir -p dist && rm -rf dist/* && cp package.json dist/package.json && cd ./src && npx tsc","compile":"cd ./src && npx tsc --watch"},"repository":{"url":"git+https://github.com/Amodx/Libraries.git"},"bugs":{"url":"https://github.com/Amodx/Libraries/issues"},"homepage":"https://github.com/Amodx/Libraries","author":"Amodx","license":"MIT","devDependencies":{},"main":"index.js","publishConfig":{"access":"public"}}
|