refactor(view): introduce AppViewManager to consolidate logic
AppViewManager is the single entry point to changing the view hierarchy. It is split between the manager itself which does coordination and helper methods, so both are easily testable in isolation. Also, ViewContainer is now only a pure reference to a bound element with the previous functionality but does not contain the list of views any more. Part of #1477
This commit is contained in:
33
modules/angular2/src/test_lib/test_bed.js
vendored
33
modules/angular2/src/test_lib/test_bed.js
vendored
@ -8,13 +8,8 @@ import {List} from 'angular2/src/facade/collection';
|
||||
import {View} from 'angular2/src/core/annotations/view';
|
||||
|
||||
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';
|
||||
import {DynamicComponentLoader, ComponentRef} from 'angular2/src/core/compiler/dynamic_component_loader';
|
||||
|
||||
import {queryView, viewRootNodes, el} from './utils';
|
||||
import {instantiateType, getTypeOf} from './lang_utils';
|
||||
@ -92,18 +87,9 @@ export class TestBed {
|
||||
}
|
||||
|
||||
var rootEl = el('<div></div>');
|
||||
var metadataReader = this._injector.get(DirectiveMetadataReader);
|
||||
var componentBinding = DirectiveBinding.createFromBinding(
|
||||
bind(component).toValue(context),
|
||||
metadataReader.read(component).annotation
|
||||
);
|
||||
return this._injector.get(Compiler).compileInHost(componentBinding).then((pv) => {
|
||||
var viewFactory = this._injector.get(ViewFactory);
|
||||
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]);
|
||||
var componentBinding = bind(component).toValue(context);
|
||||
return this._injector.get(DynamicComponentLoader).loadIntoNewLocation(componentBinding, null, rootEl, this._injector).then((hostComponentRef) => {
|
||||
return new ViewProxy(hostComponentRef);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -112,12 +98,12 @@ export class TestBed {
|
||||
* Proxy to `AppView` return by `createView` in {@link TestBed} which offers a high level API for tests.
|
||||
*/
|
||||
export class ViewProxy {
|
||||
_componentRef: ComponentRef;
|
||||
_view: AppView;
|
||||
_injector: Injector;
|
||||
|
||||
constructor(injector: Injector, view: AppView) {
|
||||
this._view = view;
|
||||
this._injector = injector;
|
||||
constructor(componentRef: ComponentRef) {
|
||||
this._componentRef = componentRef;
|
||||
this._view = componentRef.hostView.componentChildViews[0];
|
||||
}
|
||||
|
||||
get context(): any {
|
||||
@ -137,8 +123,7 @@ export class ViewProxy {
|
||||
}
|
||||
|
||||
destroy() {
|
||||
var viewHydrator = this._injector.get(AppViewHydrator);
|
||||
viewHydrator.dehydrateInPlaceHostView(null, this._view);
|
||||
this._componentRef.dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
|
12
modules/angular2/src/test_lib/test_injector.js
vendored
12
modules/angular2/src/test_lib/test_injector.js
vendored
@ -35,8 +35,9 @@ import {Injector} from 'angular2/di';
|
||||
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 {AppViewPool, APP_VIEW_POOL_CAPACITY} from 'angular2/src/core/compiler/view_pool';
|
||||
import {AppViewManager} from 'angular2/src/core/compiler/view_manager';
|
||||
import {AppViewManagerUtils} from 'angular2/src/core/compiler/view_manager_utils';
|
||||
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';
|
||||
@ -86,9 +87,10 @@ function _getAppBindings() {
|
||||
rvh.RenderViewHydrator,
|
||||
bind(rvf.VIEW_POOL_CAPACITY).toValue(500),
|
||||
ProtoViewFactory,
|
||||
ViewFactory,
|
||||
AppViewHydrator,
|
||||
bind(VIEW_POOL_CAPACITY).toValue(500),
|
||||
AppViewPool,
|
||||
AppViewManager,
|
||||
AppViewManagerUtils,
|
||||
bind(APP_VIEW_POOL_CAPACITY).toValue(500),
|
||||
Compiler,
|
||||
CompilerCache,
|
||||
bind(TemplateResolver).toClass(MockTemplateResolver),
|
||||
|
@ -18,8 +18,6 @@ import 'package:angular2/src/facade/collection.dart' show StringMapWrapper;
|
||||
import './test_injector.dart';
|
||||
export './test_injector.dart' show inject;
|
||||
|
||||
import 'package:collection/equality.dart';
|
||||
|
||||
bool IS_DARTIUM = true;
|
||||
|
||||
List _testBindings = [];
|
||||
|
Reference in New Issue
Block a user