@@ -27,14 +27,15 @@ import {StylingContext} from '../interfaces/styling';
27
27
import { BINDING_INDEX , CHILD_HEAD , CHILD_TAIL , CLEANUP , CONTEXT , DECLARATION_VIEW , ExpandoInstructions , FLAGS , HEADER_OFFSET , HOST , INJECTOR , InitPhaseState , LView , LViewFlags , NEXT , PARENT , QUERIES , RENDERER , RENDERER_FACTORY , RootContext , RootContextFlags , SANITIZER , TVIEW , TView , T_HOST } from '../interfaces/view' ;
28
28
import { assertNodeOfPossibleTypes , assertNodeType } from '../node_assert' ;
29
29
import { isNodeMatchingSelectorList } from '../node_selector_matcher' ;
30
- import { enterView , getBindingsEnabled , getCheckNoChangesMode , getIsParent , getLView , getNamespace , getPreviousOrParentTNode , isCreationMode , leaveView , namespaceHTML , resetComponentState , setActiveHost , setBindingRoot , setCheckNoChangesMode , setCurrentDirectiveDef , setCurrentQueryIndex , setIsParent , setPreviousOrParentTNode , setSelectedIndex } from '../state' ;
30
+ import { enterView , getBindingsEnabled , getCheckNoChangesMode , getIsParent , getLView , getNamespace , getPreviousOrParentTNode , incrementActiveDirectiveId , isCreationMode , leaveView , namespaceHTML , resetComponentState , setActiveHostElement , setBindingRoot , setCheckNoChangesMode , setCurrentDirectiveDef , setCurrentQueryIndex , setIsParent , setPreviousOrParentTNode , setSelectedIndex } from '../state' ;
31
31
import { initializeStaticContext as initializeStaticStylingContext } from '../styling/class_and_style_bindings' ;
32
32
import { NO_CHANGE } from '../tokens' ;
33
33
import { attrsStylingIndexOf } from '../util/attrs_utils' ;
34
34
import { INTERPOLATION_DELIMITER , renderStringify } from '../util/misc_utils' ;
35
35
import { getLViewParent , getRootContext } from '../util/view_traversal_utils' ;
36
36
import { getComponentViewByIndex , getNativeByTNode , isComponentDef , isContentQueryHost , isRootView , readPatchedLView , resetPreOrderHookFlags , unwrapRNode , viewAttachedToChangeDetector } from '../util/view_utils' ;
37
37
38
+
38
39
/**
39
40
* A permanent marker promise which signifies that the current CD tree is
40
41
* clean.
@@ -107,6 +108,8 @@ export function setHostBindings(tView: TView, viewData: LView): void {
107
108
// Negative numbers mean that we are starting new EXPANDO block and need to update
108
109
// the current element and directive index.
109
110
currentElementIndex = - instruction ;
111
+ setActiveHostElement ( currentElementIndex ) ;
112
+
110
113
// Injector block and providers are taken into account.
111
114
const providerCount = ( tView . expandoInstructions [ ++ i ] as number ) ;
112
115
bindingRootIndex += INJECTOR_BLOOM_PARENT_SIZE + providerCount ;
@@ -124,14 +127,20 @@ export function setHostBindings(tView: TView, viewData: LView): void {
124
127
if ( instruction !== null ) {
125
128
viewData [ BINDING_INDEX ] = bindingRootIndex ;
126
129
const hostCtx = unwrapRNode ( viewData [ currentDirectiveIndex ] ) ;
127
- setActiveHost ( hostCtx , currentElementIndex ) ;
128
130
instruction ( RenderFlags . Update , hostCtx , currentElementIndex ) ;
129
- setActiveHost ( null ) ;
131
+
132
+ // Each directive gets a uniqueId value that is the same for both
133
+ // create and update calls when the hostBindings function is called. The
134
+ // directive uniqueId is not set anywhere--it is just incremented between
135
+ // each hostBindings call and is useful for helping instruction code
136
+ // uniquely determine which directive is currently active when executed.
137
+ incrementActiveDirectiveId ( ) ;
130
138
}
131
139
currentDirectiveIndex ++ ;
132
140
}
133
141
}
134
142
}
143
+ setActiveHostElement ( null ) ;
135
144
}
136
145
137
146
/** Refreshes content queries for all directives in the given view. */
@@ -897,15 +906,27 @@ function invokeDirectivesHostBindings(tView: TView, viewData: LView, tNode: TNod
897
906
const end = tNode . directiveEnd ;
898
907
const expando = tView . expandoInstructions ! ;
899
908
const firstTemplatePass = tView . firstTemplatePass ;
909
+ const elementIndex = tNode . index - HEADER_OFFSET ;
910
+ setActiveHostElement ( elementIndex ) ;
911
+
900
912
for ( let i = start ; i < end ; i ++ ) {
901
913
const def = tView . data [ i ] as DirectiveDef < any > ;
902
914
const directive = viewData [ i ] ;
903
915
if ( def . hostBindings ) {
904
916
invokeHostBindingsInCreationMode ( def , expando , directive , tNode , firstTemplatePass ) ;
917
+
918
+ // Each directive gets a uniqueId value that is the same for both
919
+ // create and update calls when the hostBindings function is called. The
920
+ // directive uniqueId is not set anywhere--it is just incremented between
921
+ // each hostBindings call and is useful for helping instruction code
922
+ // uniquely determine which directive is currently active when executed.
923
+ incrementActiveDirectiveId ( ) ;
905
924
} else if ( firstTemplatePass ) {
906
925
expando . push ( null ) ;
907
926
}
908
927
}
928
+
929
+ setActiveHostElement ( null ) ;
909
930
}
910
931
911
932
export function invokeHostBindingsInCreationMode (
@@ -914,9 +935,7 @@ export function invokeHostBindingsInCreationMode(
914
935
const previousExpandoLength = expando . length ;
915
936
setCurrentDirectiveDef ( def ) ;
916
937
const elementIndex = tNode . index - HEADER_OFFSET ;
917
- setActiveHost ( directive , elementIndex ) ;
918
938
def . hostBindings ! ( RenderFlags . Create , directive , elementIndex ) ;
919
- setActiveHost ( null ) ;
920
939
setCurrentDirectiveDef ( null ) ;
921
940
// `hostBindings` function may or may not contain `allocHostVars` call
922
941
// (e.g. it may not if it only contains host listeners), so we need to check whether
0 commit comments