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)](/doc/en/lb4/apidocs.metadata.decoratorfactory._constructor_.html) | Construct a new class decorator factory |
Properties
| Property | Modifiers | Type | Description |
|---|---|---|---|
| [decoratorName](/doc/en/lb4/apidocs.metadata.decoratorfactory.decoratorname.html) | `protected` | string | |
| [key](/doc/en/lb4/apidocs.metadata.decoratorfactory.key.html) | `protected` | string | |
| [options](/doc/en/lb4/apidocs.metadata.decoratorfactory.options.html) | `protected` | [DecoratorOptions](/doc/en/lb4/apidocs.metadata.decoratoroptions.html) | |
| [spec](/doc/en/lb4/apidocs.metadata.decoratorfactory.spec.html) | `protected` | T | |
| [TARGET](/doc/en/lb4/apidocs.metadata.decoratorfactory.target.html) | `static` | string | A constant to reference the target of a decoration |
Methods
| Method | Modifiers | Description |
|---|---|---|
| [\_createDecorator(key, spec, options)](/doc/en/lb4/apidocs.metadata.decoratorfactory._createdecorator.html) | `protected` `static` | Create a decorator function |
| [allowInheritance()](/doc/en/lb4/apidocs.metadata.decoratorfactory.allowinheritance.html) | `protected` | |
| [cloneDeep(val)](/doc/en/lb4/apidocs.metadata.decoratorfactory.clonedeep.html) | `static` | |
| [create()](/doc/en/lb4/apidocs.metadata.decoratorfactory.create.html) | Create a decorator function of the given type. Each sub class MUST implement this method. | |
| [decorate(target, member, descriptorOrIndex)](/doc/en/lb4/apidocs.metadata.decoratorfactory.decorate.html) | `protected` | Base implementation of the decorator function |
| [duplicateDecorationError(target, member, descriptorOrIndex)](/doc/en/lb4/apidocs.metadata.decoratorfactory.duplicatedecorationerror.html) | `protected` | Create an error to report if the decorator is applied to the target more than once |
| [getNumberOfParameters(target, member)](/doc/en/lb4/apidocs.metadata.decoratorfactory.getnumberofparameters.html) | `static` | Get the number of parameters for a given constructor or method |
| [getTarget(spec)](/doc/en/lb4/apidocs.metadata.decoratorfactory.gettarget.html) | Get the optional decoration target of a given spec | |
| [getTargetName(target, member, descriptorOrIndex)](/doc/en/lb4/apidocs.metadata.decoratorfactory.gettargetname.html) | `static` | Get the qualified name of a decoration target. |
| [inherit(inheritedMetadata)](/doc/en/lb4/apidocs.metadata.decoratorfactory.inherit.html) | `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)](/doc/en/lb4/apidocs.metadata.decoratorfactory.mergewithinherited.html) | `protected` | 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)](/doc/en/lb4/apidocs.metadata.decoratorfactory.mergewithown.html) | `protected` | 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. |
| [withTarget(spec, target)](/doc/en/lb4/apidocs.metadata.decoratorfactory.withtarget.html) | Set a reference to the target class or prototype for a given spec if it's an object |