refactor(RuntimeMetadata): Annotation -> Metadata

This commit is contained in:
Victor Berchet 2015-10-23 15:55:48 -07:00
parent e1e52c098b
commit abdd524911
1 changed files with 20 additions and 20 deletions

View File

@ -10,7 +10,7 @@ import {
import {BaseException} from 'angular2/src/core/facade/exceptions'; import {BaseException} from 'angular2/src/core/facade/exceptions';
import {MapWrapper, StringMapWrapper, ListWrapper} from 'angular2/src/core/facade/collection'; import {MapWrapper, StringMapWrapper, ListWrapper} from 'angular2/src/core/facade/collection';
import * as cpl from './directive_metadata'; import * as cpl from './directive_metadata';
import * as dirAnn from 'angular2/src/core/metadata/directives'; import * as md from 'angular2/src/core/metadata/directives';
import {DirectiveResolver} from 'angular2/src/core/linker/directive_resolver'; import {DirectiveResolver} from 'angular2/src/core/linker/directive_resolver';
import {ViewResolver} from 'angular2/src/core/linker/view_resolver'; import {ViewResolver} from 'angular2/src/core/linker/view_resolver';
import {ViewMetadata} from 'angular2/src/core/metadata/view'; import {ViewMetadata} from 'angular2/src/core/metadata/view';
@ -33,35 +33,35 @@ export class RuntimeMetadataResolver {
getMetadata(directiveType: Type): cpl.CompileDirectiveMetadata { getMetadata(directiveType: Type): cpl.CompileDirectiveMetadata {
var meta = this._cache.get(directiveType); var meta = this._cache.get(directiveType);
if (isBlank(meta)) { if (isBlank(meta)) {
var directiveAnnotation = this._directiveResolver.resolve(directiveType); var dirMeta = this._directiveResolver.resolve(directiveType);
var moduleUrl = calcModuleUrl(directiveType, directiveAnnotation); var moduleUrl = calcModuleUrl(directiveType, dirMeta);
var templateMeta = null; var templateMeta = null;
var changeDetectionStrategy = null; var changeDetectionStrategy = null;
if (directiveAnnotation instanceof dirAnn.ComponentMetadata) { if (dirMeta instanceof md.ComponentMetadata) {
var compAnnotation = <dirAnn.ComponentMetadata>directiveAnnotation; var cmpMeta = <md.ComponentMetadata>dirMeta;
var viewAnnotation = this._viewResolver.resolve(directiveType); var viewMeta = this._viewResolver.resolve(directiveType);
templateMeta = new cpl.CompileTemplateMetadata({ templateMeta = new cpl.CompileTemplateMetadata({
encapsulation: viewAnnotation.encapsulation, encapsulation: viewMeta.encapsulation,
template: viewAnnotation.template, template: viewMeta.template,
templateUrl: viewAnnotation.templateUrl, templateUrl: viewMeta.templateUrl,
styles: viewAnnotation.styles, styles: viewMeta.styles,
styleUrls: viewAnnotation.styleUrls styleUrls: viewMeta.styleUrls
}); });
changeDetectionStrategy = compAnnotation.changeDetection; changeDetectionStrategy = cmpMeta.changeDetection;
} }
meta = cpl.CompileDirectiveMetadata.create({ meta = cpl.CompileDirectiveMetadata.create({
selector: directiveAnnotation.selector, selector: dirMeta.selector,
exportAs: directiveAnnotation.exportAs, exportAs: dirMeta.exportAs,
isComponent: isPresent(templateMeta), isComponent: isPresent(templateMeta),
dynamicLoadable: true, dynamicLoadable: true,
type: new cpl.CompileTypeMetadata( type: new cpl.CompileTypeMetadata(
{name: stringify(directiveType), moduleUrl: moduleUrl, runtime: directiveType}), {name: stringify(directiveType), moduleUrl: moduleUrl, runtime: directiveType}),
template: templateMeta, template: templateMeta,
changeDetection: changeDetectionStrategy, changeDetection: changeDetectionStrategy,
inputs: directiveAnnotation.inputs, inputs: dirMeta.inputs,
outputs: directiveAnnotation.outputs, outputs: dirMeta.outputs,
host: directiveAnnotation.host, host: dirMeta.host,
lifecycleHooks: ListWrapper.filter(LIFECYCLE_HOOKS_VALUES, lifecycleHooks: ListWrapper.filter(LIFECYCLE_HOOKS_VALUES,
hook => hasLifecycleHook(hook, directiveType)) hook => hasLifecycleHook(hook, directiveType))
}); });
@ -112,9 +112,9 @@ function isValidDirective(value: Type): boolean {
return isPresent(value) && (value instanceof Type); return isPresent(value) && (value instanceof Type);
} }
function calcModuleUrl(type: Type, directiveAnnotation: dirAnn.DirectiveMetadata): string { function calcModuleUrl(type: Type, dirMeta: md.DirectiveMetadata): string {
if (isPresent(directiveAnnotation.moduleId)) { if (isPresent(dirMeta.moduleId)) {
return `package:${directiveAnnotation.moduleId}${MODULE_SUFFIX}`; return `package:${dirMeta.moduleId}${MODULE_SUFFIX}`;
} else { } else {
return reflector.importUri(type); return reflector.importUri(type);
} }