@@ -11,10 +11,11 @@ import {SetterFn} from 'reflection/types';
1111import { FIELD , IMPLEMENTS , int , isPresent , isBlank } from 'facade/lang' ;
1212import { Injector } from 'di/di' ;
1313import { NgElement } from 'core/dom/element' ;
14+ import { ViewPort } from './viewport' ;
1415
1516const NG_BINDING_CLASS = 'ng-binding' ;
1617
17- /***
18+ /**
1819 * Const of making objects: http://jsperf.com/instantiate-size-of-object
1920 */
2021@IMPLEMENTS ( WatchGroupDispatcher )
@@ -29,7 +30,8 @@ export class View {
2930 /// to keep track of the nodes.
3031 nodes :List < Node > ;
3132 onChangeDispatcher :OnChangeDispatcher ;
32- childViews : List < View > ;
33+ componentChildViews : List < View > ;
34+ viewPorts : List < ViewPort > ;
3335 constructor ( nodes :List < Node > , elementInjectors :List ,
3436 rootElementInjectors :List , textNodes :List , bindElements :List ,
3537 protoRecordRange :ProtoRecordRange , context ) {
@@ -41,9 +43,8 @@ export class View {
4143 this . bindElements = bindElements ;
4244 this . recordRange = protoRecordRange . instantiate ( this , MapWrapper . create ( ) ) ;
4345 this . recordRange . setContext ( context ) ;
44- // TODO(rado): Since this is only used in tests for now, investigate whether
45- // we can remove it.
46- this . childViews = [ ] ;
46+ this . componentChildViews = null ;
47+ this . viewPorts = null ;
4748 }
4849
4950 onRecordChange ( record :Record , target ) {
@@ -62,10 +63,24 @@ export class View {
6263 }
6364 }
6465
65- addChild ( childView : View ) {
66- ListWrapper . push ( this . childViews , childView ) ;
66+ addViewPort ( viewPort : ViewPort ) {
67+ if ( isBlank ( this . viewPorts ) ) this . viewPorts = [ ] ;
68+ ListWrapper . push ( this . viewPorts , viewPort ) ;
69+ }
70+
71+ addComponentChildView ( childView : View ) {
72+ if ( isBlank ( this . componentChildViews ) ) this . componentChildViews = [ ] ;
73+ ListWrapper . push ( this . componentChildViews , childView ) ;
74+ this . recordRange . addRange ( childView . recordRange ) ;
75+ }
76+
77+ addViewPortChildView ( childView : View ) {
6778 this . recordRange . addRange ( childView . recordRange ) ;
6879 }
80+
81+ removeViewPortChildView ( childView : View ) {
82+ childView . recordRange . remove ( ) ;
83+ }
6984}
7085
7186export class ProtoView {
@@ -120,9 +135,10 @@ export class ProtoView {
120135 bindElements , this . protoRecordRange , context ) ;
121136
122137 ProtoView . _instantiateDirectives (
123- view , elements , elementInjectors , lightDomAppInjector , shadowAppInjectors ) ;
124- ProtoView . _instantiateChildComponentViews (
125- elements , binders , elementInjectors , shadowAppInjectors , view ) ;
138+ view , elements , binders , elementInjectors , lightDomAppInjector ,
139+ shadowAppInjectors , hostElementInjector ) ;
140+ ProtoView . _instantiateChildComponentViews ( view , elements , binders ,
141+ elementInjectors , shadowAppInjectors ) ;
126142
127143 return view ;
128144 }
@@ -212,12 +228,25 @@ export class ProtoView {
212228 }
213229
214230 static _instantiateDirectives (
215- view : View , elements :List , injectors :List < ElementInjectors > , lightDomAppInjector : Injector ,
216- shadowDomAppInjectors :List < Injectors > ) {
231+ view , elements :List , binders : List < ElementBinder > , injectors :List < ElementInjectors > ,
232+ lightDomAppInjector : Injector , shadowDomAppInjectors :List < Injectors > ,
233+ hostElementInjector : ElementInjector ) {
217234 for ( var i = 0 ; i < injectors . length ; ++ i ) {
218- var preBuiltObjs = new PreBuiltObjects ( view , new NgElement ( elements [ i ] ) ) ;
219- if ( injectors [ i ] != null ) injectors [ i ] . instantiateDirectives (
235+ var injector = injectors [ i ] ;
236+ if ( injector != null ) {
237+ var binder = binders [ i ] ;
238+ var element = elements [ i ] ;
239+ var ngElement = new NgElement ( element ) ;
240+ var viewPort = null ;
241+ if ( isPresent ( binder . templateDirective ) ) {
242+ viewPort = new ViewPort ( view , element , binder . nestedProtoView , injector ) ;
243+ viewPort . attach ( lightDomAppInjector , hostElementInjector ) ;
244+ view . addViewPort ( viewPort ) ;
245+ }
246+ var preBuiltObjs = new PreBuiltObjects ( view , ngElement , viewPort ) ;
247+ injector . instantiateDirectives (
220248 lightDomAppInjector , shadowDomAppInjectors [ i ] , preBuiltObjs ) ;
249+ }
221250 }
222251 }
223252
@@ -252,20 +281,17 @@ export class ProtoView {
252281 }
253282 }
254283
255- static _instantiateChildComponentViews ( elements , binders , injectors ,
256- shadowDomAppInjectors : List < Injector > , view : View ) {
284+ static _instantiateChildComponentViews ( view : View , elements , binders ,
285+ injectors , shadowDomAppInjectors : List < Injector > ) {
257286 for ( var i = 0 ; i < binders . length ; ++ i ) {
258287 var binder = binders [ i ] ;
259288 if ( isPresent ( binder . componentDirective ) ) {
260289 var injector = injectors [ i ] ;
261290 var childView = binder . nestedProtoView . instantiate (
262291 injector . getComponent ( ) , shadowDomAppInjectors [ i ] , injector ) ;
263- view . addChild ( childView ) ;
292+ view . addComponentChildView ( childView ) ;
264293 var shadowRoot = elements [ i ] . createShadowRoot ( ) ;
265- // TODO(rado): reuse utility from ViewPort/View.
266- for ( var j = 0 ; j < childView . nodes . length ; ++ j ) {
267- DOM . appendChild ( shadowRoot , childView . nodes [ j ] ) ;
268- }
294+ ViewPort . moveViewNodesIntoParent ( shadowRoot , childView ) ;
269295 }
270296 }
271297 }
0 commit comments