refactor(view): provide ViewContainers dynamically on any element
This commit is contained in:
+18
-5
@@ -8,6 +8,8 @@ import {SetterFn} from 'angular2/src/reflection/types';
|
||||
import {IMPLEMENTS, int, isPresent, isBlank, BaseException} from 'angular2/src/facade/lang';
|
||||
import {ViewContainer} from './view_container';
|
||||
import * as renderApi from 'angular2/src/render/api';
|
||||
import * as vfModule from './view_factory';
|
||||
import * as vhModule from './view_hydrator';
|
||||
|
||||
/**
|
||||
* Const of making objects: http://jsperf.com/instantiate-size-of-object
|
||||
@@ -17,7 +19,6 @@ import * as renderApi from 'angular2/src/render/api';
|
||||
// TODO(tbosch): this is not supported in dart2js (no '.' is allowed)
|
||||
// @IMPLEMENTS(renderApi.EventDispatcher)
|
||||
export class AppView {
|
||||
|
||||
render:renderApi.ViewRef;
|
||||
/// This list matches the _nodes list. It is sparse, since only Elements have ElementInjector
|
||||
rootElementInjectors:List<ElementInjector>;
|
||||
@@ -28,6 +29,8 @@ export class AppView {
|
||||
preBuiltObjects: List<PreBuiltObjects>;
|
||||
proto: AppProtoView;
|
||||
renderer: renderApi.Renderer;
|
||||
viewFactory: vfModule.ViewFactory;
|
||||
viewHydrator: vhModule.AppViewHydrator;
|
||||
|
||||
/**
|
||||
* The context against which data-binding expressions in this view are evaluated against.
|
||||
@@ -43,30 +46,40 @@ export class AppView {
|
||||
*/
|
||||
locals:Locals;
|
||||
|
||||
constructor(renderer:renderApi.Renderer, proto:AppProtoView, protoLocals:Map) {
|
||||
constructor(renderer:renderApi.Renderer, viewFactory:vfModule.ViewFactory, viewHydrator:vhModule.AppViewHydrator, proto:AppProtoView, protoLocals:Map) {
|
||||
this.render = null;
|
||||
this.proto = proto;
|
||||
this.changeDetector = null;
|
||||
this.elementInjectors = null;
|
||||
this.rootElementInjectors = null;
|
||||
this.componentChildViews = null;
|
||||
this.viewContainers = null;
|
||||
this.viewContainers = ListWrapper.createFixedSize(this.proto.elementBinders.length);
|
||||
this.preBuiltObjects = null;
|
||||
this.context = null;
|
||||
this.locals = new Locals(null, MapWrapper.clone(protoLocals)); //TODO optimize this
|
||||
this.renderer = renderer;
|
||||
this.viewFactory = viewFactory;
|
||||
this.viewHydrator = viewHydrator;
|
||||
}
|
||||
|
||||
init(changeDetector:ChangeDetector, elementInjectors:List, rootElementInjectors:List,
|
||||
viewContainers:List, preBuiltObjects:List, componentChildViews:List) {
|
||||
preBuiltObjects:List, componentChildViews:List) {
|
||||
this.changeDetector = changeDetector;
|
||||
this.elementInjectors = elementInjectors;
|
||||
this.rootElementInjectors = rootElementInjectors;
|
||||
this.viewContainers = viewContainers;
|
||||
this.preBuiltObjects = preBuiltObjects;
|
||||
this.componentChildViews = componentChildViews;
|
||||
}
|
||||
|
||||
getOrCreateViewContainer(boundElementIndex:number) {
|
||||
var viewContainer = this.viewContainers[boundElementIndex];
|
||||
if (isBlank(viewContainer)) {
|
||||
viewContainer = new ViewContainer(this, this.proto.elementBinders[boundElementIndex].nestedProtoView, this.elementInjectors[boundElementIndex]);
|
||||
this.viewContainers[boundElementIndex] = viewContainer;
|
||||
}
|
||||
return viewContainer;
|
||||
}
|
||||
|
||||
setLocal(contextName: string, value) {
|
||||
if (!this.hydrated()) throw new BaseException('Cannot set locals on dehydrated view.');
|
||||
if (!MapWrapper.contains(this.proto.variableBindings, contextName)) {
|
||||
|
||||
Reference in New Issue
Block a user