@amodx/ncs 0.0.1 → 0.0.21
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 +78 -0
- package/Components/ComponentArray.d.ts +30 -0
- package/Components/ComponentArray.js +82 -0
- package/Components/ComponentCursor.d.ts +27 -0
- package/Components/ComponentCursor.js +72 -0
- package/Contexts/Context.types.d.ts +76 -0
- package/Contexts/ContextArray.d.ts +14 -0
- package/Contexts/ContextArray.js +47 -0
- package/Contexts/ContextCursor.d.ts +24 -0
- package/Contexts/ContextCursor.js +47 -0
- package/Data/SerializedData.types.d.ts +44 -0
- package/Data/deserializeComponent.d.ts +3 -0
- package/Data/deserializeComponent.js +3 -0
- package/Data/deserializeNode.d.ts +3 -0
- package/Data/deserializeNode.js +34 -0
- package/Data/serializeComponent.d.ts +7 -0
- package/Data/serializeComponent.js +36 -0
- package/Data/serializeNode.d.ts +13 -0
- package/Data/serializeNode.js +83 -0
- package/Functional.d.ts +12 -0
- package/Functional.js +31 -0
- package/Graphs/Graph.d.ts +19 -21
- package/Graphs/Graph.js +85 -74
- package/NCS.d.ts +79 -48
- package/NCS.js +115 -32
- package/Nodes/Node.types.d.ts +39 -0
- package/Nodes/Node.types.js +16 -0
- package/Nodes/NodeArray.d.ts +25 -0
- package/Nodes/NodeArray.js +96 -0
- package/Nodes/NodeComponents.d.ts +19 -0
- package/Nodes/NodeComponents.js +183 -0
- package/Nodes/NodeContext.d.ts +14 -0
- package/Nodes/NodeContext.js +107 -0
- package/Nodes/NodeCursor.d.ts +65 -0
- package/Nodes/NodeCursor.js +348 -0
- package/Nodes/NodeEvents.d.ts +13 -14
- package/Nodes/NodeEvents.js +58 -28
- package/Nodes/NodeId.d.ts +4 -13
- package/Nodes/NodeId.js +16 -48
- package/Nodes/NodeObservers.d.ts +35 -20
- package/Nodes/NodeObservers.js +162 -37
- package/Nodes/NodeTags.d.ts +17 -0
- package/Nodes/NodeTags.js +102 -0
- package/Pools/NCSPools.d.ts +27 -4
- package/Pools/NCSPools.js +14 -2
- package/Queries/Query.types.d.ts +8 -0
- package/Queries/QueryInstance.d.ts +6 -4
- package/Queries/QueryInstance.js +89 -44
- package/Queries/QueryPrototype.d.ts +1 -1
- package/Register/NCSRegister.d.ts +17 -9
- package/Register/NCSRegister.js +25 -2
- package/Register/registerComponent.d.ts +31 -25
- package/Register/registerComponent.js +88 -36
- package/Register/registerContext.d.ts +10 -13
- package/Register/registerContext.js +16 -16
- package/Register/registerSystem.d.ts +1 -1
- package/Register/registerSystem.js +1 -1
- package/Register/registerTag.d.ts +15 -17
- package/Register/registerTag.js +20 -23
- package/Schema/Functions/createBaseSchemaCursor.d.ts +18 -0
- package/Schema/Functions/createBaseSchemaCursor.js +34 -0
- package/Schema/Functions/createSchemaBinaryObjectCursorClass.d.ts +22 -0
- package/Schema/Functions/createSchemaBinaryObjectCursorClass.js +134 -0
- package/Schema/Functions/createSchemaIndex.d.ts +3 -0
- package/Schema/Functions/createSchemaIndex.js +18 -0
- package/Schema/Functions/createSchemaObjectCursorClass.d.ts +18 -0
- package/Schema/Functions/createSchemaObjectCursorClass.js +66 -0
- package/Schema/Functions/createSchemaTypedArrayCursorClass.d.ts +17 -0
- package/Schema/Functions/createSchemaTypedArrayCursorClass.js +66 -0
- package/Schema/Property/Property.d.ts +11 -0
- package/Schema/Property/Property.js +16 -0
- package/Schema/Property/Property.types.d.ts +26 -0
- package/Schema/Property/Property.types.js +20 -0
- package/Schema/Schema.d.ts +28 -0
- package/Schema/Schema.js +223 -0
- package/Schema/Schema.types.d.ts +59 -0
- package/Schema/Schema.types.js +8 -0
- package/Schema/SchemaArray.d.ts +23 -0
- package/Schema/SchemaArray.js +87 -0
- package/Schema/SchemaArrayCursor.d.ts +19 -0
- package/Schema/SchemaArrayCursor.js +56 -0
- package/Schema/SchemaView.d.ts +24 -0
- package/Schema/SchemaView.js +141 -0
- package/Systems/{SystemData.d.ts → System.types.d.ts} +0 -4
- package/Systems/SystemInstance.d.ts +6 -4
- package/Systems/SystemInstance.js +14 -8
- package/Systems/SystemPrototype.d.ts +1 -1
- package/Systems/SystemPrototype.js +0 -1
- package/Tags/Tag.d.ts +1 -1
- package/Tags/Tag.js +1 -1
- package/Tags/{TagData.d.ts → Tag.types.d.ts} +0 -17
- package/Tags/TagArray.d.ts +18 -0
- package/Tags/TagArray.js +37 -0
- package/Tags/TagCursor.d.ts +20 -0
- package/Tags/TagCursor.js +45 -0
- package/Util/IdPalette.d.ts +13 -0
- package/Util/IdPalette.js +38 -0
- package/{Pools → Util}/ItemPool.d.ts +2 -3
- package/{Pools → Util}/ItemPool.js +2 -4
- package/Util/Observable.d.ts +28 -0
- package/Util/Observable.js +58 -0
- package/Util/Util.types.d.ts +4 -0
- package/index.d.ts +16 -6
- package/index.js +24 -6
- package/package.json +1 -1
- package/Components/ComponentData.d.ts +0 -112
- package/Components/ComponentInstance.d.ts +0 -36
- package/Components/ComponentInstance.js +0 -125
- package/Components/ComponentInstanceMap.d.ts +0 -7
- package/Components/ComponentInstanceMap.js +0 -15
- package/Components/ComponentObservers.d.ts +0 -8
- package/Components/ComponentObservers.js +0 -13
- package/Components/ComponentPipelines.d.ts +0 -16
- package/Components/ComponentPipelines.js +0 -33
- package/Components/ComponentPrototype.d.ts +0 -17
- package/Components/ComponentPrototype.js +0 -73
- package/Contexts/ContextData.d.ts +0 -59
- package/Contexts/ContextInstance.d.ts +0 -14
- package/Contexts/ContextInstance.js +0 -26
- package/Contexts/ContextInstanceAnchor.d.ts +0 -15
- package/Contexts/ContextInstanceAnchor.js +0 -33
- package/Contexts/ContextPrototype.d.ts +0 -9
- package/Contexts/ContextPrototype.js +0 -19
- package/Graphs/GraphEvents.d.ts +0 -9
- package/Graphs/GraphEvents.js +0 -35
- package/Graphs/GraphObservers.d.ts +0 -9
- package/Graphs/GraphObservers.js +0 -6
- package/Graphs/GraphUpdate.d.ts +0 -13
- package/Graphs/GraphUpdate.js +0 -38
- package/Maps/ItemGraphMap.d.ts +0 -11
- package/Maps/ItemGraphMap.js +0 -30
- package/Maps/ItemNodeMap.d.ts +0 -17
- package/Maps/ItemNodeMap.js +0 -41
- package/Nodes/Components/NodeComponentObservers.d.ts +0 -15
- package/Nodes/Components/NodeComponentObservers.js +0 -33
- package/Nodes/Components/NodeComponents.d.ts +0 -22
- package/Nodes/Components/NodeComponents.js +0 -107
- package/Nodes/Context/NodeContext.d.ts +0 -13
- package/Nodes/Context/NodeContext.js +0 -45
- package/Nodes/NodeData.d.ts +0 -40
- package/Nodes/NodeInstance.d.ts +0 -50
- package/Nodes/NodeInstance.js +0 -202
- package/Nodes/NodePipelines.d.ts +0 -16
- package/Nodes/NodePipelines.js +0 -33
- package/Nodes/Tags/NodeTagObservers.d.ts +0 -15
- package/Nodes/Tags/NodeTagObservers.js +0 -33
- package/Nodes/Tags/NodeTags.d.ts +0 -21
- package/Nodes/Tags/NodeTags.js +0 -95
- package/Queries/QueryData.d.ts +0 -8
- package/Register/ItemRegister.d.ts +0 -7
- package/Register/ItemRegister.js +0 -24
- package/Register/registerTrait.d.ts +0 -15
- package/Register/registerTrait.js +0 -39
- package/Tags/TagInstance.d.ts +0 -13
- package/Tags/TagInstance.js +0 -17
- package/Tags/TagInstanceMap.d.ts +0 -7
- package/Tags/TagInstanceMap.js +0 -15
- package/Tags/TagPrototype.d.ts +0 -16
- package/Tags/TagPrototype.js +0 -34
- package/Traits/TraitContaienrObservers.d.ts +0 -15
- package/Traits/TraitContaienrObservers.js +0 -33
- package/Traits/TraitContainer.d.ts +0 -22
- package/Traits/TraitContainer.js +0 -114
- package/Traits/TraitData.d.ts +0 -106
- package/Traits/TraitInstance.d.ts +0 -35
- package/Traits/TraitInstance.js +0 -115
- package/Traits/TraitInstanceMap.d.ts +0 -7
- package/Traits/TraitInstanceMap.js +0 -15
- package/Traits/TraitObservers.d.ts +0 -8
- package/Traits/TraitObservers.js +0 -13
- package/Traits/TraitPipelines.d.ts +0 -16
- package/Traits/TraitPipelines.js +0 -33
- package/Traits/TraitPrototype.d.ts +0 -16
- package/Traits/TraitPrototype.js +0 -74
- /package/Components/{ComponentData.js → Component.types.js} +0 -0
- /package/Contexts/{ContextData.js → Context.types.js} +0 -0
- /package/{Nodes/NodeData.js → Data/SerializedData.types.js} +0 -0
- /package/Queries/{QueryData.js → Query.types.js} +0 -0
- /package/Systems/{SystemData.js → System.types.js} +0 -0
- /package/Tags/{TagData.js → Tag.types.js} +0 -0
- /package/{Traits/TraitData.js → Util/Util.types.js} +0 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type ObservableFunction<T> = (data: T) => void;
|
|
2
|
+
export declare class Observable<T = void> {
|
|
3
|
+
private observers;
|
|
4
|
+
private once;
|
|
5
|
+
constructor();
|
|
6
|
+
listener(func: any): ObservableFunction<T>;
|
|
7
|
+
/**
|
|
8
|
+
* Subscribe to the observer. If only the first param is set must be the observer function itself which will be used as they key.
|
|
9
|
+
* Otherwise the first param is the key to subsrcibe to the observer with.
|
|
10
|
+
*/
|
|
11
|
+
subscribe(func: ObservableFunction<T>): void;
|
|
12
|
+
/**
|
|
13
|
+
* Unsubscribe to the observer using the key used in the subscribe function.
|
|
14
|
+
*/
|
|
15
|
+
unsubscribe(func: ObservableFunction<T>): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Subscribe to the observer once.
|
|
18
|
+
*/
|
|
19
|
+
subscribeOnce(func: ObservableFunction<T>): void;
|
|
20
|
+
/**
|
|
21
|
+
* Run each callback function.
|
|
22
|
+
*/
|
|
23
|
+
notify(data: T): void;
|
|
24
|
+
/**
|
|
25
|
+
* Removes all observers.
|
|
26
|
+
*/
|
|
27
|
+
clear(): void;
|
|
28
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export class Observable {
|
|
2
|
+
observers = [];
|
|
3
|
+
once = null;
|
|
4
|
+
constructor() { }
|
|
5
|
+
listener(func) {
|
|
6
|
+
return func;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Subscribe to the observer. If only the first param is set must be the observer function itself which will be used as they key.
|
|
10
|
+
* Otherwise the first param is the key to subsrcibe to the observer with.
|
|
11
|
+
*/
|
|
12
|
+
subscribe(func) {
|
|
13
|
+
this.observers.push(func);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Unsubscribe to the observer using the key used in the subscribe function.
|
|
17
|
+
*/
|
|
18
|
+
unsubscribe(func) {
|
|
19
|
+
for (let i = 0; i < this.observers.length; i++) {
|
|
20
|
+
if (this.observers[i] == func) {
|
|
21
|
+
this.observers.splice(i, 1);
|
|
22
|
+
if (this.once && this.once.has(func))
|
|
23
|
+
this.once.delete(func);
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Subscribe to the observer once.
|
|
31
|
+
*/
|
|
32
|
+
subscribeOnce(func) {
|
|
33
|
+
this.observers.push(func);
|
|
34
|
+
if (!this.once)
|
|
35
|
+
this.once = new Set();
|
|
36
|
+
this.once.add(func);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Run each callback function.
|
|
40
|
+
*/
|
|
41
|
+
notify(data) {
|
|
42
|
+
for (let i = this.observers.length - 1; i >= 0; i--) {
|
|
43
|
+
const func = this.observers[i];
|
|
44
|
+
func(data);
|
|
45
|
+
if (this.once && this.once.has(func)) {
|
|
46
|
+
this.observers.splice(i, 1);
|
|
47
|
+
this.once.delete(func);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Removes all observers.
|
|
53
|
+
*/
|
|
54
|
+
clear() {
|
|
55
|
+
this.once && this.once.clear();
|
|
56
|
+
this.observers.length = 0;
|
|
57
|
+
}
|
|
58
|
+
}
|
package/index.d.ts
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
export * from "./NCS";
|
|
2
|
+
export * from "./Functional";
|
|
2
3
|
export * from "./Graphs/Graph";
|
|
3
|
-
export * from "./
|
|
4
|
-
export * from "./
|
|
5
|
-
export * from "./
|
|
6
|
-
export * from "./
|
|
7
|
-
export * from "./Nodes/
|
|
8
|
-
export * from "./
|
|
4
|
+
export * from "./Data/SerializedData.types";
|
|
5
|
+
export * from "./Schema/Schema";
|
|
6
|
+
export * from "./Schema/Property/Property";
|
|
7
|
+
export * from "./Nodes/NodeCursor";
|
|
8
|
+
export * from "./Nodes/Node.types";
|
|
9
|
+
export * from "./Components/Component.types";
|
|
10
|
+
export * from "./Components/ComponentCursor";
|
|
11
|
+
export * from "./Tags/Tag.types";
|
|
12
|
+
export * from "./Tags/TagCursor";
|
|
13
|
+
export * from "./Contexts/Context.types";
|
|
14
|
+
export * from "./Contexts/ContextCursor";
|
|
15
|
+
export * from "./Queries/Query.types";
|
|
16
|
+
export * from "./Queries/QueryInstance";
|
|
17
|
+
export * from "./Systems/System.types";
|
|
18
|
+
export * from "./Systems/SystemInstance";
|
package/index.js
CHANGED
|
@@ -1,8 +1,26 @@
|
|
|
1
1
|
export * from "./NCS";
|
|
2
|
+
export * from "./Functional";
|
|
2
3
|
export * from "./Graphs/Graph";
|
|
3
|
-
|
|
4
|
-
export * from "./
|
|
5
|
-
|
|
6
|
-
export * from "./
|
|
7
|
-
export * from "./
|
|
8
|
-
|
|
4
|
+
//data
|
|
5
|
+
export * from "./Data/SerializedData.types";
|
|
6
|
+
//schema
|
|
7
|
+
export * from "./Schema/Schema";
|
|
8
|
+
export * from "./Schema/Property/Property";
|
|
9
|
+
//nodes
|
|
10
|
+
export * from "./Nodes/NodeCursor";
|
|
11
|
+
export * from "./Nodes/Node.types";
|
|
12
|
+
//components
|
|
13
|
+
export * from "./Components/Component.types";
|
|
14
|
+
export * from "./Components/ComponentCursor";
|
|
15
|
+
//tags
|
|
16
|
+
export * from "./Tags/Tag.types";
|
|
17
|
+
export * from "./Tags/TagCursor";
|
|
18
|
+
//context
|
|
19
|
+
export * from "./Contexts/Context.types";
|
|
20
|
+
export * from "./Contexts/ContextCursor";
|
|
21
|
+
//queries
|
|
22
|
+
export * from "./Queries/Query.types";
|
|
23
|
+
export * from "./Queries/QueryInstance";
|
|
24
|
+
//systems
|
|
25
|
+
export * from "./Systems/System.types";
|
|
26
|
+
export * from "./Systems/SystemInstance";
|
package/package.json
CHANGED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { Property } from "@amodx/schemas";
|
|
2
|
-
import { ComponentInstance } from "./ComponentInstance";
|
|
3
|
-
import { TraitData } from "../Traits/TraitData";
|
|
4
|
-
/**
|
|
5
|
-
* Interface representing the meta data of a component.
|
|
6
|
-
*/
|
|
7
|
-
export interface ComponentMetaData {
|
|
8
|
-
name: string;
|
|
9
|
-
[key: string]: any;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Interface representing the pool data of a component.
|
|
13
|
-
*/
|
|
14
|
-
export interface ComponentPoolData {
|
|
15
|
-
maxSize: number;
|
|
16
|
-
[key: string]: any;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Interface representing the state data of a component.
|
|
20
|
-
*/
|
|
21
|
-
export interface ComponentStateData {
|
|
22
|
-
[key: string]: any;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Type representing the data of a component.
|
|
26
|
-
*
|
|
27
|
-
* @template ComponentSchema - The ComponentSchema of the component.
|
|
28
|
-
*/
|
|
29
|
-
export type ComponentData<ComponentSchema extends object = any> = {
|
|
30
|
-
/**
|
|
31
|
-
* The type of the component.
|
|
32
|
-
*/
|
|
33
|
-
type: string;
|
|
34
|
-
/**
|
|
35
|
-
* The namespace of the component.
|
|
36
|
-
*/
|
|
37
|
-
namespace?: string;
|
|
38
|
-
/**
|
|
39
|
-
* The state data of the component.
|
|
40
|
-
*/
|
|
41
|
-
state: ComponentStateData;
|
|
42
|
-
/**
|
|
43
|
-
* The ComponentSchema of the component.
|
|
44
|
-
*/
|
|
45
|
-
schema: ComponentSchema;
|
|
46
|
-
/**
|
|
47
|
-
* The traits associated with the component.
|
|
48
|
-
*/
|
|
49
|
-
traits: TraitData[];
|
|
50
|
-
};
|
|
51
|
-
/**
|
|
52
|
-
* Type representing the data required to register a component.
|
|
53
|
-
*
|
|
54
|
-
* Used for serlization and creation.
|
|
55
|
-
* @template ComponentSchema - The schema of the component.
|
|
56
|
-
* @template Data - The runtime data of the component.
|
|
57
|
-
* @template Logic - The logic functions of the component.
|
|
58
|
-
* @template Shared - The shared data of all components of this type.
|
|
59
|
-
* @template Meta - The shared meta data of all components of this type.
|
|
60
|
-
*/
|
|
61
|
-
export type ComponentRegisterData<ComponentSchema extends object = {}, Data extends Record<string, any> = {}, Logic extends Record<string, any> = {}, Shared extends Record<string, any> = {}> = {
|
|
62
|
-
/**
|
|
63
|
-
* The type of the component.
|
|
64
|
-
*/
|
|
65
|
-
type: string;
|
|
66
|
-
/**
|
|
67
|
-
* The namespace of the component.
|
|
68
|
-
*/
|
|
69
|
-
namespace?: string;
|
|
70
|
-
pool?: ComponentPoolData;
|
|
71
|
-
/**
|
|
72
|
-
* The schema used to create an editable version of the component.
|
|
73
|
-
* For the actual ComponentInstance the schema is created into an object.
|
|
74
|
-
*/
|
|
75
|
-
schema?: Property<any, any>[];
|
|
76
|
-
/**
|
|
77
|
-
* The logic functions of the component.
|
|
78
|
-
*/
|
|
79
|
-
logic?: Logic | ((component: ComponentInstance<ComponentSchema, Data, Logic, Shared>) => Logic);
|
|
80
|
-
/**
|
|
81
|
-
* The runtime data of the component.
|
|
82
|
-
*/
|
|
83
|
-
data?: Data | ((component: ComponentInstance<ComponentSchema, Data, Logic, Shared>) => Data);
|
|
84
|
-
/**
|
|
85
|
-
* The shared data of all components.
|
|
86
|
-
*/
|
|
87
|
-
shared?: Shared;
|
|
88
|
-
/**
|
|
89
|
-
* The shared meta data of all components.
|
|
90
|
-
*/
|
|
91
|
-
meta?: ComponentMetaData;
|
|
92
|
-
/**
|
|
93
|
-
* Optional initialization function for the component.
|
|
94
|
-
*
|
|
95
|
-
* @param component - The instance of the component being initialized.
|
|
96
|
-
*/
|
|
97
|
-
init?(component: ComponentInstance<ComponentSchema, Data, Logic, Shared>): Promise<void> | void;
|
|
98
|
-
/**
|
|
99
|
-
* Optional update function for the component.
|
|
100
|
-
* The update function is usually called once per frame.
|
|
101
|
-
* It is up to the graph though when it gets called.
|
|
102
|
-
*
|
|
103
|
-
* @param component - The instance of the component being updated.
|
|
104
|
-
*/
|
|
105
|
-
update?(component: ComponentInstance<ComponentSchema, Data, Logic, Shared>): Promise<void> | void;
|
|
106
|
-
/**
|
|
107
|
-
* Optional disposal function for the component.
|
|
108
|
-
*
|
|
109
|
-
* @param component - The instance of the component being disposed.
|
|
110
|
-
*/
|
|
111
|
-
dispose?(component: ComponentInstance<ComponentSchema, Data, Logic, Shared>): Promise<void> | void;
|
|
112
|
-
};
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { ComponentData, ComponentStateData } from "./ComponentData";
|
|
2
|
-
import { ObjectSchemaInstance, QueryPath } from "@amodx/schemas";
|
|
3
|
-
import { SchemaNode } from "@amodx/schemas/Schemas/SchemaNode";
|
|
4
|
-
import { NodeInstance } from "../Nodes/NodeInstance";
|
|
5
|
-
import { ComponentObservers } from "./ComponentObservers";
|
|
6
|
-
import { ComponentPipelines } from "./ComponentPipelines";
|
|
7
|
-
import { TraintContainer } from "../Traits/TraitContainer";
|
|
8
|
-
import { ComponentPrototype } from "./ComponentPrototype";
|
|
9
|
-
export declare class ComponentInstance<ComponentSchema extends object = {}, Data extends object = {}, Logic extends object = {}, Shared extends object = {}> {
|
|
10
|
-
get type(): string;
|
|
11
|
-
get shared(): Shared;
|
|
12
|
-
componentPrototype: ComponentPrototype<ComponentSchema, Data, Logic, Shared>;
|
|
13
|
-
schema: ObjectSchemaInstance<ComponentSchema>;
|
|
14
|
-
data: Data;
|
|
15
|
-
logic: Logic;
|
|
16
|
-
state: ComponentStateData;
|
|
17
|
-
private _traits?;
|
|
18
|
-
get traits(): TraintContainer;
|
|
19
|
-
get hasTraits(): boolean;
|
|
20
|
-
private _observers?;
|
|
21
|
-
get observers(): ComponentObservers;
|
|
22
|
-
get hasObservers(): boolean;
|
|
23
|
-
private _pipelines?;
|
|
24
|
-
get pipelines(): ComponentPipelines<ComponentSchema>;
|
|
25
|
-
get hasPipelines(): boolean;
|
|
26
|
-
node: NodeInstance;
|
|
27
|
-
addOnSchemaUpdate(path: QueryPath<ComponentSchema>, listener: (node: SchemaNode) => void): void;
|
|
28
|
-
removeOnSchemaUpdate(path: QueryPath<ComponentSchema>, listener: (node: SchemaNode) => void): void;
|
|
29
|
-
init(): Promise<void>;
|
|
30
|
-
private _disposed;
|
|
31
|
-
isDisposed(): boolean;
|
|
32
|
-
dispose(): Promise<void>;
|
|
33
|
-
getDependencies(): boolean;
|
|
34
|
-
copy(): ComponentData;
|
|
35
|
-
toJSON(): ComponentData;
|
|
36
|
-
}
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { ObjectPath } from "@amodx/schemas";
|
|
2
|
-
import { GraphUpdate } from "../Graphs/GraphUpdate";
|
|
3
|
-
import { ComponentObservers } from "./ComponentObservers";
|
|
4
|
-
import { ComponentPipelines } from "./ComponentPipelines";
|
|
5
|
-
import { TraintContainer } from "../Traits/TraitContainer";
|
|
6
|
-
export class ComponentInstance {
|
|
7
|
-
get type() {
|
|
8
|
-
return this.componentPrototype.data.type;
|
|
9
|
-
}
|
|
10
|
-
get shared() {
|
|
11
|
-
return this.componentPrototype.data.shared;
|
|
12
|
-
}
|
|
13
|
-
componentPrototype;
|
|
14
|
-
schema;
|
|
15
|
-
data;
|
|
16
|
-
logic;
|
|
17
|
-
state;
|
|
18
|
-
_traits;
|
|
19
|
-
get traits() {
|
|
20
|
-
if (!this._traits) {
|
|
21
|
-
this._traits = new TraintContainer(this);
|
|
22
|
-
}
|
|
23
|
-
return this._traits;
|
|
24
|
-
}
|
|
25
|
-
get hasTraits() {
|
|
26
|
-
return Boolean(this._traits);
|
|
27
|
-
}
|
|
28
|
-
_observers;
|
|
29
|
-
get observers() {
|
|
30
|
-
if (!this._observers) {
|
|
31
|
-
this._observers = new ComponentObservers();
|
|
32
|
-
}
|
|
33
|
-
return this._observers;
|
|
34
|
-
}
|
|
35
|
-
get hasObservers() {
|
|
36
|
-
return Boolean(this._observers);
|
|
37
|
-
}
|
|
38
|
-
_pipelines;
|
|
39
|
-
get pipelines() {
|
|
40
|
-
if (!this._pipelines) {
|
|
41
|
-
this._pipelines = new ComponentPipelines();
|
|
42
|
-
}
|
|
43
|
-
return this._pipelines;
|
|
44
|
-
}
|
|
45
|
-
get hasPipelines() {
|
|
46
|
-
return Boolean(this._pipelines);
|
|
47
|
-
}
|
|
48
|
-
node;
|
|
49
|
-
addOnSchemaUpdate(path, listener) {
|
|
50
|
-
this.schema
|
|
51
|
-
.getSchema()
|
|
52
|
-
.getNode(ObjectPath.Create(path))
|
|
53
|
-
?.observers.updatedOrLoadedIn.subscribe(listener);
|
|
54
|
-
}
|
|
55
|
-
removeOnSchemaUpdate(path, listener) {
|
|
56
|
-
this.schema
|
|
57
|
-
.getSchema()
|
|
58
|
-
.getNode(ObjectPath.Create(path))
|
|
59
|
-
?.observers.updatedOrLoadedIn.unsubscribe(listener);
|
|
60
|
-
}
|
|
61
|
-
async init() {
|
|
62
|
-
if (!this.componentPrototype.data.init)
|
|
63
|
-
return;
|
|
64
|
-
await this.componentPrototype.data.init(this);
|
|
65
|
-
if (this.componentPrototype.data.update) {
|
|
66
|
-
GraphUpdate.addComponentToUpdate(this);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
_disposed = false;
|
|
70
|
-
isDisposed() {
|
|
71
|
-
return this._disposed;
|
|
72
|
-
}
|
|
73
|
-
async dispose() {
|
|
74
|
-
if (this.componentPrototype.data.update) {
|
|
75
|
-
GraphUpdate.removeComponentFromUpate(this);
|
|
76
|
-
}
|
|
77
|
-
this.hasPipelines &&
|
|
78
|
-
this.pipelines.isDisposedSet() &&
|
|
79
|
-
this.pipelines.disposed.pipe(this);
|
|
80
|
-
this.hasObservers &&
|
|
81
|
-
this.observers.isDisposedSet() &&
|
|
82
|
-
this.observers.disposed.notify();
|
|
83
|
-
if (this.componentPrototype.data.dispose)
|
|
84
|
-
await this.componentPrototype.data.dispose(this);
|
|
85
|
-
this._disposed = true;
|
|
86
|
-
if (this.hasTraits)
|
|
87
|
-
await this.traits.dispose();
|
|
88
|
-
this.componentPrototype.destory(this);
|
|
89
|
-
delete this._traits;
|
|
90
|
-
delete this._observers;
|
|
91
|
-
delete this._pipelines;
|
|
92
|
-
}
|
|
93
|
-
getDependencies() {
|
|
94
|
-
// return this.node.graph.dependencies;
|
|
95
|
-
return false;
|
|
96
|
-
}
|
|
97
|
-
copy() {
|
|
98
|
-
const data = {
|
|
99
|
-
schema: this.schema?.getSchema
|
|
100
|
-
? this.schema.getSchema().store()
|
|
101
|
-
: {},
|
|
102
|
-
type: this.type,
|
|
103
|
-
state: this.state,
|
|
104
|
-
traits: (this.hasTraits && this.traits.traits.map((_) => _.toJSON())) || [],
|
|
105
|
-
};
|
|
106
|
-
return ((this.hasPipelines &&
|
|
107
|
-
this.pipelines.isCopySet() &&
|
|
108
|
-
this.pipelines.copy.pipe(data)) ||
|
|
109
|
-
data);
|
|
110
|
-
}
|
|
111
|
-
toJSON() {
|
|
112
|
-
const data = {
|
|
113
|
-
schema: this.schema?.getSchema
|
|
114
|
-
? this.schema.getSchema().store()
|
|
115
|
-
: {},
|
|
116
|
-
type: this.type,
|
|
117
|
-
state: this.state,
|
|
118
|
-
traits: (this.hasTraits && this.traits.traits.map((_) => _.toJSON())) || [],
|
|
119
|
-
};
|
|
120
|
-
return ((this.hasPipelines &&
|
|
121
|
-
this.pipelines.isToJSONSet() &&
|
|
122
|
-
this.pipelines.toJSON.pipe(data)) ||
|
|
123
|
-
data);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { ComponentInstance } from "./ComponentInstance";
|
|
2
|
-
import { ItemGraphMap } from "../Maps/ItemGraphMap";
|
|
3
|
-
export declare class ComponentInstanceMap {
|
|
4
|
-
private static types;
|
|
5
|
-
static registerComponent(type: string): ItemGraphMap<any>;
|
|
6
|
-
static getMap(type: string): ItemGraphMap<ComponentInstance<any, any, any, any>>;
|
|
7
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { ItemGraphMap } from "../Maps/ItemGraphMap";
|
|
2
|
-
export class ComponentInstanceMap {
|
|
3
|
-
static types = new Map();
|
|
4
|
-
static registerComponent(type) {
|
|
5
|
-
const map = new ItemGraphMap();
|
|
6
|
-
this.types.set(type, map);
|
|
7
|
-
return map;
|
|
8
|
-
}
|
|
9
|
-
static getMap(type) {
|
|
10
|
-
const map = this.types.get(type);
|
|
11
|
-
if (!map)
|
|
12
|
-
throw new Error(`Map for component ${type} does not exist`);
|
|
13
|
-
return map;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Observable } from "@amodx/core/Observers";
|
|
2
|
-
export class ComponentObservers {
|
|
3
|
-
_disposed;
|
|
4
|
-
get disposed() {
|
|
5
|
-
if (!this._disposed) {
|
|
6
|
-
this._disposed = new Observable();
|
|
7
|
-
}
|
|
8
|
-
return this._disposed;
|
|
9
|
-
}
|
|
10
|
-
isDisposedSet() {
|
|
11
|
-
return !!this._disposed;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Pipeline } from "@amodx/core/Pipelines";
|
|
2
|
-
import { ComponentInstance } from "./ComponentInstance";
|
|
3
|
-
import { ComponentData } from "./ComponentData";
|
|
4
|
-
export interface ComponentPipelines {
|
|
5
|
-
}
|
|
6
|
-
export declare class ComponentPipelines<ComponentSchema extends object = {}> {
|
|
7
|
-
private _disposed?;
|
|
8
|
-
private _toJSON?;
|
|
9
|
-
private _copy?;
|
|
10
|
-
get disposed(): Pipeline<ComponentInstance<ComponentSchema>>;
|
|
11
|
-
get toJSON(): Pipeline<ComponentData<ComponentSchema>>;
|
|
12
|
-
get copy(): Pipeline<ComponentData<ComponentSchema>>;
|
|
13
|
-
isDisposedSet(): boolean;
|
|
14
|
-
isToJSONSet(): boolean;
|
|
15
|
-
isCopySet(): boolean;
|
|
16
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { Pipeline } from "@amodx/core/Pipelines";
|
|
2
|
-
export class ComponentPipelines {
|
|
3
|
-
_disposed;
|
|
4
|
-
_toJSON;
|
|
5
|
-
_copy;
|
|
6
|
-
get disposed() {
|
|
7
|
-
if (!this._disposed) {
|
|
8
|
-
this._disposed = new Pipeline();
|
|
9
|
-
}
|
|
10
|
-
return this._disposed;
|
|
11
|
-
}
|
|
12
|
-
get toJSON() {
|
|
13
|
-
if (!this._toJSON) {
|
|
14
|
-
this._toJSON = new Pipeline();
|
|
15
|
-
}
|
|
16
|
-
return this._toJSON;
|
|
17
|
-
}
|
|
18
|
-
get copy() {
|
|
19
|
-
if (!this._copy) {
|
|
20
|
-
this._copy = new Pipeline();
|
|
21
|
-
}
|
|
22
|
-
return this._copy;
|
|
23
|
-
}
|
|
24
|
-
isDisposedSet() {
|
|
25
|
-
return !!this._disposed;
|
|
26
|
-
}
|
|
27
|
-
isToJSONSet() {
|
|
28
|
-
return !!this._toJSON;
|
|
29
|
-
}
|
|
30
|
-
isCopySet() {
|
|
31
|
-
return !!this._copy;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { ObjectSchemaInstance, Schema } from "@amodx/schemas";
|
|
2
|
-
import { ComponentData, ComponentRegisterData } from "./ComponentData";
|
|
3
|
-
import { ComponentInstance } from "./ComponentInstance";
|
|
4
|
-
import { NodeInstance } from "../Nodes/NodeInstance";
|
|
5
|
-
import { ItemPool } from "../Pools/ItemPool";
|
|
6
|
-
export declare class ComponentPrototype<ComponentSchema extends object = {}, Data extends Record<string, any> = {}, Logic extends Record<string, any> = {}, Shared extends Record<string, any> = {}> {
|
|
7
|
-
data: ComponentRegisterData<ComponentSchema, Data, Logic, Shared>;
|
|
8
|
-
schemaController: Schema<ComponentSchema> | null;
|
|
9
|
-
baseContextSchema: ComponentSchema;
|
|
10
|
-
pool: ItemPool<ComponentInstance<ComponentSchema, Data, Logic, Shared>>;
|
|
11
|
-
constructor(data: ComponentRegisterData<ComponentSchema, Data, Logic, Shared>);
|
|
12
|
-
getSchema(overrides: Partial<ComponentSchema>): ObjectSchemaInstance<ComponentSchema>;
|
|
13
|
-
private getPooled;
|
|
14
|
-
private return;
|
|
15
|
-
create(node: NodeInstance, data: ComponentData): ComponentInstance<ComponentSchema, Data, Logic, Shared>;
|
|
16
|
-
destory(component: ComponentInstance<ComponentSchema, Data, Logic, Shared>): void;
|
|
17
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { Schema } from "@amodx/schemas";
|
|
2
|
-
import { ComponentInstance } from "./ComponentInstance";
|
|
3
|
-
import { ComponentInstanceMap } from "./ComponentInstanceMap";
|
|
4
|
-
import { ItemPool } from "../Pools/ItemPool";
|
|
5
|
-
export class ComponentPrototype {
|
|
6
|
-
data;
|
|
7
|
-
schemaController;
|
|
8
|
-
baseContextSchema;
|
|
9
|
-
pool = new ItemPool();
|
|
10
|
-
constructor(data) {
|
|
11
|
-
this.data = data;
|
|
12
|
-
this.schemaController =
|
|
13
|
-
Array.isArray(data.schema) && data.schema.length
|
|
14
|
-
? Schema.Create(...data.schema)
|
|
15
|
-
: null;
|
|
16
|
-
this.baseContextSchema = (this.schemaController ? this.schemaController.createData() : {});
|
|
17
|
-
this.pool.maxSize = data.pool?.maxSize || 100;
|
|
18
|
-
}
|
|
19
|
-
getSchema(overrides) {
|
|
20
|
-
if (!this.schemaController)
|
|
21
|
-
return structuredClone(this.baseContextSchema);
|
|
22
|
-
return this.schemaController.instantiate(overrides);
|
|
23
|
-
}
|
|
24
|
-
getPooled() {
|
|
25
|
-
let comp = null;
|
|
26
|
-
if (this.data.pool?.maxSize) {
|
|
27
|
-
comp = this.pool.get();
|
|
28
|
-
}
|
|
29
|
-
return comp || new ComponentInstance();
|
|
30
|
-
}
|
|
31
|
-
return(component) {
|
|
32
|
-
if (this.data.pool?.maxSize) {
|
|
33
|
-
return this.pool.addItem(component);
|
|
34
|
-
}
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
create(node, data) {
|
|
38
|
-
const instance = this.getPooled();
|
|
39
|
-
instance.node = node;
|
|
40
|
-
instance.componentPrototype = this;
|
|
41
|
-
if (this.data.schema && !instance.schema) {
|
|
42
|
-
instance.schema = this.getSchema(data.schema);
|
|
43
|
-
}
|
|
44
|
-
if (this.data.schema && instance.schema?.getSchema) {
|
|
45
|
-
instance.schema.getSchema().loadIn(this.data.schema);
|
|
46
|
-
}
|
|
47
|
-
if (this.data.logic) {
|
|
48
|
-
instance.logic = this.data.logic
|
|
49
|
-
? typeof this.data.logic == "function"
|
|
50
|
-
? this.data.logic(instance)
|
|
51
|
-
: structuredClone(this.data.logic)
|
|
52
|
-
: {};
|
|
53
|
-
}
|
|
54
|
-
if (this.data.data) {
|
|
55
|
-
instance.data = this.data.data
|
|
56
|
-
? typeof this.data.data == "function"
|
|
57
|
-
? this.data.data(instance)
|
|
58
|
-
: structuredClone(this.data.data)
|
|
59
|
-
: {};
|
|
60
|
-
}
|
|
61
|
-
if (data.state) {
|
|
62
|
-
instance.state = structuredClone(data.state);
|
|
63
|
-
}
|
|
64
|
-
const map = ComponentInstanceMap.getMap(data.type);
|
|
65
|
-
map.addNode(node, instance);
|
|
66
|
-
return instance;
|
|
67
|
-
}
|
|
68
|
-
destory(component) {
|
|
69
|
-
const map = ComponentInstanceMap.getMap(component.type);
|
|
70
|
-
map.removeNode(component.node, component);
|
|
71
|
-
this.return(component);
|
|
72
|
-
}
|
|
73
|
-
}
|