Page Contents
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 |
---|---|---|
(constructor)(key, spec, options) | Construct a new class decorator factory |
Properties
Property | Modifiers | Type | Description |
---|---|---|---|
decoratorName | protected |
string | |
key | protected |
string | |
options | protected |
DecoratorOptions | |
spec | protected |
T | |
TARGET | static |
string | A constant to reference the target of a decoration |
Methods
Method | Modifiers | Description |
---|---|---|
_createDecorator(key, spec, options) | <p>protected </p><p>static </p> |
Create a decorator function |
allowInheritance() | protected |
|
cloneDeep(val) | static |
|
create() | Create a decorator function of the given type. Each sub class MUST implement this method. | |
decorate(target, member, descriptorOrIndex) | protected |
Base implementation of the decorator function |
duplicateDecorationError(target, member, descriptorOrIndex) | protected |
Create an error to report if the decorator is applied to the target more than once |
getNumberOfParameters(target, member) | static |
Get the number of parameters for a given constructor or method |
getTarget(spec) | Get the optional decoration target of a given spec | |
getTargetName(target, member, descriptorOrIndex) | static |
Get the qualified name of a decoration target. |
inherit(inheritedMetadata) | protected |
Inherit metadata from base classes. By default, this method merges base metadata into the spec if allowInheritance is set to true . To customize the behavior, this method can be overridden by sub classes. |
mergeWithInherited(inheritedMetadata, target, member, descriptorOrIndex) | protected |
<p>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.</p><p>It MUST be overridden by subclasses to process inherited metadata.</p> |
mergeWithOwn(ownMetadata, target, member, descriptorOrIndex) | protected |
<p>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.</p><p>It MUST be overridden by subclasses to process own metadata.</p> |
withTarget(spec, target) | Set a reference to the target class or prototype for a given spec if it’s an object |