Script Decorator
This file defines the Script
decorator, which is used to mark class methods as script methods in the @sodacore/core
library. It attaches metadata to methods, allowing them to be identified and managed as script commands with a specified name.
Features
- Script Method Registration: Marks methods as script methods with a custom name.
- Metadata Management: Collects and stores metadata about script methods for later retrieval.
Usage
typescript
import Script from './decorator/script';
class MyScriptClass {
@Script('customName')
myMethod() {
// This method is now registered as a script method with the name 'customName'
}
}
- Use
@Script(name)
on any method you want to register as a script method with the given name.
API
Script(name: string): MethodDecorator
- name: The name to associate with the script method.
- Returns: A method decorator that registers the method as a script method with the specified name.
How It Works
- Retrieves the current list of script methods from the class metadata.
- Adds the decorated method's property key and name to the list.
- Updates the metadata with the new list of script methods.
Notes
- Designed for use in classes that define script commands or actions.
- The metadata can be used by the framework to discover and invoke script methods by name.