9
9
import { InjectFlags , InjectionToken , Injector } from '../di' ;
10
10
import { resolveForwardRef } from '../di/forward_ref' ;
11
11
import { Type } from '../interface/type' ;
12
- import { QueryList } from '../linker' ;
13
12
import { validateAttribute , validateProperty } from '../sanitization/sanitization' ;
14
13
import { Sanitizer } from '../sanitization/security' ;
15
14
import { StyleSanitizeFn } from '../sanitization/style_sanitizer' ;
@@ -36,7 +35,7 @@ import {BINDING_INDEX, CLEANUP, CONTAINER_INDEX, CONTENT_QUERIES, CONTEXT, DECLA
36
35
import { assertNodeOfPossibleTypes , assertNodeType } from './node_assert' ;
37
36
import { appendChild , appendProjectedNode , createTextNode , getLViewChild , insertView , removeView } from './node_manipulation' ;
38
37
import { isNodeMatchingSelectorList , matchingSelectorIndex } from './node_selector_matcher' ;
39
- import { decreaseElementDepthCount , enterView , getBindingsEnabled , getCheckNoChangesMode , getContextLView , getCurrentDirectiveDef , getCurrentQueryIndex , getElementDepthCount , getFirstTemplatePass , getIsParent , getLView , getPreviousOrParentTNode , increaseElementDepthCount , isCreationMode , leaveView , nextContextImpl , resetComponentState , setBindingRoot , setCheckNoChangesMode , setCurrentDirectiveDef , setCurrentQueryIndex , setFirstTemplatePass , setIsParent , setPreviousOrParentTNode } from './state' ;
38
+ import { decreaseElementDepthCount , enterView , getBindingsEnabled , getCheckNoChangesMode , getContextLView , getCurrentDirectiveDef , getCurrentQueryIndex , getElementDepthCount , getIsParent , getLView , getPreviousOrParentTNode , increaseElementDepthCount , isCreationMode , leaveView , nextContextImpl , resetComponentState , setBindingRoot , setCheckNoChangesMode , setCurrentDirectiveDef , setCurrentQueryIndex , setIsParent , setPreviousOrParentTNode } from './state' ;
40
39
import { getInitialClassNameValue , initializeStaticContext as initializeStaticStylingContext , patchContextWithStaticAttrs , renderInitialStylesAndClasses , renderStyling , updateClassProp as updateElementClassProp , updateContextWithBindings , updateStyleProp as updateElementStyleProp , updateStylingMap } from './styling/class_and_style_bindings' ;
41
40
import { BoundPlayerFactory } from './styling/player_factory' ;
42
41
import { createEmptyStylingContext , getStylingContext , hasClassInput , hasStyling , isAnimationProp } from './styling/util' ;
@@ -66,7 +65,6 @@ export function refreshDescendantViews(lView: LView) {
66
65
const tView = lView [ TVIEW ] ;
67
66
// This needs to be set before children are processed to support recursive components
68
67
tView . firstTemplatePass = false ;
69
- setFirstTemplatePass ( false ) ;
70
68
71
69
// Resetting the bindingIndex of the current LView as the next steps may trigger change detection.
72
70
lView [ BINDING_INDEX ] = tView . bindingStartIndex ;
@@ -380,7 +378,6 @@ export function renderEmbeddedTemplate<T>(viewToRender: LView, tView: TView, con
380
378
// off firstTemplatePass. If we don't set it here, instances will perform directive
381
379
// matching, etc again and again.
382
380
viewToRender [ TVIEW ] . firstTemplatePass = false ;
383
- setFirstTemplatePass ( false ) ;
384
381
385
382
refreshDescendantViews ( viewToRender ) ;
386
383
} finally {
@@ -654,7 +651,7 @@ function createDirectivesAndLocals(
654
651
localRefExtractor : LocalRefExtractor = getNativeByTNode ) {
655
652
if ( ! getBindingsEnabled ( ) ) return ;
656
653
const previousOrParentTNode = getPreviousOrParentTNode ( ) ;
657
- if ( getFirstTemplatePass ( ) ) {
654
+ if ( tView . firstTemplatePass ) {
658
655
ngDevMode && ngDevMode . firstTemplatePass ++ ;
659
656
660
657
resolveDirectives (
@@ -1654,7 +1651,7 @@ function resolveDirectives(
1654
1651
tView : TView , viewData : LView , directives : DirectiveDef < any > [ ] | null , tNode : TNode ,
1655
1652
localRefs : string [ ] | null ) : void {
1656
1653
// Please make sure to have explicit type for `exportsMap`. Inferred type triggers bug in tsickle.
1657
- ngDevMode && assertEqual ( getFirstTemplatePass ( ) , true , 'should run on first template pass only' ) ;
1654
+ ngDevMode && assertEqual ( tView . firstTemplatePass , true , 'should run on first template pass only' ) ;
1658
1655
const exportsMap : ( { [ key : string ] : number } | null ) = localRefs ? { '' : - 1 } : null ;
1659
1656
if ( directives ) {
1660
1657
initNodeFlags ( tNode , tView . data . length , directives . length ) ;
@@ -1691,7 +1688,7 @@ function resolveDirectives(
1691
1688
function instantiateAllDirectives ( tView : TView , lView : LView , tNode : TNode ) {
1692
1689
const start = tNode . directiveStart ;
1693
1690
const end = tNode . directiveEnd ;
1694
- if ( ! getFirstTemplatePass ( ) && start < end ) {
1691
+ if ( ! tView . firstTemplatePass && start < end ) {
1695
1692
getOrCreateNodeInjectorForNode (
1696
1693
tNode as TElementNode | TContainerNode | TElementContainerNode , lView ) ;
1697
1694
}
@@ -1709,7 +1706,7 @@ function invokeDirectivesHostBindings(tView: TView, viewData: LView, tNode: TNod
1709
1706
const start = tNode . directiveStart ;
1710
1707
const end = tNode . directiveEnd ;
1711
1708
const expando = tView . expandoInstructions ! ;
1712
- const firstTemplatePass = getFirstTemplatePass ( ) ;
1709
+ const firstTemplatePass = tView . firstTemplatePass ;
1713
1710
for ( let i = start ; i < end ; i ++ ) {
1714
1711
const def = tView . data [ i ] as DirectiveDef < any > ;
1715
1712
const directive = viewData [ i ] ;
@@ -1757,7 +1754,7 @@ export function generateExpandoInstructionBlock(
1757
1754
*/
1758
1755
function prefillHostVars ( tView : TView , lView : LView , totalHostVars : number ) : void {
1759
1756
ngDevMode &&
1760
- assertEqual ( getFirstTemplatePass ( ) , true , 'Should only be called in first template pass.' ) ;
1757
+ assertEqual ( tView . firstTemplatePass , true , 'Should only be called in first template pass.' ) ;
1761
1758
for ( let i = 0 ; i < totalHostVars ; i ++ ) {
1762
1759
lView . push ( NO_CHANGE ) ;
1763
1760
tView . blueprint . push ( NO_CHANGE ) ;
@@ -1813,7 +1810,7 @@ function postProcessBaseDirective<T>(
1813
1810
*/
1814
1811
function findDirectiveMatches ( tView : TView , viewData : LView , tNode : TNode ) : DirectiveDef < any > [ ] |
1815
1812
null {
1816
- ngDevMode && assertEqual ( getFirstTemplatePass ( ) , true , 'should run on first template pass only' ) ;
1813
+ ngDevMode && assertEqual ( tView . firstTemplatePass , true , 'should run on first template pass only' ) ;
1817
1814
const registry = tView . directiveRegistry ;
1818
1815
let matches : any [ ] | null = null ;
1819
1816
if ( registry ) {
@@ -1844,9 +1841,9 @@ function findDirectiveMatches(tView: TView, viewData: LView, tNode: TNode): Dire
1844
1841
1845
1842
/** Stores index of component's host element so it will be queued for view refresh during CD. */
1846
1843
export function queueComponentIndexForCheck ( previousOrParentTNode : TNode ) : void {
1847
- ngDevMode &&
1848
- assertEqual ( getFirstTemplatePass ( ) , true , 'Should only be called in first template pass.' ) ;
1849
1844
const tView = getLView ( ) [ TVIEW ] ;
1845
+ ngDevMode &&
1846
+ assertEqual ( tView . firstTemplatePass , true , 'Should only be called in first template pass.' ) ;
1850
1847
( tView . components || ( tView . components = [ ] ) ) . push ( previousOrParentTNode . index ) ;
1851
1848
}
1852
1849
@@ -1857,7 +1854,7 @@ export function queueComponentIndexForCheck(previousOrParentTNode: TNode): void
1857
1854
function queueHostBindingForCheck (
1858
1855
tView : TView , def : DirectiveDef < any > | ComponentDef < any > , hostVars : number ) : void {
1859
1856
ngDevMode &&
1860
- assertEqual ( getFirstTemplatePass ( ) , true , 'Should only be called in first template pass.' ) ;
1857
+ assertEqual ( tView . firstTemplatePass , true , 'Should only be called in first template pass.' ) ;
1861
1858
const expando = tView . expandoInstructions ! ;
1862
1859
const length = expando . length ;
1863
1860
// Check whether a given `hostBindings` function already exists in expandoInstructions,
@@ -1912,7 +1909,6 @@ function saveNameToExportMap(
1912
1909
* @param index the initial index
1913
1910
*/
1914
1911
export function initNodeFlags ( tNode : TNode , index : number , numberOfDirectives : number ) {
1915
- ngDevMode && assertEqual ( getFirstTemplatePass ( ) , true , 'expected firstTemplatePass to be true' ) ;
1916
1912
const flags = tNode . flags ;
1917
1913
ngDevMode && assertEqual (
1918
1914
flags === 0 || flags === TNodeFlags . isComponent , true ,
@@ -1961,7 +1957,7 @@ function addComponentLogic<T>(
1961
1957
componentView [ HOST ] = lView [ previousOrParentTNode . index ] ;
1962
1958
lView [ previousOrParentTNode . index ] = componentView ;
1963
1959
1964
- if ( getFirstTemplatePass ( ) ) {
1960
+ if ( lView [ TVIEW ] . firstTemplatePass ) {
1965
1961
queueComponentIndexForCheck ( previousOrParentTNode ) ;
1966
1962
}
1967
1963
}
@@ -2098,7 +2094,7 @@ export function template(
2098
2094
// TODO: consider a separate node type for templates
2099
2095
const tNode = containerInternal ( index , tagName || null , attrs || null ) ;
2100
2096
2101
- if ( getFirstTemplatePass ( ) ) {
2097
+ if ( tView . firstTemplatePass ) {
2102
2098
tNode . tViews = createTView (
2103
2099
- 1 , templateFn , consts , vars , tView . directiveRegistry , tView . pipeRegistry , null ) ;
2104
2100
}
@@ -2126,7 +2122,10 @@ export function template(
2126
2122
*/
2127
2123
export function container ( index : number ) : void {
2128
2124
const tNode = containerInternal ( index , null , null ) ;
2129
- getFirstTemplatePass ( ) && ( tNode . tViews = [ ] ) ;
2125
+ const lView = getLView ( ) ;
2126
+ if ( lView [ TVIEW ] . firstTemplatePass ) {
2127
+ tNode . tViews = [ ] ;
2128
+ }
2130
2129
setIsParent ( false ) ;
2131
2130
}
2132
2131
@@ -2550,10 +2549,9 @@ export function projection(nodeIndex: number, selectorIndex: number = 0, attrs?:
2550
2549
export function addToViewTree < T extends LView | LContainer > (
2551
2550
lView : LView , adjustedHostIndex : number , state : T ) : T {
2552
2551
const tView = lView [ TVIEW ] ;
2553
- const firstTemplatePass = getFirstTemplatePass ( ) ;
2554
2552
if ( lView [ TAIL ] ) {
2555
2553
lView [ TAIL ] ! [ NEXT ] = state ;
2556
- } else if ( firstTemplatePass ) {
2554
+ } else if ( tView . firstTemplatePass ) {
2557
2555
tView . childIndex = adjustedHostIndex ;
2558
2556
}
2559
2557
lView [ TAIL ] = state ;
@@ -2813,9 +2811,9 @@ export function bind<T>(value: T): T|NO_CHANGE {
2813
2811
* @param count Amount of vars to be allocated
2814
2812
*/
2815
2813
export function allocHostVars ( count : number ) : void {
2816
- if ( ! getFirstTemplatePass ( ) ) return ;
2817
2814
const lView = getLView ( ) ;
2818
2815
const tView = lView [ TVIEW ] ;
2816
+ if ( ! tView . firstTemplatePass ) return ;
2819
2817
queueHostBindingForCheck ( tView , getCurrentDirectiveDef ( ) ! , count ) ;
2820
2818
prefillHostVars ( tView , lView , count ) ;
2821
2819
}
0 commit comments