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:
vsavkin
2015-09-03 15:10:48 -07:00
committed by Victor Savkin
parent 337ce21149
commit 896add7d77
19 changed files with 511 additions and 89 deletions

View File

@ -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;
}