Registry class for managing different classes.
Kind: global class
- Registry
- new Registry(config)
- instance
- .createInstance(name, args, baseClass) ⇒
Object - .isValidClass(targetClass, baseClass) ⇒
boolean - .isValidInstance(instance, baseClass) ⇒
boolean - .ingest(source)
- .setWith(name, targetClass, baseClass, override)
- .set(name, targetClass, override)
- .setMany(classes, override)
- .get(name, defaultValue) ⇒
function|null - .has(name) ⇒
boolean - .remove(name)
- .removeAll()
- .destroy()
- .createInstance(name, args, baseClass) ⇒
- static
Create a new Registry instance.
| Param | Type | Description |
|---|---|---|
| config | Object |
Configuration object. |
| config.classes | Object |
Initial set of classes. |
Create an instance of a class.
Kind: instance method of Registry
Returns: Object - An instance of the class.
| Param | Type | Description |
|---|---|---|
| name | string |
The name of the class to instantiate. |
| args | Array |
The arguments to pass to the class constructor. |
| baseClass | function |
The base class for validation. |
Check if a class is valid.
Kind: instance method of Registry
Returns: boolean - Whether the class is valid.
| Param | Type | Description |
|---|---|---|
| targetClass | function |
The class to check. |
| baseClass | function |
The base class for validation. |
Check if an instance is valid.
Kind: instance method of Registry
Returns: boolean - Whether the instance is valid.
| Param | Type | Description |
|---|---|---|
| instance | Object |
The instance to check. |
| baseClass | function |
The base class for validation. |
Ingest classes from a source.
Kind: instance method of Registry
| Param | Type | Description |
|---|---|---|
| source | Object |
The source object. |
Register a class with additional validation.
Kind: instance method of Registry
| Param | Type | Default | Description |
|---|---|---|---|
| name | string |
The name of the class. | |
| targetClass | function |
The class to register. | |
| baseClass | function |
The base class for validation. | |
| override | boolean |
false |
Whether to override existing class. |
Register a class.
Kind: instance method of Registry
| Param | Type | Default | Description |
|---|---|---|---|
| name | string |
The name of the class. | |
| targetClass | function |
The class to register. | |
| override | boolean |
true |
Whether to override existing class. |
Register multiple classes.
Kind: instance method of Registry
| Param | Type | Default | Description |
|---|---|---|---|
| classes | Object |
An object mapping names to classes. | |
| override | boolean |
false |
Whether to override existing classes. |
Retrieve a class by name.
Kind: instance method of Registry
Returns: function | null - The class or null.
| Param | Type | Default | Description |
|---|---|---|---|
| name | string |
The name of the class. | |
| defaultValue | * |
|
The default value if the class does not exist. |
Check if a class exists by name.
Kind: instance method of Registry
Returns: boolean - Whether the class exists.
| Param | Type | Description |
|---|---|---|
| name | string |
The name of the class. |
Removes a specific class from the registry.
Kind: instance method of Registry
| Param | Type | Description |
|---|---|---|
| name | string |
The name of the class to be removed from the registry. |
Removes all classes from the registry.
Kind: instance method of Registry
Destroys the registry by deleting all properties of the classes object. This method ensures that all class references in the registry are cleared, potentially allowing them to be garbage collected if there are no other references to them.
Kind: instance method of Registry
Registry.get(config) ⇒ Registry
Static method to get a Registry instance.
Kind: static method of Registry
Returns: Registry - A Registry instance.
| Param | Type | Description |
|---|---|---|
| config | Object |
Configuration object or existing Registry instance. |