refactor(TemplateResolver): rename to ViewResolver

This commit is contained in:
Victor Berchet 2015-06-24 10:54:04 +02:00
parent 356c927d12
commit b15474c6f2
11 changed files with 43 additions and 48 deletions

View File

@ -1,5 +1,5 @@
export * from './src/mock/mock_location_strategy'; export * from './src/mock/mock_location_strategy';
export {LocationStrategy} from './src/router/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'; export {MockXHR} from 'angular2/src/render/xhr_mock';

View File

@ -27,7 +27,7 @@ import {ExceptionHandler} from './exception_handler';
import {ViewLoader} from 'angular2/src/render/dom/compiler/view_loader'; import {ViewLoader} from 'angular2/src/render/dom/compiler/view_loader';
import {StyleUrlResolver} from 'angular2/src/render/dom/compiler/style_url_resolver'; import {StyleUrlResolver} from 'angular2/src/render/dom/compiler/style_url_resolver';
import {StyleInliner} from 'angular2/src/render/dom/compiler/style_inliner'; 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 {DirectiveResolver} from './compiler/directive_resolver';
import {List, ListWrapper} from 'angular2/src/facade/collection'; import {List, ListWrapper} from 'angular2/src/facade/collection';
import {Promise, PromiseWrapper} from 'angular2/src/facade/async'; import {Promise, PromiseWrapper} from 'angular2/src/facade/async';
@ -118,7 +118,7 @@ function _injectorBindings(appComponentType): List<Type | Binding | List<any>> {
AppViewListener, AppViewListener,
Compiler, Compiler,
CompilerCache, CompilerCache,
TemplateResolver, ViewResolver,
bind(PipeRegistry).toValue(defaultPipeRegistry), bind(PipeRegistry).toValue(defaultPipeRegistry),
bind(ChangeDetection).toClass(bestChangeDetection), bind(ChangeDetection).toClass(bestChangeDetection),
ViewLoader, ViewLoader,

View File

@ -18,7 +18,7 @@ import {AppProtoView} from './view';
import {ElementBinder} from './element_binder'; import {ElementBinder} from './element_binder';
import {ProtoViewRef} from './view_ref'; import {ProtoViewRef} from './view_ref';
import {DirectiveBinding} from './element_injector'; import {DirectiveBinding} from './element_injector';
import {TemplateResolver} from './template_resolver'; import {ViewResolver} from './view_resolver';
import {View} from '../annotations_impl/view'; import {View} from '../annotations_impl/view';
import {ComponentUrlMapper} from './component_url_mapper'; import {ComponentUrlMapper} from './component_url_mapper';
import {ProtoViewFactory} from './proto_view_factory'; import {ProtoViewFactory} from './proto_view_factory';
@ -66,21 +66,21 @@ export class Compiler {
private _reader: DirectiveResolver; private _reader: DirectiveResolver;
private _compilerCache: CompilerCache; private _compilerCache: CompilerCache;
private _compiling: Map<Type, Promise<AppProtoView>>; private _compiling: Map<Type, Promise<AppProtoView>>;
private _templateResolver: TemplateResolver; private _viewResolver: ViewResolver;
private _componentUrlMapper: ComponentUrlMapper; private _componentUrlMapper: ComponentUrlMapper;
private _urlResolver: UrlResolver; private _urlResolver: UrlResolver;
private _appUrl: string; private _appUrl: string;
private _render: renderApi.RenderCompiler; private _render: renderApi.RenderCompiler;
private _protoViewFactory: ProtoViewFactory; private _protoViewFactory: ProtoViewFactory;
constructor(reader: DirectiveResolver, cache: CompilerCache, templateResolver: TemplateResolver, constructor(reader: DirectiveResolver, cache: CompilerCache, viewResolver: ViewResolver,
componentUrlMapper: ComponentUrlMapper, urlResolver: UrlResolver, componentUrlMapper: ComponentUrlMapper, urlResolver: UrlResolver,
render: renderApi.RenderCompiler, protoViewFactory: ProtoViewFactory, render: renderApi.RenderCompiler, protoViewFactory: ProtoViewFactory,
appUrl: AppRootUrl) { appUrl: AppRootUrl) {
this._reader = reader; this._reader = reader;
this._compilerCache = cache; this._compilerCache = cache;
this._compiling = new Map(); this._compiling = new Map();
this._templateResolver = templateResolver; this._viewResolver = viewResolver;
this._componentUrlMapper = componentUrlMapper; this._componentUrlMapper = componentUrlMapper;
this._urlResolver = urlResolver; this._urlResolver = urlResolver;
this._appUrl = appUrl.value; this._appUrl = appUrl.value;
@ -139,7 +139,7 @@ export class Compiler {
// It happens when a template references a component multiple times. // It happens when a template references a component multiple times.
return pvPromise; return pvPromise;
} }
var template = this._templateResolver.resolve(component); var template = this._viewResolver.resolve(component);
var directives = this._flattenDirectives(template); var directives = this._flattenDirectives(template);

View File

@ -8,7 +8,7 @@ import {reflector} from 'angular2/src/reflection/reflection';
@Injectable() @Injectable()
export class TemplateResolver { export class ViewResolver {
_cache: Map<Type, /*node*/ any> = new Map(); _cache: Map<Type, /*node*/ any> = new Map();
resolve(component: Type): View { resolve(component: Type): View {

View File

@ -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 {Type, isPresent, BaseException, stringify, isBlank} from 'angular2/src/facade/lang';
import {View} from 'angular2/src/core/annotations_impl/view'; 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 MockViewResolver extends ViewResolver {
export class MockTemplateResolver extends TemplateResolver { _views: Map<Type, View> = new Map();
_views: Map<Type, View>; _inlineTemplates: Map<Type, string> = new Map();
_inlineTemplates: Map<Type, string>; _viewCache: Map<Type, View> = new Map();
_viewCache: Map<Type, View>; _directiveOverrides: Map<Type, Map<Type, Type>> = new Map();
_directiveOverrides: Map<Type, Map<Type, Type>>;
constructor() { constructor() {
super(); 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: * Returns the {@link View} for a component:
* - Set the {@link View} to the overridden view when it exists or fallback to the default * - Set the {@link View} to the overridden view when it exists or fallback to the default
* `TemplateResolver`, * `ViewResolver`,
* see `setView`. * see `setView`.
* - Override the directives, see `overrideViewDirective`. * - Override the directives, see `overrideViewDirective`.
* - Override the @View definition, see `setInlineTemplate`. * - Override the @View definition, see `setInlineTemplate`.

View File

@ -7,7 +7,7 @@ import {List} from 'angular2/src/facade/collection';
import {View} from 'angular2/src/core/annotations_impl/view'; 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 {AppView} from 'angular2/src/core/compiler/view';
import {internalView} from 'angular2/src/core/compiler/view_ref'; import {internalView} from 'angular2/src/core/compiler/view_ref';
import { import {
@ -40,7 +40,7 @@ export class TestBed {
* @param {ViewDefinition} template * @param {ViewDefinition} template
*/ */
overrideView(component: Type, template: View): void { 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 * @param {string} html
*/ */
setInlineTemplate(component: Type, html: string): void { 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 * @param {Type} to
*/ */
overrideDirective(component: Type, from: Type, to: Type): void { overrideDirective(component: Type, from: Type, to: Type): void {
this._injector.get(TemplateResolver).overrideViewDirective(component, from, to); this._injector.get(ViewResolver).overrideViewDirective(component, from, to);
} }
/** /**

View File

@ -6,7 +6,7 @@ import {List, ListWrapper, MapWrapper} from 'angular2/src/facade/collection';
import {View} from 'angular2/src/core/annotations_impl/view'; 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 {AppView} from 'angular2/src/core/compiler/view';
import {internalView} from 'angular2/src/core/compiler/view_ref'; import {internalView} from 'angular2/src/core/compiler/view_ref';
import { import {
@ -127,15 +127,15 @@ export class TestComponentBuilder {
* @return {Promise<RootTestComponent>} * @return {Promise<RootTestComponent>}
*/ */
createAsync(rootComponentType: Type): Promise<RootTestComponent> { createAsync(rootComponentType: Type): Promise<RootTestComponent> {
var mockTemplateResolver = this._injector.get(TemplateResolver); var mockViewResolver = this._injector.get(ViewResolver);
MapWrapper.forEach(this._viewOverrides, MapWrapper.forEach(this._viewOverrides,
(view, type) => { mockTemplateResolver.setView(type, view); }); (view, type) => { mockViewResolver.setView(type, view); });
MapWrapper.forEach(this._templateOverrides, (template, type) => { MapWrapper.forEach(this._templateOverrides, (template, type) => {
mockTemplateResolver.setInlineTemplate(type, template); mockViewResolver.setInlineTemplate(type, template);
}); });
MapWrapper.forEach(this._directiveOverrides, (overrides, component) => { MapWrapper.forEach(this._directiveOverrides, (overrides, component) => {
MapWrapper.forEach(overrides, (to, from) => { MapWrapper.forEach(overrides, (to, from) => {
mockTemplateResolver.overrideViewDirective(component, from, to); mockViewResolver.overrideViewDirective(component, from, to);
}); });
}); });

View File

@ -12,7 +12,7 @@ import {
} from 'angular2/change_detection'; } from 'angular2/change_detection';
import {ExceptionHandler} from 'angular2/src/core/exception_handler'; import {ExceptionHandler} from 'angular2/src/core/exception_handler';
import {ViewLoader} from 'angular2/src/render/dom/compiler/view_loader'; 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 {DirectiveResolver} from 'angular2/src/core/compiler/directive_resolver';
import {DynamicComponentLoader} from 'angular2/src/core/compiler/dynamic_component_loader'; import {DynamicComponentLoader} from 'angular2/src/core/compiler/dynamic_component_loader';
import {ShadowDomStrategy} from 'angular2/src/render/dom/shadow_dom/shadow_dom_strategy'; 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 {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 {MockXHR} from 'angular2/src/render/xhr_mock';
import {MockLocationStrategy} from 'angular2/src/mock/mock_location_strategy'; import {MockLocationStrategy} from 'angular2/src/mock/mock_location_strategy';
import {LocationStrategy} from 'angular2/src/router/location_strategy'; import {LocationStrategy} from 'angular2/src/router/location_strategy';
@ -101,7 +101,7 @@ function _getAppBindings() {
bind(APP_VIEW_POOL_CAPACITY).toValue(500), bind(APP_VIEW_POOL_CAPACITY).toValue(500),
Compiler, Compiler,
CompilerCache, CompilerCache,
bind(TemplateResolver).toClass(MockTemplateResolver), bind(ViewResolver).toClass(MockViewResolver),
bind(PipeRegistry).toValue(defaultPipeRegistry), bind(PipeRegistry).toValue(defaultPipeRegistry),
bind(ChangeDetection).toClass(DynamicChangeDetection), bind(ChangeDetection).toClass(DynamicChangeDetection),
ViewLoader, ViewLoader,

View File

@ -26,7 +26,7 @@ import {Attribute, View, Component, Directive} from 'angular2/annotations';
import * as viewAnn from 'angular2/src/core/annotations_impl/view'; import * as viewAnn from 'angular2/src/core/annotations_impl/view';
import {internalProtoView} from 'angular2/src/core/compiler/view_ref'; import {internalProtoView} from 'angular2/src/core/compiler/view_ref';
import {DirectiveBinding} from 'angular2/src/core/compiler/element_injector'; 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 { import {
ComponentUrlMapper, ComponentUrlMapper,
RuntimeComponentUrlMapper RuntimeComponentUrlMapper
@ -47,7 +47,7 @@ export function main() {
beforeEach(() => { beforeEach(() => {
directiveResolver = new DirectiveResolver(); directiveResolver = new DirectiveResolver();
tplResolver = new FakeTemplateResolver(); tplResolver = new FakeViewResolver();
cmpUrlMapper = new RuntimeComponentUrlMapper(); cmpUrlMapper = new RuntimeComponentUrlMapper();
renderCompiler = new SpyRenderCompiler(); renderCompiler = new SpyRenderCompiler();
renderCompiler.spy('compileHost') renderCompiler.spy('compileHost')
@ -567,7 +567,7 @@ class FakeAppRootUrl extends AppRootUrl {
get value() { return 'http://www.app.com'; } get value() { return 'http://www.app.com'; }
} }
class FakeTemplateResolver extends TemplateResolver { class FakeViewResolver extends ViewResolver {
_cmpViews: Map<Type, viewAnn.View> = new Map(); _cmpViews: Map<Type, viewAnn.View> = new Map();
constructor() { super(); } constructor() { super(); }

View File

@ -10,7 +10,7 @@ import {
import {stringify} from 'angular2/src/facade/lang'; 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'; 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'; import * as viewImpl from 'angular2/src/core/annotations_impl/view';
export function main() { export function main() {
describe('MockTemplateResolver', () => { describe('MockViewResolver', () => {
var resolver; var resolver;
beforeEach(() => { resolver = new MockTemplateResolver(); }); beforeEach(() => { resolver = new MockViewResolver(); });
describe('View overriding', () => { 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); var template = resolver.resolve(SomeComponent);
expect(template.template).toEqual('template'); 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); resolver.resolve(SomeComponent);
expect(() => { expect(() => {
resolver.setView(SomeComponent, new viewImpl.View({template: 'overridden template'})); resolver.setView(SomeComponent, new viewImpl.View({template: 'overridden template'}));
@ -65,7 +65,7 @@ export function main() {
expect(template.template).toEqual('overridden template x 2'); 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); resolver.resolve(SomeComponent);
expect(() => { resolver.setInlineTemplate(SomeComponent, 'overridden template'); }) expect(() => { resolver.setInlineTemplate(SomeComponent, 'overridden template'); })
.toThrowError( .toThrowError(
@ -75,7 +75,7 @@ export function main() {
describe('Directive overriding', () => { 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); resolver.overrideViewDirective(SomeComponent, SomeDirective, SomeOtherDirective);
var template = resolver.resolve(SomeComponent); var template = resolver.resolve(SomeComponent);
expect(template.directives.length).toEqual(1); 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)}`); `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); resolver.resolve(SomeComponent);
expect(() => { expect(() => {
resolver.overrideViewDirective(SomeComponent, SomeDirective, SomeOtherDirective); resolver.overrideViewDirective(SomeComponent, SomeDirective, SomeOtherDirective);

View File

@ -14,7 +14,7 @@ import {DirectiveResolver} from 'angular2/src/core/compiler/directive_resolver';
import * as viewModule from 'angular2/src/core/annotations_impl/view'; import * as viewModule from 'angular2/src/core/annotations_impl/view';
import {Component, Directive, View} from 'angular2/angular2'; import {Component, Directive, View} from 'angular2/angular2';
import {ViewLoader} from 'angular2/src/render/dom/compiler/view_loader'; 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 {UrlResolver} from 'angular2/src/services/url_resolver';
import {AppRootUrl} from 'angular2/src/services/app_root_url'; import {AppRootUrl} from 'angular2/src/services/app_root_url';
import {ComponentUrlMapper} from 'angular2/src/core/compiler/component_url_mapper'; import {ComponentUrlMapper} from 'angular2/src/core/compiler/component_url_mapper';
@ -33,14 +33,14 @@ export function main() {
reflector.reflectionCapabilities = new ReflectionCapabilities(); reflector.reflectionCapabilities = new ReflectionCapabilities();
var reader = new DirectiveResolver(); var reader = new DirectiveResolver();
var cache = new CompilerCache(); var cache = new CompilerCache();
var templateResolver = new MultipleTemplateResolver( var viewResolver = new MultipleViewResolver(
count, [BenchmarkComponentNoBindings, BenchmarkComponentWithBindings]); count, [BenchmarkComponentNoBindings, BenchmarkComponentWithBindings]);
var urlResolver = new UrlResolver(); var urlResolver = new UrlResolver();
var shadowDomStrategy = new NativeShadowDomStrategy(); var shadowDomStrategy = new NativeShadowDomStrategy();
var renderCompiler = new rc.DefaultDomCompiler(new Parser(new Lexer()), shadowDomStrategy, var renderCompiler = new rc.DefaultDomCompiler(new Parser(new Lexer()), shadowDomStrategy,
new ViewLoader(null, null, null)); new ViewLoader(null, null, null));
var compiler = new Compiler( 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()); new ProtoViewFactory(new DynamicChangeDetection(null)), new FakeAppRootUrl());
function measureWrapper(func, desc) { function measureWrapper(func, desc) {
@ -93,7 +93,7 @@ class Dir4 {
constructor(dir3: Dir3) {} constructor(dir3: Dir3) {}
} }
class MultipleTemplateResolver extends TemplateResolver { class MultipleViewResolver extends ViewResolver {
_multiple: number; _multiple: number;
_cache: Map<any, any>; _cache: Map<any, any>;