Get started with reflect-metadata CDN
Apache-2.0 licensed
Reflect-Metadata is a library that provides decorators and metadata reflection capabilities for JS classes and properties.
Tags:- decorator
- metadata
- javascript
- reflect
Stable version
Copied!
How to start using reflect-metadata CDN
import { createConnection, getConnectionOptions, Connection } from 'typeorm';
import { ReflectMetadataFactory } from 'reflect-metadata';
import * as Reflect from 'reflect-metadata/Reflect.min';
@ReflectMetadata('decoratorKey', { name: 'myDecorator', mode: Reflect.ParameterMode.AFTER, position: 0 })
class MyClass {
constructor(private myDependency: string) {}
}
const connectionOptions = getConnectionOptions();
createConnection(connectionOptions).then(async connection => {
const metadataFactory = new ReflectMetadataFactory();
Reflect.decorate(MyClass, [
Reflect.paramDecorator('myDecorator', (data: any, key: PropertyKey, object: Function) => {
return function(target: Object, propertyKey: PropertyKey, index: number) {
Reflect.defineMetadata('myDecoratorKey', data, target, propertyKey);
};
}),
]);
const myInstance = new MyClass('dependencyValue');
const myPropertyValue = Reflect.getMetadata('myDecoratorKey', MyClass.prototype, 'constructor')[0];
console.log('MyClass instance:', myInstance);
console.log('MyClass decorator value:', myPropertyValue);
await connection.close();
});
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!