Home > @loopback/metadata > DecoratorFactory
DecoratorFactory class
Base factory class for decorator functions
Signature:
export declare class DecoratorFactory<T, // Type of the metadata spec for individual class/method/property/parameter
M extends T | MetadataMap<T> | MetadataMap<T[]>, // Type of the metadata
D extends DecoratorType>
Example
function classDecorator(spec: MySpec): ClassDecorator {
return ClassDecoratorFactory.createDecorator('my-key', spec);
}
or
function classDecorator(spec: MySpec): ClassDecorator {
const factory: ClassDecoratorFactory<MySpec>('my-key', spec);
return factory.create();
}
These functions above declare @classDecorator that can be used as follows:
@classDecorator({x: 1})
class MyController {}
Constructors
| Constructor | Modifiers | Description |
|---|---|---|
|
Construct a new class decorator factory |
Properties
| Property | Modifiers | Type | Description |
|---|---|---|---|
|
|
string | ||
|
|
string | ||
|
| |||
|
|
T | ||
|
|
string |
A constant to reference the target of a decoration |
Methods
| Method | Modifiers | Description |
|---|---|---|
|
|
Create a decorator function | |
|
| ||
|
| ||
|
Create a decorator function of the given type. Each sub class MUST implement this method. | ||
|
|
Base implementation of the decorator function | |
|
|
Create an error to report if the decorator is applied to the target more than once | |
|
|
Get the number of parameters for a given constructor or method | |
|
Get the optional decoration target of a given spec | ||
|
|
Get the qualified name of a decoration target. | |
|
|
Inherit metadata from base classes. By default, this method merges base metadata into the spec if | |
|
mergeWithInherited(inheritedMetadata, target, member, descriptorOrIndex) |
|
This method is called by the default implementation of the decorator function to merge the spec argument from the decoration with the inherited metadata for a class, all properties, all methods, or all method parameters that are decorated by this decorator. It MUST be overridden by subclasses to process inherited metadata. |
|
mergeWithOwn(ownMetadata, target, member, descriptorOrIndex) |
|
This method is called by the default implementation of the decorator function to merge the spec argument from the decoration with the own metadata for a class, all properties, all methods, or all method parameters that are decorated by this decorator. It MUST be overridden by subclasses to process own metadata. |
|
Set a reference to the target class or prototype for a given spec if it’s an object |