feat(core): add support for @Property and @Event decorators
Example: @Directive({selector: 'my-selector'}) class MyDirective { @Property() prop; @Property('el-prop') prop2; @Event() event; @Event('el-event') event2; } Closes #3992
This commit is contained in:
@ -290,3 +290,24 @@ export function makeParamDecorator(annotationCls): any {
|
||||
ParamDecoratorFactory.prototype = Object.create(annotationCls.prototype);
|
||||
return ParamDecoratorFactory;
|
||||
}
|
||||
|
||||
export function makePropDecorator(decoratorCls): any {
|
||||
function PropDecoratorFactory(...args): any {
|
||||
var decoratorInstance = Object.create(decoratorCls.prototype);
|
||||
decoratorCls.apply(decoratorInstance, args);
|
||||
|
||||
if (this instanceof decoratorCls) {
|
||||
return decoratorInstance;
|
||||
} else {
|
||||
return function PropDecorator(target: any, name: string) {
|
||||
var meta = Reflect.getOwnMetadata('propMetadata', target.constructor);
|
||||
meta = meta || {};
|
||||
meta[name] = meta[name] || [];
|
||||
meta[name].unshift(decoratorInstance);
|
||||
Reflect.defineMetadata('propMetadata', meta, target.constructor);
|
||||
};
|
||||
}
|
||||
}
|
||||
PropDecoratorFactory.prototype = Object.create(decoratorCls.prototype);
|
||||
return PropDecoratorFactory;
|
||||
}
|
||||
|
Reference in New Issue
Block a user