# new Decoration(flavouropt)
The Decoration class provides a builder pattern for creating and managing decorators with different flavours. It supports registering, extending, and applying decorators with context-aware flavour resolution. The class implements a fluent interface for defining, extending, and applying decorators with different flavours, allowing for framework-specific decorator implementations while maintaining a consistent API.
A decorator management class that handles flavoured decorators
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
flavour |
string
|
<optional> |
Optional flavour parameter for the decorator context |
Example
```typescript
// Create a new decoration for 'component' with default flavour
const componentDecorator = new Decoration()
.for('component')
.define(customComponentDecorator);
// Create a flavoured decoration
const vueComponent = new Decoration('vue')
.for('component')
.define(vueComponentDecorator);
// Apply the decoration
Classes
- Decoration
The Decoration class provides a builder pattern for creating and managing decorators with different flavours. It supports registering, extending, and applying decorators with context-aware flavour resolution. The class implements a fluent interface for defining, extending, and applying decorators with different flavours, allowing for framework-specific decorator implementations while maintaining a consistent API.
Members
# decorators
Stores all registered decorators organized by key and flavour
Static map of registered decorators
# flavourResolver
Resolver function that determines the appropriate flavour for a given target
Function to resolve flavour from a target
Methods
# apply(target, propertyKeyopt, descriptoropt) → {function}
Builds and returns the decorator factory function
Creates the final decorator function
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
target |
any
|
||
propertyKey |
any
|
<optional> |
|
descriptor |
TypedPropertyDescriptor.<any>
|
<optional> |
The generated decorator function
function
# decorate(addonopt, …decorators) → {this}
Internal method to add decorators with addon support
Adds decorators to the current context
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
addon |
boolean
|
<optional> |
false | Whether the decorators are addons |
decorators |
<repeatable> |
Array of decorators |
Current instance for chaining
this
# define(decorators)
Sets the primary decorators for the current context
Defines the base decorators
Parameters:
Name | Type | Description |
---|---|---|
decorators |
Decorators to define |
Builder instance for finishing the chain
# extend(decorators) → {DecorationBuilderBuild}
Adds additional decorators to the current context
Extends existing decorators
Parameters:
Name | Type | Description |
---|---|---|
decorators |
Additional decorators |
Builder instance for building the decorator
# for(key) → {DecorationBuilderMid}
Initializes a new decoration chain with the specified key
Sets the key for the decoration builder
Parameters:
Name | Type | Description |
---|---|---|
key |
string
|
The identifier for the decorator |
Builder instance for method chaining
# static register(key, flavour, decoratorsopt, extrasopt)
Internal method to store decorators in the static registry
Registers decorators for a specific key and flavour
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
key |
string
|
Decorator key |
|
flavour |
string
|
Decorator flavour |
|
decorators |
<optional> |
Primary decorators |
|
extras |
<optional> |
Additional decorators |
# static setFlavourResolver(resolver)
Configures the function used to determine decorator flavours
Sets the global flavour resolver
Parameters:
Name | Type | Description |
---|---|---|
resolver |
FlavourResolver
|
Function to resolve flavours |