From b15474c6f237e58e5650b5b8270b1273ff8f4a6c Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Wed, 24 Jun 2015 10:54:04 +0200 Subject: [PATCH] refactor(TemplateResolver): rename to ViewResolver --- modules/angular2/mock.ts | 2 +- modules/angular2/src/core/application.ts | 4 ++-- .../angular2/src/core/compiler/compiler.ts | 10 +++++----- ...{template_resolver.ts => view_resolver.ts} | 2 +- ...resolver_mock.ts => view_resolver_mock.ts} | 19 +++++++------------ modules/angular2/src/test_lib/test_bed.ts | 8 ++++---- .../src/test_lib/test_component_builder.ts | 10 +++++----- .../angular2/src/test_lib/test_injector.ts | 6 +++--- .../test/core/compiler/compiler_spec.ts | 6 +++--- ...ock_spec.ts => view_resolver_mock_spec.ts} | 16 ++++++++-------- .../src/compiler/compiler_benchmark.ts | 8 ++++---- 11 files changed, 43 insertions(+), 48 deletions(-) rename modules/angular2/src/core/compiler/{template_resolver.ts => view_resolver.ts} (96%) rename modules/angular2/src/mock/{template_resolver_mock.ts => view_resolver_mock.ts} (88%) rename modules/angular2/test/mock/{template_resolver_mock_spec.ts => view_resolver_mock_spec.ts} (86%) diff --git a/modules/angular2/mock.ts b/modules/angular2/mock.ts index bfad95eefd..4d186a4576 100644 --- a/modules/angular2/mock.ts +++ b/modules/angular2/mock.ts @@ -1,5 +1,5 @@ export * from './src/mock/mock_location_strategy'; export {LocationStrategy} from './src/router/location_strategy'; -export {MockTemplateResolver} from 'angular2/src/mock/template_resolver_mock'; +export {MockViewResolver} from 'angular2/src/mock/view_resolver_mock'; export {MockXHR} from 'angular2/src/render/xhr_mock'; diff --git a/modules/angular2/src/core/application.ts b/modules/angular2/src/core/application.ts index f260c58b6e..a64fd5ad26 100644 --- a/modules/angular2/src/core/application.ts +++ b/modules/angular2/src/core/application.ts @@ -27,7 +27,7 @@ import {ExceptionHandler} from './exception_handler'; import {ViewLoader} from 'angular2/src/render/dom/compiler/view_loader'; import {StyleUrlResolver} from 'angular2/src/render/dom/compiler/style_url_resolver'; import {StyleInliner} from 'angular2/src/render/dom/compiler/style_inliner'; -import {TemplateResolver} from './compiler/template_resolver'; +import {ViewResolver} from './compiler/view_resolver'; import {DirectiveResolver} from './compiler/directive_resolver'; import {List, ListWrapper} from 'angular2/src/facade/collection'; import {Promise, PromiseWrapper} from 'angular2/src/facade/async'; @@ -118,7 +118,7 @@ function _injectorBindings(appComponentType): List> { AppViewListener, Compiler, CompilerCache, - TemplateResolver, + ViewResolver, bind(PipeRegistry).toValue(defaultPipeRegistry), bind(ChangeDetection).toClass(bestChangeDetection), ViewLoader, diff --git a/modules/angular2/src/core/compiler/compiler.ts b/modules/angular2/src/core/compiler/compiler.ts index 5b1096a85c..2401344e09 100644 --- a/modules/angular2/src/core/compiler/compiler.ts +++ b/modules/angular2/src/core/compiler/compiler.ts @@ -18,7 +18,7 @@ import {AppProtoView} from './view'; import {ElementBinder} from './element_binder'; import {ProtoViewRef} from './view_ref'; import {DirectiveBinding} from './element_injector'; -import {TemplateResolver} from './template_resolver'; +import {ViewResolver} from './view_resolver'; import {View} from '../annotations_impl/view'; import {ComponentUrlMapper} from './component_url_mapper'; import {ProtoViewFactory} from './proto_view_factory'; @@ -66,21 +66,21 @@ export class Compiler { private _reader: DirectiveResolver; private _compilerCache: CompilerCache; private _compiling: Map>; - private _templateResolver: TemplateResolver; + private _viewResolver: ViewResolver; private _componentUrlMapper: ComponentUrlMapper; private _urlResolver: UrlResolver; private _appUrl: string; private _render: renderApi.RenderCompiler; private _protoViewFactory: ProtoViewFactory; - constructor(reader: DirectiveResolver, cache: CompilerCache, templateResolver: TemplateResolver, + constructor(reader: DirectiveResolver, cache: CompilerCache, viewResolver: ViewResolver, componentUrlMapper: ComponentUrlMapper, urlResolver: UrlResolver, render: renderApi.RenderCompiler, protoViewFactory: ProtoViewFactory, appUrl: AppRootUrl) { this._reader = reader; this._compilerCache = cache; this._compiling = new Map(); - this._templateResolver = templateResolver; + this._viewResolver = viewResolver; this._componentUrlMapper = componentUrlMapper; this._urlResolver = urlResolver; this._appUrl = appUrl.value; @@ -139,7 +139,7 @@ export class Compiler { // It happens when a template references a component multiple times. return pvPromise; } - var template = this._templateResolver.resolve(component); + var template = this._viewResolver.resolve(component); var directives = this._flattenDirectives(template); diff --git a/modules/angular2/src/core/compiler/template_resolver.ts b/modules/angular2/src/core/compiler/view_resolver.ts similarity index 96% rename from modules/angular2/src/core/compiler/template_resolver.ts rename to modules/angular2/src/core/compiler/view_resolver.ts index 4b0376ac21..fe85096698 100644 --- a/modules/angular2/src/core/compiler/template_resolver.ts +++ b/modules/angular2/src/core/compiler/view_resolver.ts @@ -8,7 +8,7 @@ import {reflector} from 'angular2/src/reflection/reflection'; @Injectable() -export class TemplateResolver { +export class ViewResolver { _cache: Map = new Map(); resolve(component: Type): View { diff --git a/modules/angular2/src/mock/template_resolver_mock.ts b/modules/angular2/src/mock/view_resolver_mock.ts similarity index 88% rename from modules/angular2/src/mock/template_resolver_mock.ts rename to modules/angular2/src/mock/view_resolver_mock.ts index 02e00b16aa..cedb9ed4e1 100644 --- a/modules/angular2/src/mock/template_resolver_mock.ts +++ b/modules/angular2/src/mock/view_resolver_mock.ts @@ -2,21 +2,16 @@ import {Map, MapWrapper, ListWrapper} from 'angular2/src/facade/collection'; import {Type, isPresent, BaseException, stringify, isBlank} from 'angular2/src/facade/lang'; import {View} from 'angular2/src/core/annotations_impl/view'; -import {TemplateResolver} from 'angular2/src/core/compiler/template_resolver'; +import {ViewResolver} from 'angular2/src/core/compiler/view_resolver'; - -export class MockTemplateResolver extends TemplateResolver { - _views: Map; - _inlineTemplates: Map; - _viewCache: Map; - _directiveOverrides: Map>; +export class MockViewResolver extends ViewResolver { + _views: Map = new Map(); + _inlineTemplates: Map = new Map(); + _viewCache: Map = new Map(); + _directiveOverrides: Map> = new Map(); constructor() { super(); - this._views = new Map(); - this._inlineTemplates = new Map(); - this._viewCache = new Map(); - this._directiveOverrides = new Map(); } /** @@ -64,7 +59,7 @@ export class MockTemplateResolver extends TemplateResolver { /** * Returns the {@link View} for a component: * - Set the {@link View} to the overridden view when it exists or fallback to the default - * `TemplateResolver`, + * `ViewResolver`, * see `setView`. * - Override the directives, see `overrideViewDirective`. * - Override the @View definition, see `setInlineTemplate`. diff --git a/modules/angular2/src/test_lib/test_bed.ts b/modules/angular2/src/test_lib/test_bed.ts index b85cfb8648..df452e4e8e 100644 --- a/modules/angular2/src/test_lib/test_bed.ts +++ b/modules/angular2/src/test_lib/test_bed.ts @@ -7,7 +7,7 @@ import {List} from 'angular2/src/facade/collection'; import {View} from 'angular2/src/core/annotations_impl/view'; -import {TemplateResolver} from 'angular2/src/core/compiler/template_resolver'; +import {ViewResolver} from 'angular2/src/core/compiler/view_resolver'; import {AppView} from 'angular2/src/core/compiler/view'; import {internalView} from 'angular2/src/core/compiler/view_ref'; import { @@ -40,7 +40,7 @@ export class TestBed { * @param {ViewDefinition} template */ overrideView(component: Type, template: View): void { - this._injector.get(TemplateResolver).setView(component, template); + this._injector.get(ViewResolver).setView(component, template); } /** @@ -51,7 +51,7 @@ export class TestBed { * @param {string} html */ setInlineTemplate(component: Type, html: string): void { - this._injector.get(TemplateResolver).setInlineTemplate(component, html); + this._injector.get(ViewResolver).setInlineTemplate(component, html); } /** @@ -62,7 +62,7 @@ export class TestBed { * @param {Type} to */ overrideDirective(component: Type, from: Type, to: Type): void { - this._injector.get(TemplateResolver).overrideViewDirective(component, from, to); + this._injector.get(ViewResolver).overrideViewDirective(component, from, to); } /** diff --git a/modules/angular2/src/test_lib/test_component_builder.ts b/modules/angular2/src/test_lib/test_component_builder.ts index c8a44b88ad..c213ccb489 100644 --- a/modules/angular2/src/test_lib/test_component_builder.ts +++ b/modules/angular2/src/test_lib/test_component_builder.ts @@ -6,7 +6,7 @@ import {List, ListWrapper, MapWrapper} from 'angular2/src/facade/collection'; import {View} from 'angular2/src/core/annotations_impl/view'; -import {TemplateResolver} from 'angular2/src/core/compiler/template_resolver'; +import {ViewResolver} from 'angular2/src/core/compiler/view_resolver'; import {AppView} from 'angular2/src/core/compiler/view'; import {internalView} from 'angular2/src/core/compiler/view_ref'; import { @@ -127,15 +127,15 @@ export class TestComponentBuilder { * @return {Promise} */ createAsync(rootComponentType: Type): Promise { - var mockTemplateResolver = this._injector.get(TemplateResolver); + var mockViewResolver = this._injector.get(ViewResolver); MapWrapper.forEach(this._viewOverrides, - (view, type) => { mockTemplateResolver.setView(type, view); }); + (view, type) => { mockViewResolver.setView(type, view); }); MapWrapper.forEach(this._templateOverrides, (template, type) => { - mockTemplateResolver.setInlineTemplate(type, template); + mockViewResolver.setInlineTemplate(type, template); }); MapWrapper.forEach(this._directiveOverrides, (overrides, component) => { MapWrapper.forEach(overrides, (to, from) => { - mockTemplateResolver.overrideViewDirective(component, from, to); + mockViewResolver.overrideViewDirective(component, from, to); }); }); diff --git a/modules/angular2/src/test_lib/test_injector.ts b/modules/angular2/src/test_lib/test_injector.ts index 42dff5b564..437e97fb52 100644 --- a/modules/angular2/src/test_lib/test_injector.ts +++ b/modules/angular2/src/test_lib/test_injector.ts @@ -12,7 +12,7 @@ import { } from 'angular2/change_detection'; import {ExceptionHandler} from 'angular2/src/core/exception_handler'; import {ViewLoader} from 'angular2/src/render/dom/compiler/view_loader'; -import {TemplateResolver} from 'angular2/src/core/compiler/template_resolver'; +import {ViewResolver} from 'angular2/src/core/compiler/view_resolver'; import {DirectiveResolver} from 'angular2/src/core/compiler/directive_resolver'; import {DynamicComponentLoader} from 'angular2/src/core/compiler/dynamic_component_loader'; import {ShadowDomStrategy} from 'angular2/src/render/dom/shadow_dom/shadow_dom_strategy'; @@ -31,7 +31,7 @@ import {DOM} from 'angular2/src/dom/dom_adapter'; import {EventManager, DomEventsPlugin} from 'angular2/src/render/dom/events/event_manager'; -import {MockTemplateResolver} from 'angular2/src/mock/template_resolver_mock'; +import {MockViewResolver} from 'angular2/src/mock/view_resolver_mock'; import {MockXHR} from 'angular2/src/render/xhr_mock'; import {MockLocationStrategy} from 'angular2/src/mock/mock_location_strategy'; import {LocationStrategy} from 'angular2/src/router/location_strategy'; @@ -101,7 +101,7 @@ function _getAppBindings() { bind(APP_VIEW_POOL_CAPACITY).toValue(500), Compiler, CompilerCache, - bind(TemplateResolver).toClass(MockTemplateResolver), + bind(ViewResolver).toClass(MockViewResolver), bind(PipeRegistry).toValue(defaultPipeRegistry), bind(ChangeDetection).toClass(DynamicChangeDetection), ViewLoader, diff --git a/modules/angular2/test/core/compiler/compiler_spec.ts b/modules/angular2/test/core/compiler/compiler_spec.ts index 35c010c46b..8d4c6c63cf 100644 --- a/modules/angular2/test/core/compiler/compiler_spec.ts +++ b/modules/angular2/test/core/compiler/compiler_spec.ts @@ -26,7 +26,7 @@ import {Attribute, View, Component, Directive} from 'angular2/annotations'; import * as viewAnn from 'angular2/src/core/annotations_impl/view'; import {internalProtoView} from 'angular2/src/core/compiler/view_ref'; import {DirectiveBinding} from 'angular2/src/core/compiler/element_injector'; -import {TemplateResolver} from 'angular2/src/core/compiler/template_resolver'; +import {ViewResolver} from 'angular2/src/core/compiler/view_resolver'; import { ComponentUrlMapper, RuntimeComponentUrlMapper @@ -47,7 +47,7 @@ export function main() { beforeEach(() => { directiveResolver = new DirectiveResolver(); - tplResolver = new FakeTemplateResolver(); + tplResolver = new FakeViewResolver(); cmpUrlMapper = new RuntimeComponentUrlMapper(); renderCompiler = new SpyRenderCompiler(); renderCompiler.spy('compileHost') @@ -567,7 +567,7 @@ class FakeAppRootUrl extends AppRootUrl { get value() { return 'http://www.app.com'; } } -class FakeTemplateResolver extends TemplateResolver { +class FakeViewResolver extends ViewResolver { _cmpViews: Map = new Map(); constructor() { super(); } diff --git a/modules/angular2/test/mock/template_resolver_mock_spec.ts b/modules/angular2/test/mock/view_resolver_mock_spec.ts similarity index 86% rename from modules/angular2/test/mock/template_resolver_mock_spec.ts rename to modules/angular2/test/mock/view_resolver_mock_spec.ts index 532a514960..f5d2d86d68 100644 --- a/modules/angular2/test/mock/template_resolver_mock_spec.ts +++ b/modules/angular2/test/mock/view_resolver_mock_spec.ts @@ -10,7 +10,7 @@ import { import {stringify} from 'angular2/src/facade/lang'; -import {MockTemplateResolver} from 'angular2/src/mock/template_resolver_mock'; +import {MockViewResolver} from 'angular2/src/mock/view_resolver_mock'; import {Component, View} from 'angular2/angular2'; @@ -19,13 +19,13 @@ import {isBlank} from 'angular2/src/facade/lang'; import * as viewImpl from 'angular2/src/core/annotations_impl/view'; export function main() { - describe('MockTemplateResolver', () => { + describe('MockViewResolver', () => { var resolver; - beforeEach(() => { resolver = new MockTemplateResolver(); }); + beforeEach(() => { resolver = new MockViewResolver(); }); describe('View overriding', () => { - it('should fallback to the default TemplateResolver when templates are not overridden', + it('should fallback to the default ViewResolver when templates are not overridden', () => { var template = resolver.resolve(SomeComponent); expect(template.template).toEqual('template'); @@ -40,7 +40,7 @@ export function main() { }); - it('should not allow overriding a template after it has been resolved', () => { + it('should not allow overriding a view after it has been resolved', () => { resolver.resolve(SomeComponent); expect(() => { resolver.setView(SomeComponent, new viewImpl.View({template: 'overridden template'})); @@ -65,7 +65,7 @@ export function main() { expect(template.template).toEqual('overridden template x 2'); }); - it('should not allow overriding a template after it has been resolved', () => { + it('should not allow overriding a view after it has been resolved', () => { resolver.resolve(SomeComponent); expect(() => { resolver.setInlineTemplate(SomeComponent, 'overridden template'); }) .toThrowError( @@ -75,7 +75,7 @@ export function main() { describe('Directive overriding', () => { - it('should allow overriding a directive from the default template', () => { + it('should allow overriding a directive from the default view', () => { resolver.overrideViewDirective(SomeComponent, SomeDirective, SomeOtherDirective); var template = resolver.resolve(SomeComponent); expect(template.directives.length).toEqual(1); @@ -97,7 +97,7 @@ export function main() { `Overriden directive ${stringify(SomeOtherDirective)} not found in the template of ${stringify(SomeComponent)}`); }); - it('should not allow overriding a directive after its template has been resolved', () => { + it('should not allow overriding a directive after its view has been resolved', () => { resolver.resolve(SomeComponent); expect(() => { resolver.overrideViewDirective(SomeComponent, SomeDirective, SomeOtherDirective); diff --git a/modules/benchmarks/src/compiler/compiler_benchmark.ts b/modules/benchmarks/src/compiler/compiler_benchmark.ts index a003e2defb..fa56250b0e 100644 --- a/modules/benchmarks/src/compiler/compiler_benchmark.ts +++ b/modules/benchmarks/src/compiler/compiler_benchmark.ts @@ -14,7 +14,7 @@ import {DirectiveResolver} from 'angular2/src/core/compiler/directive_resolver'; import * as viewModule from 'angular2/src/core/annotations_impl/view'; import {Component, Directive, View} from 'angular2/angular2'; import {ViewLoader} from 'angular2/src/render/dom/compiler/view_loader'; -import {TemplateResolver} from 'angular2/src/core/compiler/template_resolver'; +import {ViewResolver} from 'angular2/src/core/compiler/view_resolver'; import {UrlResolver} from 'angular2/src/services/url_resolver'; import {AppRootUrl} from 'angular2/src/services/app_root_url'; import {ComponentUrlMapper} from 'angular2/src/core/compiler/component_url_mapper'; @@ -33,14 +33,14 @@ export function main() { reflector.reflectionCapabilities = new ReflectionCapabilities(); var reader = new DirectiveResolver(); var cache = new CompilerCache(); - var templateResolver = new MultipleTemplateResolver( + var viewResolver = new MultipleViewResolver( count, [BenchmarkComponentNoBindings, BenchmarkComponentWithBindings]); var urlResolver = new UrlResolver(); var shadowDomStrategy = new NativeShadowDomStrategy(); var renderCompiler = new rc.DefaultDomCompiler(new Parser(new Lexer()), shadowDomStrategy, new ViewLoader(null, null, null)); var compiler = new Compiler( - reader, cache, templateResolver, new ComponentUrlMapper(), urlResolver, renderCompiler, + reader, cache, viewResolver, new ComponentUrlMapper(), urlResolver, renderCompiler, new ProtoViewFactory(new DynamicChangeDetection(null)), new FakeAppRootUrl()); function measureWrapper(func, desc) { @@ -93,7 +93,7 @@ class Dir4 { constructor(dir3: Dir3) {} } -class MultipleTemplateResolver extends TemplateResolver { +class MultipleViewResolver extends ViewResolver { _multiple: number; _cache: Map;