forked from playcanvas/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregistry.js
More file actions
55 lines (48 loc) · 1.44 KB
/
registry.js
File metadata and controls
55 lines (48 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
* @class
* @name ComponentSystemRegistry
* @classdesc Store, access and delete instances of the various ComponentSystems.
* @description Create a new ComponentSystemRegistry.
*/
class ComponentSystemRegistry {
constructor() {
// An array of pc.ComponentSystem objects
this.list = [];
}
/**
* @private
* @function
* @name ComponentSystemRegistry#add
* @description Add a component system to the registry.
* @param {object} system - The {@link ComponentSystem} instance.
*/
add(system) {
var id = system.id;
if (this[id]) {
throw new Error("ComponentSystem name '" + id + "' already registered or not allowed");
}
this[id] = system;
// Update the component system array
this.list.push(system);
}
/**
* @private
* @function
* @name ComponentSystemRegistry#remove
* @description Remove a component system from the registry.
* @param {object} system - The {@link ComponentSystem} instance.
*/
remove(system) {
var id = system.id;
if (!this[id]) {
throw new Error("No ComponentSystem named '" + id + "' registered");
}
delete this[id];
// Update the component system array
var index = this.list.indexOf(this[id]);
if (index !== -1) {
this.list.splice(index, 1);
}
}
}
export { ComponentSystemRegistry };