Skip to content

Commit

Permalink
feat(util/decorators): add decorators caching
Browse files Browse the repository at this point in the history
  • Loading branch information
Hotell committed Jan 31, 2016
1 parent b081e66 commit 5c8e0e5
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/core/util/decorators.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -81,7 +80,8 @@ export function makeDecorator(

}

//DecoratorFactory.prototype = Object.create(annotationCls.prototype);
DecoratorFactory.prototype = Object.create(AnnotationCls.prototype);

return DecoratorFactory;

}
Expand Down Expand Up @@ -144,7 +144,7 @@ export function makeParamDecorator( annotationCls, overrideParamDecorator: Funct

}

//ParamDecoratorFactory.prototype = Object.create(annotationCls.prototype);
ParamDecoratorFactory.prototype = Object.create(annotationCls.prototype);

return ParamDecoratorFactory;

Expand All @@ -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;
Expand All @@ -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;

Expand Down

0 comments on commit 5c8e0e5

Please sign in to comment.