refactor(TemplateResolver): rename to ViewResolver
This commit is contained in:
parent
356c927d12
commit
b15474c6f2
|
@ -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';
|
||||
|
|
|
@ -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<Type | Binding | List<any>> {
|
|||
AppViewListener,
|
||||
Compiler,
|
||||
CompilerCache,
|
||||
TemplateResolver,
|
||||
ViewResolver,
|
||||
bind(PipeRegistry).toValue(defaultPipeRegistry),
|
||||
bind(ChangeDetection).toClass(bestChangeDetection),
|
||||
ViewLoader,
|
||||
|
|
|
@ -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<Type, Promise<AppProtoView>>;
|
||||
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);
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import {reflector} from 'angular2/src/reflection/reflection';
|
|||
|
||||
|
||||
@Injectable()
|
||||
export class TemplateResolver {
|
||||
export class ViewResolver {
|
||||
_cache: Map<Type, /*node*/ any> = new Map();
|
||||
|
||||
resolve(component: Type): View {
|
|
@ -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<Type, View>;
|
||||
_inlineTemplates: Map<Type, string>;
|
||||
_viewCache: Map<Type, View>;
|
||||
_directiveOverrides: Map<Type, Map<Type, Type>>;
|
||||
export class MockViewResolver extends ViewResolver {
|
||||
_views: Map<Type, View> = new Map();
|
||||
_inlineTemplates: Map<Type, string> = new Map();
|
||||
_viewCache: Map<Type, View> = new Map();
|
||||
_directiveOverrides: Map<Type, Map<Type, Type>> = 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`.
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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<RootTestComponent>}
|
||||
*/
|
||||
createAsync(rootComponentType: Type): Promise<RootTestComponent> {
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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<Type, viewAnn.View> = new Map();
|
||||
|
||||
constructor() { super(); }
|
||||
|
|
|
@ -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);
|
|
@ -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<any, any>;
|
||||
|
||||
|
|
Loading…
Reference in New Issue