Class

Decoration

Decoration(flavouropt)

Constructor

# 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

sequenceDiagram participant C as Client participant D as Decoration participant R as FlavourResolver participant F as DecoratorFactory C->>D: new Decoration(flavour) C->>D: for(key) C->>D: define(decorators) D->>D: register(key, flavour, decorators) D->>F: decoratorFactory(key, flavour) F->>R: resolve(target) R-->>F: resolved flavour F->>F: apply decorators F-->>C: decorated target
Parameters:
Name Type Attributes Description
flavour string <optional>

Optional flavour parameter for the decorator context

View Source utils/Decoration.ts, line 50

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

View Source utils/Decoration.ts, line 56

# decorators

Set of decorators for the current context

.

Set of decorators for the current context

View Source utils/Decoration.ts, line 65

# extras

Set of additional decorators

.

Set of additional decorators

View Source utils/Decoration.ts, line 69

# flavourResolver

Resolver function that determines the appropriate flavour for a given target

Function to resolve flavour from a target

View Source utils/Decoration.ts, line 61

# key

Current decorator key

.

Current decorator key

View Source utils/Decoration.ts, line 73

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>

View Source utils/Decoration.ts, line 284

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

View Source utils/Decoration.ts, line 94

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

View Source utils/Decoration.ts, line 266

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

View Source utils/Decoration.ts, line 274

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

View Source utils/Decoration.ts, line 248

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

View Source utils/Decoration.ts, line 173

# 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

View Source utils/Decoration.ts, line 302