refactor(core): simplify decorators
Every decorator now is made of the following: - a function that can be used as a decorator or as a constructor. This function also can be used for `instanceof` checks. - a type for this function (callable and newable) - a type that describes the shape of the data that the user needs to pass to the decorator as well as the instance of the metadata The docs for decorators live at the followig places so that IDEs can discover them correctly: - General description of the decorator is placed on the `...Decorator` interface on the callable function definition - Property descriptions are placed on the interface that describes the metadata produces by the decorator
This commit is contained in:
@ -8,33 +8,33 @@
|
||||
|
||||
import {makeDecorator, makeParamDecorator, makePropDecorator} from '@angular/core/src/util/decorators';
|
||||
|
||||
export class ClassDecoratorMeta {
|
||||
constructor(public value: any /** TODO #9100 */) {}
|
||||
export interface ClassDecoratorFactory {
|
||||
(data: ClassDecorator): any;
|
||||
new (data: ClassDecorator): ClassDecorator;
|
||||
}
|
||||
|
||||
export class ParamDecoratorMeta {
|
||||
constructor(public value: any /** TODO #9100 */) {}
|
||||
}
|
||||
export interface ClassDecorator { value: any; }
|
||||
|
||||
export class PropDecoratorMeta {
|
||||
constructor(public value: any /** TODO #9100 */) {}
|
||||
}
|
||||
export interface ParamDecorator { value: any; }
|
||||
|
||||
export interface PropDecorator { value: any; }
|
||||
|
||||
export function classDecorator(value: any /** TODO #9100 */) {
|
||||
return new ClassDecoratorMeta(value);
|
||||
return new ClassDecorator({value: value});
|
||||
}
|
||||
|
||||
export function paramDecorator(value: any /** TODO #9100 */) {
|
||||
return new ParamDecoratorMeta(value);
|
||||
return new ParamDecorator(value);
|
||||
}
|
||||
|
||||
export function propDecorator(value: any /** TODO #9100 */) {
|
||||
return new PropDecoratorMeta(value);
|
||||
return new PropDecorator(value);
|
||||
}
|
||||
|
||||
/** @Annotation */ export var ClassDecorator = makeDecorator(ClassDecoratorMeta);
|
||||
/** @Annotation */ export var ParamDecorator = makeParamDecorator(ParamDecoratorMeta);
|
||||
/** @Annotation */ export var PropDecorator = makePropDecorator(PropDecoratorMeta);
|
||||
/** @Annotation */ export const ClassDecorator =
|
||||
<ClassDecoratorFactory>makeDecorator({value: undefined});
|
||||
/** @Annotation */ export const ParamDecorator = makeParamDecorator([['value', undefined]]);
|
||||
/** @Annotation */ export const PropDecorator = makePropDecorator([['value', undefined]]);
|
||||
|
||||
// used only in Dart
|
||||
export class HasGetterAndSetterDecorators {}
|
||||
|
@ -20,7 +20,7 @@ class AType {
|
||||
constructor(value: any /** TODO #9100 */) { this.value = value; }
|
||||
}
|
||||
|
||||
@ClassDecorator('class')
|
||||
@ClassDecorator({value: 'class'})
|
||||
class ClassWithDecorators {
|
||||
@PropDecorator('p1') @PropDecorator('p2') a: any /** TODO #9100 */;
|
||||
b: any /** TODO #9100 */;
|
||||
|
Reference in New Issue
Block a user