Skip to main content
Module

x/mandarinets/main-core/reflectMetadata.ts>Reflect.decorate

Mandarine.TS is a typescript, decorator-driven framework that allows you to create server-side applications. Mandarine.TS provides a range of built-in solutions such as Dependency Injection, Components, ORM and more. Under its umbrella, Mandarine.TS has 4 modules: Core, Data, Security and MVC, these modules will offer you the requirements to build a Mandarine-powered application.
Latest
function Reflect.decorate
import { Reflect } from "https://deno.land/x/mandarinets@v2.3.2/main-core/reflectMetadata.ts";
const { decorate } = Reflect;

Applies a set of decorators to a target object.

Examples

class Example { }

// constructor Example = Reflect.decorate(decoratorsArray, Example);

Parameters

decorators: ClassDecorator[]

An array of decorators.

target: Function

The target object.

Returns

Function

The result of applying the provided decorators.

Applies a set of decorators to a property of a target object.

Examples

class Example { // property declarations are not part of ES6, though they are valid in TypeScript: // static staticProperty; // property;

static staticMethod() { } method() { } }

// property (on constructor)
Reflect.decorate(decoratorsArray, Example, "staticProperty");

// property (on prototype)
Reflect.decorate(decoratorsArray, Example.prototype, "property");

// method (on constructor)
Object.defineProperty(Example, "staticMethod",
    Reflect.decorate(decoratorsArray, Example, "staticMethod",
        Object.getOwnPropertyDescriptor(Example, "staticMethod")));

// method (on prototype)
Object.defineProperty(Example.prototype, "method",
    Reflect.decorate(decoratorsArray, Example.prototype, "method",
        Object.getOwnPropertyDescriptor(Example.prototype, "method")));

Parameters

decorators: (PropertyDecorator | MethodDecorator)[]

An array of decorators.

target: any

The target object.

propertyKey: string | symbol

The property key to decorate.

optional
attributes: PropertyDescriptor | null

A property descriptor.

Returns

PropertyDescriptor | undefined

Applies a set of decorators to a property of a target object.

Examples

class Example { // property declarations are not part of ES6, though they are valid in TypeScript: // static staticProperty; // property;

static staticMethod() { } method() { } }

// property (on constructor)
Reflect.decorate(decoratorsArray, Example, "staticProperty");

// property (on prototype)
Reflect.decorate(decoratorsArray, Example.prototype, "property");

// method (on constructor)
Object.defineProperty(Example, "staticMethod",
    Reflect.decorate(decoratorsArray, Example, "staticMethod",
        Object.getOwnPropertyDescriptor(Example, "staticMethod")));

// method (on prototype)
Object.defineProperty(Example.prototype, "method",
    Reflect.decorate(decoratorsArray, Example.prototype, "method",
        Object.getOwnPropertyDescriptor(Example.prototype, "method")));

Parameters

decorators: (PropertyDecorator | MethodDecorator)[]

An array of decorators.

target: any

The target object.

propertyKey: string | symbol

The property key to decorate.

attributes: PropertyDescriptor

A property descriptor.

Returns

PropertyDescriptor