refactor(views): clean up creating views in place and extract view_hydrator
Major changes: - `compiler.compileRoot(el, type)` -> `compiler.compileInHost(type) + viewHydrator.hydrateHostViewInPlace(el, view)` - move all `hydrate`/`dehydrate` methods out of `View` and `ViewContainer` into a standalone class `view_hydrator` as private methods and provide new public methods dedicated to the individual use cases. Note: This PR does not change the current functionality, only moves it into different places. See design discussion in #1351, in preparation for imperative views.
This commit is contained in:
20
modules/angular2/src/test_lib/test_bed.js
vendored
20
modules/angular2/src/test_lib/test_bed.js
vendored
@ -11,6 +11,7 @@ import {TemplateResolver} from 'angular2/src/core/compiler/template_resolver';
|
||||
import {Compiler} from 'angular2/src/core/compiler/compiler';
|
||||
import {AppView} from 'angular2/src/core/compiler/view';
|
||||
import {ViewFactory} from 'angular2/src/core/compiler/view_factory';
|
||||
import {AppViewHydrator} from 'angular2/src/core/compiler/view_hydrator';
|
||||
|
||||
import {DirectiveBinding} from 'angular2/src/core/compiler/element_injector';
|
||||
import {DirectiveMetadataReader} from 'angular2/src/core/compiler/directive_metadata_reader';
|
||||
@ -96,11 +97,13 @@ export class TestBed {
|
||||
bind(component).toValue(context),
|
||||
metadataReader.read(component).annotation
|
||||
);
|
||||
return this._injector.get(Compiler).compileRoot(rootEl, componentBinding).then((pv) => {
|
||||
return this._injector.get(Compiler).compileInHost(componentBinding).then((pv) => {
|
||||
var viewFactory = this._injector.get(ViewFactory);
|
||||
var view = viewFactory.getView(pv);
|
||||
view.hydrate(this._injector, null, context, null);
|
||||
return new ViewProxy(view.componentChildViews[0]);
|
||||
var viewHydrator = this._injector.get(AppViewHydrator);
|
||||
var hostView = viewFactory.getView(pv);
|
||||
viewHydrator.hydrateInPlaceHostView(null, rootEl, hostView, this._injector);
|
||||
|
||||
return new ViewProxy(this._injector, hostView.componentChildViews[0]);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -110,9 +113,11 @@ export class TestBed {
|
||||
*/
|
||||
export class ViewProxy {
|
||||
_view: AppView;
|
||||
_injector: Injector;
|
||||
|
||||
constructor(view: AppView) {
|
||||
constructor(injector: Injector, view: AppView) {
|
||||
this._view = view;
|
||||
this._injector = injector;
|
||||
}
|
||||
|
||||
get context(): any {
|
||||
@ -131,6 +136,11 @@ export class ViewProxy {
|
||||
return queryView(this._view, selector);
|
||||
}
|
||||
|
||||
destroy() {
|
||||
var viewHydrator = this._injector.get(AppViewHydrator);
|
||||
viewHydrator.dehydrateInPlaceHostView(null, this._view);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {AppView} return the underlying [AppView].
|
||||
*
|
||||
|
@ -35,11 +35,13 @@ import {List, ListWrapper} from 'angular2/src/facade/collection';
|
||||
import {FunctionWrapper} from 'angular2/src/facade/lang';
|
||||
|
||||
import {ViewFactory, VIEW_POOL_CAPACITY} from 'angular2/src/core/compiler/view_factory';
|
||||
import {AppViewHydrator} from 'angular2/src/core/compiler/view_hydrator';
|
||||
import {ProtoViewFactory} from 'angular2/src/core/compiler/proto_view_factory';
|
||||
import {Renderer} from 'angular2/src/render/api';
|
||||
import {DirectDomRenderer} from 'angular2/src/render/dom/direct_dom_renderer';
|
||||
import * as rc from 'angular2/src/render/dom/compiler/compiler';
|
||||
import * as rvf from 'angular2/src/render/dom/view/view_factory';
|
||||
import * as rvh from 'angular2/src/render/dom/view/view_hydrator';
|
||||
|
||||
/**
|
||||
* Returns the root injector bindings.
|
||||
@ -79,9 +81,11 @@ function _getAppBindings() {
|
||||
bind(Renderer).toClass(DirectDomRenderer),
|
||||
bind(rc.Compiler).toClass(rc.DefaultCompiler),
|
||||
rvf.ViewFactory,
|
||||
rvh.RenderViewHydrator,
|
||||
bind(rvf.VIEW_POOL_CAPACITY).toValue(500),
|
||||
ProtoViewFactory,
|
||||
ViewFactory,
|
||||
AppViewHydrator,
|
||||
bind(VIEW_POOL_CAPACITY).toValue(500),
|
||||
Compiler,
|
||||
CompilerCache,
|
||||
|
Reference in New Issue
Block a user