From 5c8e0e59ce788d53dc1798a5d86110afa617f6be Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Sun, 31 Jan 2016 21:14:41 +0100 Subject: [PATCH] feat(util/decorators): add decorators caching --- src/core/util/decorators.ts | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/core/util/decorators.ts b/src/core/util/decorators.ts index f173491..5fff2d9 100644 --- a/src/core/util/decorators.ts +++ b/src/core/util/decorators.ts @@ -1,8 +1,7 @@ -import {global, Type, isFunction, isString, isPresent} from '../../facade/lang'; -import {reflector} from '../reflection/reflection'; -import {InjectableMetadata} from '../di/metadata'; -import {stringify} from '../../facade/lang'; -import {globalKeyRegistry} from '../di/key'; +import { Type, isFunction, isPresent } from '../../facade/lang'; +import { reflector } from '../reflection/reflection'; +import { InjectableMetadata } from '../di/metadata'; +import { globalKeyRegistry } from '../di/key'; /** * An interface implemented by all Angular type decorators, @@ -81,7 +80,8 @@ export function makeDecorator( } - //DecoratorFactory.prototype = Object.create(annotationCls.prototype); + DecoratorFactory.prototype = Object.create(AnnotationCls.prototype); + return DecoratorFactory; } @@ -144,7 +144,7 @@ export function makeParamDecorator( annotationCls, overrideParamDecorator: Funct } - //ParamDecoratorFactory.prototype = Object.create(annotationCls.prototype); + ParamDecoratorFactory.prototype = Object.create(annotationCls.prototype); return ParamDecoratorFactory; @@ -157,6 +157,9 @@ export function makePropDecorator( decoratorCls ): any { var decoratorInstance = Object.create( decoratorCls.prototype ); decoratorCls.apply( decoratorInstance, args ); + // check if this decorator was already invoked + // - if it was return it again, just with newly applied arguments + // - this is possible thanks to PropDecoratorFactory.prototype = Object.create(decoratorCls.prototype); if ( this instanceof decoratorCls ) { return decoratorInstance; @@ -173,14 +176,14 @@ export function makePropDecorator( decoratorCls ): any { reflector.registerPropMetadata(meta,target.constructor); - }; } } - //PropDecoratorFactory.prototype = Object.create(decoratorCls.prototype); + // caching + PropDecoratorFactory.prototype = Object.create(decoratorCls.prototype); return PropDecoratorFactory;