refactor(renderer): separate compiler from renderer
Part of #1675 Closes #1702
This commit is contained in:
6
modules/angular2/src/render/api.js
vendored
6
modules/angular2/src/render/api.js
vendored
@ -160,11 +160,11 @@ export class ViewDefinition {
|
||||
}
|
||||
}
|
||||
|
||||
export class Renderer {
|
||||
export class RenderCompiler {
|
||||
/**
|
||||
* Creats a ProtoViewDto that contains a single nested component with the given componentId.
|
||||
*/
|
||||
createHostProtoView(componentId):Promise<ProtoViewDto> { return null; }
|
||||
compileHost(componentId):Promise<ProtoViewDto> { return null; }
|
||||
|
||||
/**
|
||||
* Creats a ProtoViewDto for a component that will use an imperative View using the given
|
||||
@ -189,7 +189,9 @@ export class Renderer {
|
||||
* RenderProtoView for every element with a component in this protoView or in a view container's protoView
|
||||
*/
|
||||
mergeChildComponentProtoViews(protoViewRef:RenderProtoViewRef, componentProtoViewRefs:List<RenderProtoViewRef>) { return null; }
|
||||
}
|
||||
|
||||
export class Renderer {
|
||||
/**
|
||||
* Creates a view and inserts it into a ViewContainer.
|
||||
* @param {RenderViewContainerRef} viewContainerRef
|
||||
|
@ -1,26 +1,35 @@
|
||||
import {Injectable} from 'angular2/src/di/annotations_impl';
|
||||
|
||||
import {PromiseWrapper, Promise} from 'angular2/src/facade/async';
|
||||
import {BaseException} from 'angular2/src/facade/lang';
|
||||
import {BaseException, isPresent} from 'angular2/src/facade/lang';
|
||||
import {ListWrapper} from 'angular2/src/facade/collection';
|
||||
import {DOM} from 'angular2/src/dom/dom_adapter';
|
||||
|
||||
import {ViewDefinition, ProtoViewDto, DirectiveMetadata} from '../../api';
|
||||
import {ViewDefinition, ProtoViewDto, DirectiveMetadata, RenderCompiler, RenderProtoViewRef} from '../../api';
|
||||
import {CompilePipeline} from './compile_pipeline';
|
||||
import {TemplateLoader} from 'angular2/src/render/dom/compiler/template_loader';
|
||||
import {CompileStepFactory, DefaultStepFactory} from './compile_step_factory';
|
||||
import {Parser} from 'angular2/change_detection';
|
||||
import {ShadowDomStrategy} from '../shadow_dom/shadow_dom_strategy';
|
||||
import {ProtoViewBuilder} from '../view/proto_view_builder';
|
||||
|
||||
import {DirectDomProtoViewRef} from '../direct_dom_renderer';
|
||||
|
||||
function _resolveProtoView(protoViewRef:DirectDomProtoViewRef) {
|
||||
return isPresent(protoViewRef) ? protoViewRef.delegate : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The compiler loads and translates the html templates of components into
|
||||
* nested ProtoViews. To decompose its functionality it uses
|
||||
* the CompilePipeline and the CompileSteps.
|
||||
*/
|
||||
export class Compiler {
|
||||
export class DomCompiler extends RenderCompiler {
|
||||
_templateLoader: TemplateLoader;
|
||||
_stepFactory: CompileStepFactory;
|
||||
|
||||
constructor(stepFactory: CompileStepFactory, templateLoader: TemplateLoader) {
|
||||
super();
|
||||
this._templateLoader = templateLoader;
|
||||
this._stepFactory = stepFactory;
|
||||
}
|
||||
@ -44,6 +53,18 @@ export class Compiler {
|
||||
return this._compileTemplate(hostViewDef, element);
|
||||
}
|
||||
|
||||
createImperativeComponentProtoView(rendererId):Promise<ProtoViewDto> {
|
||||
var protoViewBuilder = new ProtoViewBuilder(null);
|
||||
protoViewBuilder.setImperativeRendererId(rendererId);
|
||||
return PromiseWrapper.resolve(protoViewBuilder.build());
|
||||
}
|
||||
|
||||
mergeChildComponentProtoViews(protoViewRef:RenderProtoViewRef, protoViewRefs:List<RenderProtoViewRef>) {
|
||||
_resolveProtoView(protoViewRef).mergeChildComponentProtoViews(
|
||||
ListWrapper.map(protoViewRefs, _resolveProtoView)
|
||||
);
|
||||
}
|
||||
|
||||
_compileTemplate(viewDef: ViewDefinition, tplElement):Promise<ProtoViewDto> {
|
||||
var subTaskPromises = [];
|
||||
var pipeline = new CompilePipeline(this._stepFactory.createSteps(viewDef, subTaskPromises));
|
||||
@ -60,7 +81,7 @@ export class Compiler {
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class DefaultCompiler extends Compiler {
|
||||
export class DefaultDomCompiler extends DomCompiler {
|
||||
constructor(parser:Parser, shadowDomStrategy:ShadowDomStrategy, templateLoader: TemplateLoader) {
|
||||
super(new DefaultStepFactory(parser, shadowDomStrategy), templateLoader);
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
import {Injectable} from 'angular2/src/di/annotations_impl';
|
||||
|
||||
import {Promise, PromiseWrapper} from 'angular2/src/facade/async';
|
||||
import {List, ListWrapper} from 'angular2/src/facade/collection';
|
||||
import {isBlank, isPresent, BaseException} from 'angular2/src/facade/lang';
|
||||
|
||||
@ -9,9 +8,7 @@ import {RenderView} from './view/view';
|
||||
import {RenderProtoView} from './view/proto_view';
|
||||
import {ViewFactory} from './view/view_factory';
|
||||
import {RenderViewHydrator} from './view/view_hydrator';
|
||||
import {Compiler} from './compiler/compiler';
|
||||
import {ShadowDomStrategy} from './shadow_dom/shadow_dom_strategy';
|
||||
import {ProtoViewBuilder} from './view/proto_view_builder';
|
||||
import {ViewContainer} from './view/view_container';
|
||||
|
||||
function _resolveViewContainer(vc:api.RenderViewContainerRef) {
|
||||
@ -66,42 +63,18 @@ export class DirectDomViewRef extends api.RenderViewRef {
|
||||
|
||||
@Injectable()
|
||||
export class DirectDomRenderer extends api.Renderer {
|
||||
_compiler: Compiler;
|
||||
_viewFactory: ViewFactory;
|
||||
_viewHydrator: RenderViewHydrator;
|
||||
_shadowDomStrategy: ShadowDomStrategy;
|
||||
|
||||
constructor(
|
||||
compiler: Compiler, viewFactory: ViewFactory, viewHydrator: RenderViewHydrator, shadowDomStrategy: ShadowDomStrategy) {
|
||||
viewFactory: ViewFactory, viewHydrator: RenderViewHydrator, shadowDomStrategy: ShadowDomStrategy) {
|
||||
super();
|
||||
this._compiler = compiler;
|
||||
this._viewFactory = viewFactory;
|
||||
this._viewHydrator = viewHydrator;
|
||||
this._shadowDomStrategy = shadowDomStrategy;
|
||||
}
|
||||
|
||||
createHostProtoView(directiveMetadata:api.DirectiveMetadata):Promise<api.ProtoViewDto> {
|
||||
return this._compiler.compileHost(directiveMetadata);
|
||||
}
|
||||
|
||||
createImperativeComponentProtoView(rendererId):Promise<api.ProtoViewDto> {
|
||||
var protoViewBuilder = new ProtoViewBuilder(null);
|
||||
protoViewBuilder.setImperativeRendererId(rendererId);
|
||||
return PromiseWrapper.resolve(protoViewBuilder.build());
|
||||
}
|
||||
|
||||
compile(view:api.ViewDefinition):Promise<api.ProtoViewDto> {
|
||||
// Note: compiler already uses a DirectDomProtoViewRef, so we don't
|
||||
// need to do anything here
|
||||
return this._compiler.compile(view);
|
||||
}
|
||||
|
||||
mergeChildComponentProtoViews(protoViewRef:api.RenderProtoViewRef, protoViewRefs:List<api.RenderProtoViewRef>) {
|
||||
_resolveProtoView(protoViewRef).mergeChildComponentProtoViews(
|
||||
ListWrapper.map(protoViewRefs, _resolveProtoView)
|
||||
);
|
||||
}
|
||||
|
||||
createViewInContainer(vcRef:api.RenderViewContainerRef, atIndex:number, protoViewRef:api.RenderProtoViewRef):List<api.RenderViewRef> {
|
||||
var view = this._viewFactory.getView(_resolveProtoView(protoViewRef));
|
||||
var vc = _resolveViewContainer(vcRef);
|
||||
|
Reference in New Issue
Block a user