@@ -17,13 +17,13 @@ import {RendererFactory2} from '../render/api';
1717import { Type } from '../type' ;
1818
1919import { assertComponentType , assertDefined } from './assert' ;
20- import { LifecycleHooksFeature , createRootContext } from './component' ;
20+ import { LifecycleHooksFeature , createRootComponent , createRootContext } from './component' ;
2121import { getComponentDef } from './definition' ;
22- import { adjustBlueprintForNewNode , baseDirectiveCreate , createLNode , createLViewData , createTView , elementCreate , enterView , hostElement , initChangeDetectorIfExisting , locateHostElement , queueHostBindingForCheck , renderEmbeddedTemplate , setHostBindings } from './instructions' ;
23- import { ComponentDefInternal , ComponentType , RenderFlags } from './interfaces/definition' ;
24- import { LElementNode , TNode , TNodeType } from './interfaces/node' ;
22+ import { adjustBlueprintForNewNode , createLViewData , createNodeAtIndex , createTView , elementCreate , enterView , getTNode , hostElement , locateHostElement , renderEmbeddedTemplate } from './instructions' ;
23+ import { ComponentDefInternal , RenderFlags } from './interfaces/definition' ;
24+ import { LElementNode , TElementNode , TNode , TNodeType , TViewNode } from './interfaces/node' ;
2525import { RElement , RendererFactory3 , domRendererFactory3 } from './interfaces/renderer' ;
26- import { CONTEXT , FLAGS , INJECTOR , LViewData , LViewFlags , RootContext , TVIEW } from './interfaces/view' ;
26+ import { FLAGS , INJECTOR , LViewData , LViewFlags , RootContext , TVIEW } from './interfaces/view' ;
2727import { RootViewRef , ViewRef } from './view_ref' ;
2828
2929export class ComponentFactoryResolver extends viewEngine_ComponentFactoryResolver {
@@ -115,70 +115,60 @@ export class ComponentFactory<T> extends viewEngine_ComponentFactory<T> {
115115 // The first index of the first selector is the tag name.
116116 const componentTag = this . componentDef . selectors ! [ 0 ] ! [ 0 ] as string ;
117117
118+ const rootFlags = this . componentDef . onPush ? LViewFlags . Dirty | LViewFlags . IsRoot :
119+ LViewFlags . CheckAlways | LViewFlags . IsRoot ;
118120 const rootContext : RootContext = ngModule && ! isInternalRootView ?
119121 ngModule . injector . get ( ROOT_CONTEXT ) :
120122 createRootContext ( requestAnimationFrame . bind ( window ) ) ;
121123
122124 // Create the root view. Uses empty TView and ContentTemplate.
123125 const rootView : LViewData = createLViewData (
124126 rendererFactory . createRenderer ( hostNode , this . componentDef ) ,
125- createTView ( - 1 , null , 1 , 0 , null , null , null ) , rootContext ,
126- this . componentDef . onPush ? LViewFlags . Dirty : LViewFlags . CheckAlways ) ;
127+ createTView ( - 1 , null , 1 , 0 , null , null , null ) , rootContext , rootFlags ) ;
127128 rootView [ INJECTOR ] = ngModule && ngModule . injector || null ;
128129
129130 // rootView is the parent when bootstrapping
130131 const oldView = enterView ( rootView , null ) ;
131132
132133 let component : T ;
133134 let elementNode : LElementNode ;
135+ let tElementNode : TElementNode ;
134136 try {
135137 if ( rendererFactory . begin ) rendererFactory . begin ( ) ;
136138
137139 // Create element node at index 0 in data array
138140 elementNode = hostElement ( componentTag , hostNode , this . componentDef ) ;
139- const componentView = elementNode . data as LViewData ;
140141
141- // Create directive instance with factory() and store at index 0 in directives array
142- component =
143- baseDirectiveCreate ( 0 , this . componentDef . factory ( ) , this . componentDef , elementNode ) ;
144- if ( this . componentDef . hostBindings ) {
145- queueHostBindingForCheck ( 0 , this . componentDef . hostVars ) ;
146- }
147- rootContext . components . push ( component ) ;
148- initChangeDetectorIfExisting ( elementNode . nodeInjector , component , componentView ) ;
149- componentView [ CONTEXT ] = component ;
150142 // TODO: should LifecycleHooksFeature and other host features be generated by the compiler and
151143 // executed here?
152144 // Angular 5 reference: https://stackblitz.com/edit/lifecycle-hooks-vcref
153- LifecycleHooksFeature ( component , this . componentDef ) ;
145+ component = createRootComponent (
146+ elementNode , this . componentDef , rootView , rootContext , [ LifecycleHooksFeature ] ) ;
154147
155- setHostBindings ( rootView [ TVIEW ] . hostBindings ) ;
148+ tElementNode = getTNode ( 0 ) as TElementNode ;
156149
157150 // Transform the arrays of native nodes into a LNode structure that can be consumed by the
158151 // projection instruction. This is needed to support the reprojection of these nodes.
159152 if ( projectableNodes ) {
160153 let index = 0 ;
161- const projection : TNode [ ] = elementNode . tNode . projection = [ ] ;
154+ const projection : TNode [ ] = tElementNode . projection = [ ] ;
162155 for ( let i = 0 ; i < projectableNodes . length ; i ++ ) {
163156 const nodeList = projectableNodes [ i ] ;
164157 let firstTNode : TNode | null = null ;
165158 let previousTNode : TNode | null = null ;
166159 for ( let j = 0 ; j < nodeList . length ; j ++ ) {
167160 adjustBlueprintForNewNode ( rootView ) ;
168- const lNode =
169- createLNode ( ++ index , TNodeType . Element , nodeList [ j ] as RElement , null , null ) ;
170- if ( previousTNode ) {
171- previousTNode . next = lNode . tNode ;
172- } else {
173- firstTNode = lNode . tNode ;
174- }
175- previousTNode = lNode . tNode ;
161+ const tNode =
162+ createNodeAtIndex ( ++ index , TNodeType . Element , nodeList [ j ] as RElement , null , null ) ;
163+ previousTNode ? ( previousTNode . next = tNode ) : ( firstTNode = tNode ) ;
164+ previousTNode = tNode ;
176165 }
177166 projection . push ( firstTNode ! ) ;
178167 }
179168 }
180169
181170 // Execute the template in creation mode only, and then turn off the CreationMode flag
171+ const componentView = elementNode . data as LViewData ;
182172 renderEmbeddedTemplate ( componentView , componentView [ TVIEW ] , component , RenderFlags . Create ) ;
183173 componentView [ FLAGS ] &= ~ LViewFlags . CreationMode ;
184174 } finally {
@@ -190,7 +180,7 @@ export class ComponentFactory<T> extends viewEngine_ComponentFactory<T> {
190180 new ComponentRef ( this . componentType , component , rootView , injector , hostNode ! ) ;
191181 if ( isInternalRootView ) {
192182 // The host element of the internal root view is attached to the component's host view node
193- componentRef . hostView . _lViewNode ! . tNode . child = elementNode . tNode ;
183+ componentRef . hostView . _tViewNode ! . child = tElementNode ;
194184 }
195185 return componentRef ;
196186 }
@@ -219,7 +209,7 @@ export class ComponentRef<T> extends viewEngine_ComponentRef<T> {
219209 super ( ) ;
220210 this . instance = instance ;
221211 this . hostView = this . changeDetectorRef = new RootViewRef < T > ( rootView ) ;
222- this . hostView . _lViewNode = createLNode ( - 1 , TNodeType . View , null , null , null , rootView ) ;
212+ this . hostView . _tViewNode = createNodeAtIndex ( - 1 , TNodeType . View , null , null , null , rootView ) ;
223213 this . injector = injector ;
224214 this . location = new viewEngine_ElementRef ( hostNode ) ;
225215 this . componentType = componentType ;
0 commit comments