@amodx/ncs 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +20 -0
- package/Contexts/ContextCursor.js +39 -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 +108 -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 +180 -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 +10 -13
- package/Nodes/NodeEvents.js +51 -26
- 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 +13 -18
- 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
package/Tags/TagPrototype.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { TagInstance } from "./TagInstance";
|
|
2
|
-
import { ItemPool } from "../Pools/ItemPool";
|
|
3
|
-
import { TagInstanceMap } from "./TagInstanceMap";
|
|
4
|
-
export class TagPrototype {
|
|
5
|
-
data;
|
|
6
|
-
tag;
|
|
7
|
-
pool = new ItemPool(1000);
|
|
8
|
-
constructor(data, tag) {
|
|
9
|
-
this.data = data;
|
|
10
|
-
this.tag = tag;
|
|
11
|
-
}
|
|
12
|
-
getPooled() {
|
|
13
|
-
let tag = null;
|
|
14
|
-
tag = this.pool.get();
|
|
15
|
-
return tag || new TagInstance();
|
|
16
|
-
}
|
|
17
|
-
return(tag) {
|
|
18
|
-
this.pool.addItem(tag);
|
|
19
|
-
}
|
|
20
|
-
create(node, data) {
|
|
21
|
-
const instance = this.getPooled();
|
|
22
|
-
instance.node = node;
|
|
23
|
-
instance.tag = this.tag;
|
|
24
|
-
instance.tagPrototype = this;
|
|
25
|
-
const map = TagInstanceMap.getMap(data.id);
|
|
26
|
-
map.addNode(node, instance);
|
|
27
|
-
return instance;
|
|
28
|
-
}
|
|
29
|
-
destory(tag) {
|
|
30
|
-
const map = TagInstanceMap.getMap(tag.id);
|
|
31
|
-
map.removeNode(tag.node, tag);
|
|
32
|
-
this.return(tag);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Observable } from "@amodx/core/Observers";
|
|
2
|
-
import { TraitInstance } from "Traits/TraitInstance";
|
|
3
|
-
export interface TraitContainerObservers {
|
|
4
|
-
}
|
|
5
|
-
export declare class TraitContainerObservers {
|
|
6
|
-
private _traitAdded?;
|
|
7
|
-
private _traitRemoved?;
|
|
8
|
-
private _traitsUpdated?;
|
|
9
|
-
get traitAdded(): Observable<TraitInstance>;
|
|
10
|
-
get traitRemoved(): Observable<TraitInstance>;
|
|
11
|
-
get traitsUpdated(): Observable<void>;
|
|
12
|
-
isTraitAddedSet(): boolean;
|
|
13
|
-
isTraitRemovedSet(): boolean;
|
|
14
|
-
isTraitsUpdatedSet(): boolean;
|
|
15
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { Observable } from "@amodx/core/Observers";
|
|
2
|
-
export class TraitContainerObservers {
|
|
3
|
-
_traitAdded;
|
|
4
|
-
_traitRemoved;
|
|
5
|
-
_traitsUpdated;
|
|
6
|
-
get traitAdded() {
|
|
7
|
-
if (!this._traitAdded) {
|
|
8
|
-
this._traitAdded = new Observable();
|
|
9
|
-
}
|
|
10
|
-
return this._traitAdded;
|
|
11
|
-
}
|
|
12
|
-
get traitRemoved() {
|
|
13
|
-
if (!this._traitRemoved) {
|
|
14
|
-
this._traitRemoved = new Observable();
|
|
15
|
-
}
|
|
16
|
-
return this._traitRemoved;
|
|
17
|
-
}
|
|
18
|
-
get traitsUpdated() {
|
|
19
|
-
if (!this._traitsUpdated) {
|
|
20
|
-
this._traitsUpdated = new Observable();
|
|
21
|
-
}
|
|
22
|
-
return this._traitsUpdated;
|
|
23
|
-
}
|
|
24
|
-
isTraitAddedSet() {
|
|
25
|
-
return !!this._traitAdded;
|
|
26
|
-
}
|
|
27
|
-
isTraitRemovedSet() {
|
|
28
|
-
return !!this._traitRemoved;
|
|
29
|
-
}
|
|
30
|
-
isTraitsUpdatedSet() {
|
|
31
|
-
return !!this._traitsUpdated;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { TraitInstance } from "./TraitInstance";
|
|
2
|
-
import { ComponentInstance } from "../Components/ComponentInstance";
|
|
3
|
-
import { TraitData } from "./TraitData";
|
|
4
|
-
import { TraitContainerObservers } from "./TraitContaienrObservers";
|
|
5
|
-
export declare class TraintContainer {
|
|
6
|
-
parent: ComponentInstance<any, any, any> | TraitInstance;
|
|
7
|
-
private _observers?;
|
|
8
|
-
get observers(): TraitContainerObservers;
|
|
9
|
-
get hasObservers(): boolean;
|
|
10
|
-
traits: TraitInstance[];
|
|
11
|
-
constructor(parent: ComponentInstance<any, any, any> | TraitInstance);
|
|
12
|
-
traverseTraits(): Generator<any>;
|
|
13
|
-
dispose(): Promise<void>;
|
|
14
|
-
initAllTraits(): Promise<void>;
|
|
15
|
-
add(trait: TraitData): Promise<TraitInstance<any, any, any, any>>;
|
|
16
|
-
addTraits(...traits: TraitData[]): Promise<TraitInstance<any, any, any, any>[]>;
|
|
17
|
-
removeByIndex(index: number): Promise<boolean>;
|
|
18
|
-
remove(type: string): Promise<boolean>;
|
|
19
|
-
get(type: string): TraitInstance<any, any, any, any> | null;
|
|
20
|
-
getAll(type: string): TraitInstance<any, any, any, any>[];
|
|
21
|
-
removeAll(type: string): Promise<TraitInstance<any, any, any, any>[]>;
|
|
22
|
-
}
|
package/Traits/TraitContainer.js
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { TraitContainerObservers } from "./TraitContaienrObservers";
|
|
2
|
-
import { NCSRegister } from "../Register/NCSRegister";
|
|
3
|
-
export class TraintContainer {
|
|
4
|
-
parent;
|
|
5
|
-
_observers;
|
|
6
|
-
get observers() {
|
|
7
|
-
if (!this._observers) {
|
|
8
|
-
this._observers = new TraitContainerObservers();
|
|
9
|
-
}
|
|
10
|
-
return this._observers;
|
|
11
|
-
}
|
|
12
|
-
get hasObservers() {
|
|
13
|
-
return Boolean(this._observers);
|
|
14
|
-
}
|
|
15
|
-
traits = [];
|
|
16
|
-
constructor(parent) {
|
|
17
|
-
this.parent = parent;
|
|
18
|
-
}
|
|
19
|
-
*traverseTraits() {
|
|
20
|
-
const children = [...this.traits];
|
|
21
|
-
while (children.length) {
|
|
22
|
-
const child = children.shift();
|
|
23
|
-
yield child;
|
|
24
|
-
if (child.traits.traits.length)
|
|
25
|
-
children.push(...child.traits.traits);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
async dispose() {
|
|
29
|
-
for (const child of this.traits) {
|
|
30
|
-
child.dispose();
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
async initAllTraits() {
|
|
34
|
-
for (const trait of this.traits) {
|
|
35
|
-
await trait.init();
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
async add(trait) {
|
|
39
|
-
const traitType = NCSRegister.traits.get(trait.type, trait.namespace || "main");
|
|
40
|
-
const newTrait = traitType.create(this.parent, trait);
|
|
41
|
-
this.traits.push(newTrait);
|
|
42
|
-
await newTrait.init();
|
|
43
|
-
if (trait.traits?.length) {
|
|
44
|
-
newTrait.traits.addTraits(...trait.traits);
|
|
45
|
-
}
|
|
46
|
-
this.hasObservers &&
|
|
47
|
-
this.observers.isTraitAddedSet() &&
|
|
48
|
-
this.observers.traitAdded.notify(newTrait);
|
|
49
|
-
this.hasObservers &&
|
|
50
|
-
this.observers.isTraitsUpdatedSet() &&
|
|
51
|
-
this.observers.traitsUpdated.notify();
|
|
52
|
-
return newTrait;
|
|
53
|
-
}
|
|
54
|
-
async addTraits(...traits) {
|
|
55
|
-
const newTraits = [];
|
|
56
|
-
for (const trait of traits) {
|
|
57
|
-
const traitType = NCSRegister.traits.get(trait.type, trait.namespace || "main");
|
|
58
|
-
const newTrait = traitType.create(this.parent, trait);
|
|
59
|
-
this.traits.push(newTrait);
|
|
60
|
-
newTraits.push(newTrait);
|
|
61
|
-
await newTrait.init();
|
|
62
|
-
if (trait.traits?.length) {
|
|
63
|
-
newTrait.traits.addTraits(...trait.traits);
|
|
64
|
-
}
|
|
65
|
-
this.hasObservers &&
|
|
66
|
-
this.observers.isTraitAddedSet() &&
|
|
67
|
-
this.observers.traitAdded.notify(newTrait);
|
|
68
|
-
}
|
|
69
|
-
this.hasObservers &&
|
|
70
|
-
this.observers.isTraitsUpdatedSet() &&
|
|
71
|
-
this.observers.traitsUpdated.notify();
|
|
72
|
-
return newTraits;
|
|
73
|
-
}
|
|
74
|
-
async removeByIndex(index) {
|
|
75
|
-
const trait = this.traits[index];
|
|
76
|
-
if (trait) {
|
|
77
|
-
const child = this.traits.splice(index, 1)[0];
|
|
78
|
-
this.hasObservers &&
|
|
79
|
-
this.observers.isTraitRemovedSet() &&
|
|
80
|
-
this.observers.traitRemoved.notify(child);
|
|
81
|
-
this.hasObservers &&
|
|
82
|
-
this.observers.isTraitsUpdatedSet() &&
|
|
83
|
-
this.observers.traitsUpdated.notify();
|
|
84
|
-
await trait.dispose();
|
|
85
|
-
return true;
|
|
86
|
-
}
|
|
87
|
-
return false;
|
|
88
|
-
}
|
|
89
|
-
remove(type) {
|
|
90
|
-
return this.removeByIndex(this.traits.findIndex((_) => _.type == type));
|
|
91
|
-
}
|
|
92
|
-
get(type) {
|
|
93
|
-
return this.traits.find((_) => _.type == type) || null;
|
|
94
|
-
}
|
|
95
|
-
getAll(type) {
|
|
96
|
-
return this.traits.filter((_) => _.type == type);
|
|
97
|
-
}
|
|
98
|
-
async removeAll(type) {
|
|
99
|
-
const filtered = this.getAll(type);
|
|
100
|
-
for (const trait of filtered) {
|
|
101
|
-
await trait.dispose();
|
|
102
|
-
}
|
|
103
|
-
this.traits = this.traits.filter((_) => _.type != type);
|
|
104
|
-
for (const comp of filtered) {
|
|
105
|
-
this.hasObservers &&
|
|
106
|
-
this.observers.isTraitRemovedSet() &&
|
|
107
|
-
this.observers.traitRemoved.notify(comp);
|
|
108
|
-
}
|
|
109
|
-
this.hasObservers &&
|
|
110
|
-
this.observers.isTraitsUpdatedSet() &&
|
|
111
|
-
this.observers.traitsUpdated.notify();
|
|
112
|
-
return filtered;
|
|
113
|
-
}
|
|
114
|
-
}
|
package/Traits/TraitData.d.ts
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { Property } from "@amodx/schemas";
|
|
2
|
-
import { TraitInstance } from "./TraitInstance";
|
|
3
|
-
/**
|
|
4
|
-
* Interface representing the meta data of a trait.
|
|
5
|
-
*/
|
|
6
|
-
export interface TraitMetaData {
|
|
7
|
-
name: string;
|
|
8
|
-
[key: string]: any;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Interface representing the pool data of a component.
|
|
12
|
-
*/
|
|
13
|
-
export interface TraitPoolData {
|
|
14
|
-
maxSize: number;
|
|
15
|
-
[key: string]: any;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Interface representing the state data of a trait.
|
|
19
|
-
*/
|
|
20
|
-
export interface TraitStateData {
|
|
21
|
-
[key: string]: any;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Type representing the data of a trait.
|
|
25
|
-
*
|
|
26
|
-
* @template TraitSchema - The TraitSchema of the trait.
|
|
27
|
-
*/
|
|
28
|
-
export type TraitData<TraitSchema extends object = any> = {
|
|
29
|
-
/**
|
|
30
|
-
* The type of the trait.
|
|
31
|
-
*/
|
|
32
|
-
type: string;
|
|
33
|
-
/**
|
|
34
|
-
* The namespace of the trait.
|
|
35
|
-
*/
|
|
36
|
-
namespace?: string;
|
|
37
|
-
/**
|
|
38
|
-
* The state data of the trait.
|
|
39
|
-
*/
|
|
40
|
-
state: TraitStateData;
|
|
41
|
-
/**
|
|
42
|
-
* The TraitSchema of the trait.
|
|
43
|
-
*/
|
|
44
|
-
schema: TraitSchema;
|
|
45
|
-
/**
|
|
46
|
-
* The traits associated with the trait.
|
|
47
|
-
*/
|
|
48
|
-
traits: TraitData[];
|
|
49
|
-
};
|
|
50
|
-
/**
|
|
51
|
-
* Type representing the data required to register a trait.
|
|
52
|
-
*
|
|
53
|
-
* Used for serlization and creation.
|
|
54
|
-
* @template TraitSchema - The schema of the trait.
|
|
55
|
-
* @template Data - The runtime data of the trait.
|
|
56
|
-
* @template Logic - The logic functions of the trait.
|
|
57
|
-
* @template Shared - The shared data of all traits of this type.
|
|
58
|
-
*/
|
|
59
|
-
export type TraitRegisterData<TraitSchema extends object = {}, Data extends Record<string, any> = {}, Logic extends Record<string, any> = {}, Shared extends Record<string, any> = {}> = {
|
|
60
|
-
/**
|
|
61
|
-
* The type of the trait.
|
|
62
|
-
*/
|
|
63
|
-
type: string;
|
|
64
|
-
/**
|
|
65
|
-
* The namespace of the trait.
|
|
66
|
-
*/
|
|
67
|
-
namespace?: string;
|
|
68
|
-
/**
|
|
69
|
-
* The optional name of the trait.
|
|
70
|
-
*/
|
|
71
|
-
name?: string;
|
|
72
|
-
pool?: TraitPoolData;
|
|
73
|
-
/**
|
|
74
|
-
* The schema used to create an editable version of the trait.
|
|
75
|
-
* For the actual TraitInstance the schema is created into an object.
|
|
76
|
-
*/
|
|
77
|
-
schema?: Property<any, any>[];
|
|
78
|
-
/**
|
|
79
|
-
* The logic functions of the trait.
|
|
80
|
-
*/
|
|
81
|
-
logic?: Logic | ((component: TraitInstance<TraitSchema, Data, Logic, Shared>) => Logic);
|
|
82
|
-
/**
|
|
83
|
-
* The runtime data of the trait.
|
|
84
|
-
*/
|
|
85
|
-
data?: Data | ((component: TraitInstance<TraitSchema, Data, Logic, Shared>) => Data);
|
|
86
|
-
/**
|
|
87
|
-
* The shared data of all traits.
|
|
88
|
-
*/
|
|
89
|
-
shared?: Shared;
|
|
90
|
-
/**
|
|
91
|
-
* The shared meta data of all traits.
|
|
92
|
-
*/
|
|
93
|
-
meta?: TraitMetaData;
|
|
94
|
-
/**
|
|
95
|
-
* Optional initialization function for the trait.
|
|
96
|
-
*
|
|
97
|
-
* @param component - The instance of the component being initialized.
|
|
98
|
-
*/
|
|
99
|
-
init?(component: TraitInstance<TraitSchema, Data, Logic>): Promise<void> | void;
|
|
100
|
-
/**
|
|
101
|
-
* Optional disposal function for the trait.
|
|
102
|
-
*
|
|
103
|
-
* @param component - The instance of the component being disposed.
|
|
104
|
-
*/
|
|
105
|
-
dispose?(component: TraitInstance<TraitSchema, Data, Logic>): Promise<void> | void;
|
|
106
|
-
};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { TraitData, TraitStateData } from "./TraitData";
|
|
2
|
-
import { ObjectSchemaInstance } from "@amodx/schemas";
|
|
3
|
-
import { ComponentInstance } from "../Components/ComponentInstance";
|
|
4
|
-
import { NodeInstance } from "../Nodes/NodeInstance";
|
|
5
|
-
import { TraintContainer } from "./TraitContainer";
|
|
6
|
-
import { TraitObservers } from "./TraitObservers";
|
|
7
|
-
import { TraitPipelines } from "./TraitPipelines";
|
|
8
|
-
import { TraitPrototype } from "./TraitPrototype";
|
|
9
|
-
export declare class TraitInstance<TraitSchema extends object = {}, Data extends object = {}, Logic extends object = {}, Shared extends object = {}> {
|
|
10
|
-
type: string;
|
|
11
|
-
schema: ObjectSchemaInstance<TraitSchema>;
|
|
12
|
-
data: Data;
|
|
13
|
-
logic: Logic;
|
|
14
|
-
state: TraitStateData;
|
|
15
|
-
private _shared;
|
|
16
|
-
get shared(): Shared;
|
|
17
|
-
private _traits?;
|
|
18
|
-
get traits(): TraintContainer;
|
|
19
|
-
get hasTraits(): boolean;
|
|
20
|
-
private _observers?;
|
|
21
|
-
get observers(): TraitObservers;
|
|
22
|
-
get hasObservers(): boolean;
|
|
23
|
-
private _pipelines?;
|
|
24
|
-
get pipelines(): TraitPipelines<TraitSchema>;
|
|
25
|
-
get hasPipelines(): boolean;
|
|
26
|
-
parent: ComponentInstance<any, any, any, any> | TraitInstance<any, any, any, any>;
|
|
27
|
-
traitProotype: TraitPrototype<TraitSchema, Data, Logic, Shared>;
|
|
28
|
-
getNode(): NodeInstance;
|
|
29
|
-
init(): Promise<void>;
|
|
30
|
-
private _disposed;
|
|
31
|
-
isDisposed(): boolean;
|
|
32
|
-
dispose(): Promise<void>;
|
|
33
|
-
copy(): TraitData;
|
|
34
|
-
toJSON(): TraitData;
|
|
35
|
-
}
|
package/Traits/TraitInstance.js
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { ComponentInstance } from "../Components/ComponentInstance";
|
|
2
|
-
import { NodeInstance } from "../Nodes/NodeInstance";
|
|
3
|
-
import { TraintContainer } from "./TraitContainer";
|
|
4
|
-
import { TraitObservers } from "./TraitObservers";
|
|
5
|
-
import { TraitPipelines } from "./TraitPipelines";
|
|
6
|
-
export class TraitInstance {
|
|
7
|
-
type;
|
|
8
|
-
schema;
|
|
9
|
-
data;
|
|
10
|
-
logic;
|
|
11
|
-
state;
|
|
12
|
-
_shared;
|
|
13
|
-
get shared() {
|
|
14
|
-
return this._shared;
|
|
15
|
-
}
|
|
16
|
-
_traits;
|
|
17
|
-
get traits() {
|
|
18
|
-
if (!this._traits) {
|
|
19
|
-
this._traits = new TraintContainer(this);
|
|
20
|
-
}
|
|
21
|
-
return this._traits;
|
|
22
|
-
}
|
|
23
|
-
get hasTraits() {
|
|
24
|
-
return Boolean(this._traits);
|
|
25
|
-
}
|
|
26
|
-
_observers;
|
|
27
|
-
get observers() {
|
|
28
|
-
if (!this._observers) {
|
|
29
|
-
this._observers = new TraitObservers();
|
|
30
|
-
}
|
|
31
|
-
return this._observers;
|
|
32
|
-
}
|
|
33
|
-
get hasObservers() {
|
|
34
|
-
return Boolean(this._observers);
|
|
35
|
-
}
|
|
36
|
-
_pipelines;
|
|
37
|
-
get pipelines() {
|
|
38
|
-
if (!this._pipelines) {
|
|
39
|
-
this._pipelines = new TraitPipelines();
|
|
40
|
-
}
|
|
41
|
-
return this._pipelines;
|
|
42
|
-
}
|
|
43
|
-
get hasPipelines() {
|
|
44
|
-
return Boolean(this._pipelines);
|
|
45
|
-
}
|
|
46
|
-
parent;
|
|
47
|
-
traitProotype;
|
|
48
|
-
getNode() {
|
|
49
|
-
let node = this.parent;
|
|
50
|
-
while (!(node instanceof NodeInstance)) {
|
|
51
|
-
if (node instanceof ComponentInstance) {
|
|
52
|
-
node = node.node;
|
|
53
|
-
break;
|
|
54
|
-
}
|
|
55
|
-
if (node instanceof TraitInstance) {
|
|
56
|
-
node = node.parent;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return node;
|
|
60
|
-
}
|
|
61
|
-
async init() {
|
|
62
|
-
if (!this.traitProotype.data.init)
|
|
63
|
-
return;
|
|
64
|
-
await this.traitProotype.data.init(this);
|
|
65
|
-
}
|
|
66
|
-
_disposed = false;
|
|
67
|
-
isDisposed() {
|
|
68
|
-
return this._disposed;
|
|
69
|
-
}
|
|
70
|
-
async dispose() {
|
|
71
|
-
this.hasPipelines &&
|
|
72
|
-
this.pipelines.isDisposedSet() &&
|
|
73
|
-
this.pipelines.disposed.pipe(this);
|
|
74
|
-
this.hasObservers &&
|
|
75
|
-
this.observers.isDisposedSet() &&
|
|
76
|
-
this.observers.disposed.notify();
|
|
77
|
-
if (this.traitProotype.data.dispose)
|
|
78
|
-
await this.traitProotype.data.dispose(this);
|
|
79
|
-
this._disposed = true;
|
|
80
|
-
if (this.hasTraits)
|
|
81
|
-
await this.traits.dispose();
|
|
82
|
-
this.traitProotype.destory(this);
|
|
83
|
-
delete this._traits;
|
|
84
|
-
delete this._observers;
|
|
85
|
-
delete this._pipelines;
|
|
86
|
-
}
|
|
87
|
-
copy() {
|
|
88
|
-
const data = {
|
|
89
|
-
schema: this.schema?.getSchema
|
|
90
|
-
? this.schema.getSchema().store()
|
|
91
|
-
: {},
|
|
92
|
-
type: this.type,
|
|
93
|
-
state: this.state,
|
|
94
|
-
traits: (this.hasTraits && this.traits.traits.map((_) => _.toJSON())) || [],
|
|
95
|
-
};
|
|
96
|
-
return ((this.hasPipelines &&
|
|
97
|
-
this.pipelines.isCopySet() &&
|
|
98
|
-
this.pipelines.copy.pipe(data)) ||
|
|
99
|
-
data);
|
|
100
|
-
}
|
|
101
|
-
toJSON() {
|
|
102
|
-
const data = {
|
|
103
|
-
schema: this.schema?.getSchema
|
|
104
|
-
? this.schema.getSchema().store()
|
|
105
|
-
: {},
|
|
106
|
-
type: this.type,
|
|
107
|
-
state: this.state,
|
|
108
|
-
traits: (this.hasTraits && this.traits.traits.map((_) => _.toJSON())) || [],
|
|
109
|
-
};
|
|
110
|
-
return ((this.hasPipelines &&
|
|
111
|
-
this.pipelines.isCopySet() &&
|
|
112
|
-
this.pipelines.copy.pipe(data)) ||
|
|
113
|
-
data);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { TraitInstance } from "./TraitInstance";
|
|
2
|
-
import { ItemGraphMap } from "../Maps/ItemGraphMap";
|
|
3
|
-
export declare class TraitInstanceMap {
|
|
4
|
-
private static types;
|
|
5
|
-
static registerTrait(type: string): ItemGraphMap<any>;
|
|
6
|
-
static getMap(type: string): ItemGraphMap<TraitInstance<any, any, any, any>>;
|
|
7
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { ItemGraphMap } from "../Maps/ItemGraphMap";
|
|
2
|
-
export class TraitInstanceMap {
|
|
3
|
-
static types = new Map();
|
|
4
|
-
static registerTrait(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 trait ${type} does not exist`);
|
|
13
|
-
return map;
|
|
14
|
-
}
|
|
15
|
-
}
|
package/Traits/TraitObservers.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Observable } from "@amodx/core/Observers";
|
|
2
|
-
export class TraitObservers {
|
|
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 { TraitInstance } from "./TraitInstance";
|
|
3
|
-
import { TraitData } from "./TraitData";
|
|
4
|
-
export interface TraitPipelines {
|
|
5
|
-
}
|
|
6
|
-
export declare class TraitPipelines<TraitSchema extends object = {}> {
|
|
7
|
-
private _disposed?;
|
|
8
|
-
private _toJSON?;
|
|
9
|
-
private _copy?;
|
|
10
|
-
get disposed(): Pipeline<TraitInstance<TraitSchema>>;
|
|
11
|
-
get toJSON(): Pipeline<TraitData<TraitSchema>>;
|
|
12
|
-
get copy(): Pipeline<TraitData<TraitSchema>>;
|
|
13
|
-
isDisposedSet(): boolean;
|
|
14
|
-
isToJSONSet(): boolean;
|
|
15
|
-
isCopySet(): boolean;
|
|
16
|
-
}
|
package/Traits/TraitPipelines.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { Pipeline } from "@amodx/core/Pipelines";
|
|
2
|
-
export class TraitPipelines {
|
|
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,16 +0,0 @@
|
|
|
1
|
-
import { ObjectSchemaInstance, Schema } from "@amodx/schemas";
|
|
2
|
-
import { TraitData, TraitRegisterData } from "./TraitData";
|
|
3
|
-
import { TraitInstance } from "./TraitInstance";
|
|
4
|
-
import { ItemPool } from "../Pools/ItemPool";
|
|
5
|
-
export declare class TraitPrototype<TraitSchema extends object = {}, Data extends Record<string, any> = {}, Logic extends Record<string, any> = {}, Shared extends Record<string, any> = {}> {
|
|
6
|
-
data: TraitRegisterData<TraitSchema, Data, Logic, Shared>;
|
|
7
|
-
schemaController: Schema<TraitSchema> | null;
|
|
8
|
-
baseContextSchema: TraitSchema;
|
|
9
|
-
pool: ItemPool<TraitInstance<TraitSchema, Data, Logic, Shared>>;
|
|
10
|
-
constructor(data: TraitRegisterData<TraitSchema, Data, Logic, Shared>);
|
|
11
|
-
getSchema(overrides: Partial<TraitSchema>): ObjectSchemaInstance<TraitSchema>;
|
|
12
|
-
private getPooled;
|
|
13
|
-
private return;
|
|
14
|
-
create(parent: TraitInstance["parent"], data: TraitData): TraitInstance<TraitSchema, Data, Logic, Shared>;
|
|
15
|
-
destory(instance: TraitInstance<TraitSchema, Data, Logic, Shared>): void;
|
|
16
|
-
}
|
package/Traits/TraitPrototype.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { Schema } from "@amodx/schemas";
|
|
2
|
-
import { TraitInstance } from "./TraitInstance";
|
|
3
|
-
import { TraitInstanceMap } from "./TraitInstanceMap";
|
|
4
|
-
import { ItemPool } from "../Pools/ItemPool";
|
|
5
|
-
export class TraitPrototype {
|
|
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 TraitInstance();
|
|
30
|
-
}
|
|
31
|
-
return(component) {
|
|
32
|
-
if (this.data.pool?.maxSize) {
|
|
33
|
-
return this.pool.addItem(component);
|
|
34
|
-
}
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
create(parent, data) {
|
|
38
|
-
const instance = this.getPooled();
|
|
39
|
-
instance.parent = parent;
|
|
40
|
-
if (this.data.schema && !instance.schema) {
|
|
41
|
-
instance.schema = this.getSchema(data.schema);
|
|
42
|
-
}
|
|
43
|
-
if (this.data.schema && instance.schema) {
|
|
44
|
-
instance.schema.getSchema().loadIn(this.data.schema);
|
|
45
|
-
}
|
|
46
|
-
if (this.data.logic) {
|
|
47
|
-
instance.logic = this.data.logic
|
|
48
|
-
? typeof this.data.logic == "function"
|
|
49
|
-
? this.data.logic(instance)
|
|
50
|
-
: structuredClone(this.data.logic)
|
|
51
|
-
: {};
|
|
52
|
-
}
|
|
53
|
-
if (this.data.data) {
|
|
54
|
-
instance.data = this.data.data
|
|
55
|
-
? typeof this.data.data == "function"
|
|
56
|
-
? this.data.data(instance)
|
|
57
|
-
: structuredClone(this.data.data)
|
|
58
|
-
: {};
|
|
59
|
-
}
|
|
60
|
-
if (data.state) {
|
|
61
|
-
instance.state = structuredClone(data.state);
|
|
62
|
-
}
|
|
63
|
-
const node = instance.getNode();
|
|
64
|
-
const map = TraitInstanceMap.getMap(data.type);
|
|
65
|
-
map.addNode(node, instance);
|
|
66
|
-
return instance;
|
|
67
|
-
}
|
|
68
|
-
destory(instance) {
|
|
69
|
-
const node = instance.getNode();
|
|
70
|
-
const map = TraitInstanceMap.getMap(instance.type);
|
|
71
|
-
map.removeNode(node, instance);
|
|
72
|
-
this.return(instance);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|