refactor(decorators): cleanup
This commit is contained in:
parent
8cd97c2054
commit
b6746cce9c
|
@ -86,9 +86,7 @@ export var LIFECYCLE_HOOKS_VALUES = [
|
|||
* ```
|
||||
* @stable
|
||||
*/
|
||||
export abstract class OnChanges {
|
||||
abstract ngOnChanges(changes: SimpleChanges): any /** TODO #9100 */;
|
||||
}
|
||||
export abstract class OnChanges { abstract ngOnChanges(changes: SimpleChanges): void; }
|
||||
|
||||
/**
|
||||
* Implement this interface to execute custom initialization logic after your directive's
|
||||
|
@ -132,7 +130,7 @@ export abstract class OnChanges {
|
|||
* ```
|
||||
* @stable
|
||||
*/
|
||||
export abstract class OnInit { abstract ngOnInit(): any /** TODO #9100 */; }
|
||||
export abstract class OnInit { abstract ngOnInit(): void; }
|
||||
|
||||
/**
|
||||
* Implement this interface to supplement the default change detection algorithm in your directive.
|
||||
|
@ -201,7 +199,7 @@ export abstract class OnInit { abstract ngOnInit(): any /** TODO #9100 */; }
|
|||
* ```
|
||||
* @stable
|
||||
*/
|
||||
export abstract class DoCheck { abstract ngDoCheck(): any /** TODO #9100 */; }
|
||||
export abstract class DoCheck { abstract ngDoCheck(): void; }
|
||||
|
||||
/**
|
||||
* Implement this interface to get notified when your directive is destroyed.
|
||||
|
@ -293,7 +291,7 @@ export abstract class DoCheck { abstract ngDoCheck(): any /** TODO #9100 */; }
|
|||
*
|
||||
* @stable
|
||||
*/
|
||||
export abstract class OnDestroy { abstract ngOnDestroy(): any /** TODO #9100 */; }
|
||||
export abstract class OnDestroy { abstract ngOnDestroy(): void; }
|
||||
|
||||
/**
|
||||
* Implement this interface to get notified when your directive's content has been fully
|
||||
|
@ -347,7 +345,7 @@ export abstract class OnDestroy { abstract ngOnDestroy(): any /** TODO #9100 */;
|
|||
* ```
|
||||
* @stable
|
||||
*/
|
||||
export abstract class AfterContentInit { abstract ngAfterContentInit(): any /** TODO #9100 */; }
|
||||
export abstract class AfterContentInit { abstract ngAfterContentInit(): void; }
|
||||
|
||||
/**
|
||||
* Implement this interface to get notified after every check of your directive's content.
|
||||
|
@ -396,9 +394,7 @@ export abstract class AfterContentInit { abstract ngAfterContentInit(): any /**
|
|||
* ```
|
||||
* @stable
|
||||
*/
|
||||
export abstract class AfterContentChecked {
|
||||
abstract ngAfterContentChecked(): any /** TODO #9100 */;
|
||||
}
|
||||
export abstract class AfterContentChecked { abstract ngAfterContentChecked(): void; }
|
||||
|
||||
/**
|
||||
* Implement this interface to get notified when your component's view has been fully initialized.
|
||||
|
@ -446,7 +442,7 @@ export abstract class AfterContentChecked {
|
|||
* ```
|
||||
* @stable
|
||||
*/
|
||||
export abstract class AfterViewInit { abstract ngAfterViewInit(): any /** TODO #9100 */; }
|
||||
export abstract class AfterViewInit { abstract ngAfterViewInit(): void; }
|
||||
|
||||
/**
|
||||
* Implement this interface to get notified after every check of your component's view.
|
||||
|
@ -497,4 +493,4 @@ export abstract class AfterViewInit { abstract ngAfterViewInit(): any /** TODO #
|
|||
* ```
|
||||
* @stable
|
||||
*/
|
||||
export abstract class AfterViewChecked { abstract ngAfterViewChecked(): any /** TODO #9100 */; }
|
||||
export abstract class AfterViewChecked { abstract ngAfterViewChecked(): void; }
|
||||
|
|
|
@ -103,24 +103,24 @@ function applyParams(fnOrArray: (Function | any[]), key: string): Function {
|
|||
if (isFunction(fnOrArray)) {
|
||||
return <Function>fnOrArray;
|
||||
} else if (fnOrArray instanceof Array) {
|
||||
var annotations: any[] = fnOrArray;
|
||||
var fn: Function = fnOrArray[fnOrArray.length - 1];
|
||||
const annotations: any[] = fnOrArray;
|
||||
const annoLength = annotations.length - 1;
|
||||
const fn: Function = fnOrArray[annoLength];
|
||||
if (!isFunction(fn)) {
|
||||
throw new Error(
|
||||
`Last position of Class method array must be Function in key ${key} was '${stringify(fn)}'`);
|
||||
}
|
||||
var annoLength = annotations.length - 1;
|
||||
if (annoLength != fn.length) {
|
||||
throw new Error(
|
||||
`Number of annotations (${annoLength}) does not match number of arguments (${fn.length}) in the function: ${stringify(fn)}`);
|
||||
}
|
||||
var paramsAnnotations: any[][] = [];
|
||||
for (var i = 0, ii = annotations.length - 1; i < ii; i++) {
|
||||
var paramAnnotations: any[] = [];
|
||||
const paramsAnnotations: any[][] = [];
|
||||
for (let i = 0, ii = annotations.length - 1; i < ii; i++) {
|
||||
const paramAnnotations: any[] = [];
|
||||
paramsAnnotations.push(paramAnnotations);
|
||||
var annotation = annotations[i];
|
||||
const annotation = annotations[i];
|
||||
if (annotation instanceof Array) {
|
||||
for (var j = 0; j < annotation.length; j++) {
|
||||
for (let j = 0; j < annotation.length; j++) {
|
||||
paramAnnotations.push(extractAnnotation(annotation[j]));
|
||||
}
|
||||
} else if (isFunction(annotation)) {
|
||||
|
@ -220,9 +220,9 @@ function applyParams(fnOrArray: (Function | any[]), key: string): Function {
|
|||
* @stable
|
||||
*/
|
||||
export function Class(clsDef: ClassDefinition): ConcreteType<any> {
|
||||
var constructor = applyParams(
|
||||
const constructor = applyParams(
|
||||
clsDef.hasOwnProperty('constructor') ? clsDef.constructor : undefined, 'constructor');
|
||||
var proto = constructor.prototype;
|
||||
let proto = constructor.prototype;
|
||||
if (clsDef.hasOwnProperty('extends')) {
|
||||
if (isFunction(clsDef.extends)) {
|
||||
(<Function>constructor).prototype = proto =
|
||||
|
@ -232,7 +232,7 @@ export function Class(clsDef: ClassDefinition): ConcreteType<any> {
|
|||
`Class definition 'extends' property must be a constructor function was: ${stringify(clsDef.extends)}`);
|
||||
}
|
||||
}
|
||||
for (var key in clsDef) {
|
||||
for (let key in clsDef) {
|
||||
if (key != 'extends' && key != 'prototype' && clsDef.hasOwnProperty(key)) {
|
||||
proto[key] = applyParams(<any>clsDef[key], key);
|
||||
}
|
||||
|
@ -243,7 +243,7 @@ export function Class(clsDef: ClassDefinition): ConcreteType<any> {
|
|||
}
|
||||
|
||||
if (!constructor['name']) {
|
||||
(constructor as any /** TODO #9100 */)['overriddenName'] = `class${_nextClassId++}`;
|
||||
(constructor as any)['overriddenName'] = `class${_nextClassId++}`;
|
||||
}
|
||||
|
||||
return <ConcreteType<any>>constructor;
|
||||
|
@ -258,21 +258,18 @@ var Reflect = global.Reflect;
|
|||
}
|
||||
})();
|
||||
|
||||
export function makeDecorator(
|
||||
annotationCls: any /* TODO #9100 */,
|
||||
chainFn: (fn: Function) => void = null): (...args: any[]) => (cls: any) => any {
|
||||
function DecoratorFactory(objOrType: any /** TODO #9100 */): (cls: any) => any {
|
||||
var annotationInstance = new (<any>annotationCls)(objOrType);
|
||||
export function makeDecorator(annotationCls: any, chainFn: (fn: Function) => void = null):
|
||||
(...args: any[]) => (cls: any) => any {
|
||||
function DecoratorFactory(objOrType: any): (cls: any) => any {
|
||||
const annotationInstance = new (<any>annotationCls)(objOrType);
|
||||
if (this instanceof annotationCls) {
|
||||
return annotationInstance;
|
||||
} else {
|
||||
var chainAnnotation =
|
||||
const chainAnnotation =
|
||||
isFunction(this) && this.annotations instanceof Array ? this.annotations : [];
|
||||
chainAnnotation.push(annotationInstance);
|
||||
var TypeDecorator: TypeDecorator =
|
||||
<TypeDecorator>function TypeDecorator(cls: any /** TODO #9100 */) {
|
||||
var annotations = Reflect.getOwnMetadata('annotations', cls);
|
||||
annotations = annotations || [];
|
||||
const TypeDecorator: TypeDecorator = <TypeDecorator>function TypeDecorator(cls: Type) {
|
||||
const annotations = Reflect.getOwnMetadata('annotations', cls) || [];
|
||||
annotations.push(annotationInstance);
|
||||
Reflect.defineMetadata('annotations', annotations, cls);
|
||||
return cls;
|
||||
|
@ -288,8 +285,8 @@ export function makeDecorator(
|
|||
return DecoratorFactory;
|
||||
}
|
||||
|
||||
export function makeParamDecorator(annotationCls: any /** TODO #9100 */): any {
|
||||
function ParamDecoratorFactory(...args: any[] /** TODO #9100 */): any {
|
||||
export function makeParamDecorator(annotationCls: any): any {
|
||||
function ParamDecoratorFactory(...args: any[]): any {
|
||||
var annotationInstance = Object.create(annotationCls.prototype);
|
||||
annotationCls.apply(annotationInstance, args);
|
||||
if (this instanceof annotationCls) {
|
||||
|
@ -300,11 +297,8 @@ export function makeParamDecorator(annotationCls: any /** TODO #9100 */): any {
|
|||
}
|
||||
|
||||
|
||||
function ParamDecorator(
|
||||
cls: any /** TODO #9100 */, unusedKey: any /** TODO #9100 */,
|
||||
index: any /** TODO #9100 */): any {
|
||||
var parameters: any[][] = Reflect.getMetadata('parameters', cls);
|
||||
parameters = parameters || [];
|
||||
function ParamDecorator(cls: any, unusedKey: any, index: number): any {
|
||||
const parameters: any[][] = Reflect.getMetadata('parameters', cls) || [];
|
||||
|
||||
// there might be gaps if some in between parameters do not have annotations.
|
||||
// we pad with nulls.
|
||||
|
@ -325,8 +319,8 @@ export function makeParamDecorator(annotationCls: any /** TODO #9100 */): any {
|
|||
return ParamDecoratorFactory;
|
||||
}
|
||||
|
||||
export function makePropDecorator(annotationCls: any /** TODO #9100 */): any {
|
||||
function PropDecoratorFactory(...args: any[] /** TODO #9100 */): any {
|
||||
export function makePropDecorator(annotationCls: any): any {
|
||||
function PropDecoratorFactory(...args: any[]): any {
|
||||
var decoratorInstance = Object.create(annotationCls.prototype);
|
||||
annotationCls.apply(decoratorInstance, args);
|
||||
|
||||
|
@ -334,8 +328,7 @@ export function makePropDecorator(annotationCls: any /** TODO #9100 */): any {
|
|||
return decoratorInstance;
|
||||
} else {
|
||||
return function PropDecorator(target: any, name: string) {
|
||||
var meta = Reflect.getOwnMetadata('propMetadata', target.constructor);
|
||||
meta = meta || {};
|
||||
const meta = Reflect.getOwnMetadata('propMetadata', target.constructor) || {};
|
||||
meta[name] = meta[name] || [];
|
||||
meta[name].unshift(decoratorInstance);
|
||||
Reflect.defineMetadata('propMetadata', meta, target.constructor);
|
||||
|
|
|
@ -7,22 +7,22 @@ export declare class AbstractProviderError extends BaseException {
|
|||
|
||||
/** @stable */
|
||||
export declare abstract class AfterContentChecked {
|
||||
abstract ngAfterContentChecked(): any;
|
||||
abstract ngAfterContentChecked(): void;
|
||||
}
|
||||
|
||||
/** @stable */
|
||||
export declare abstract class AfterContentInit {
|
||||
abstract ngAfterContentInit(): any;
|
||||
abstract ngAfterContentInit(): void;
|
||||
}
|
||||
|
||||
/** @stable */
|
||||
export declare abstract class AfterViewChecked {
|
||||
abstract ngAfterViewChecked(): any;
|
||||
abstract ngAfterViewChecked(): void;
|
||||
}
|
||||
|
||||
/** @stable */
|
||||
export declare abstract class AfterViewInit {
|
||||
abstract ngAfterViewInit(): any;
|
||||
abstract ngAfterViewInit(): void;
|
||||
}
|
||||
|
||||
/** @experimental */
|
||||
|
@ -686,7 +686,7 @@ export declare function disposePlatform(): void;
|
|||
|
||||
/** @stable */
|
||||
export declare abstract class DoCheck {
|
||||
abstract ngDoCheck(): any;
|
||||
abstract ngDoCheck(): void;
|
||||
}
|
||||
|
||||
/** @deprecated */
|
||||
|
@ -972,17 +972,17 @@ export declare class NoProviderError extends AbstractProviderError {
|
|||
|
||||
/** @stable */
|
||||
export declare abstract class OnChanges {
|
||||
abstract ngOnChanges(changes: SimpleChanges): any;
|
||||
abstract ngOnChanges(changes: SimpleChanges): void;
|
||||
}
|
||||
|
||||
/** @stable */
|
||||
export declare abstract class OnDestroy {
|
||||
abstract ngOnDestroy(): any;
|
||||
abstract ngOnDestroy(): void;
|
||||
}
|
||||
|
||||
/** @stable */
|
||||
export declare abstract class OnInit {
|
||||
abstract ngOnInit(): any;
|
||||
abstract ngOnInit(): void;
|
||||
}
|
||||
|
||||
/** @stable */
|
||||
|
|
Loading…
Reference in New Issue