@@ -19,7 +19,7 @@ import {RuntimeError, RuntimeErrorCode} from '../../errors';
1919import { assertDefined , assertEqual } from '../../util/assert' ;
2020import { executeCheckHooks , executeInitAndCheckHooks , incrementInitPhaseFlags } from '../hooks' ;
2121import { CONTAINER_HEADER_OFFSET , LContainerFlags , MOVED_VIEWS } from '../interfaces/container' ;
22- import { ComponentTemplate , RenderFlags } from '../interfaces/definition' ;
22+ import { ComponentTemplate , HostBindingsFunction , RenderFlags } from '../interfaces/definition' ;
2323import {
2424 CONTEXT ,
2525 EFFECTS_TO_SCHEDULE ,
@@ -47,8 +47,10 @@ import {
4747 isRefreshingViews ,
4848 leaveView ,
4949 setBindingIndex ,
50+ setBindingRootForHostBindings ,
5051 setIsInCheckNoChangesMode ,
5152 setIsRefreshingViews ,
53+ setSelectedIndex ,
5254} from '../state' ;
5355import { getFirstLContainer , getNextLContainer } from '../util/view_traversal_utils' ;
5456import {
@@ -61,15 +63,12 @@ import {
6163 viewAttachedToChangeDetector ,
6264} from '../util/view_utils' ;
6365
64- import {
65- executeTemplate ,
66- executeViewQueryFn ,
67- handleError ,
68- processHostBindingOpCodes ,
69- refreshContentQueries ,
70- } from './shared' ;
71- import { runEffectsInView } from '../reactivity/view_effect_runner' ;
7266import { isDestroyed } from '../interfaces/type_checks' ;
67+ import { ProfilerEvent } from '../profiler_types' ;
68+ import { profiler } from '../profiler' ;
69+ import { runEffectsInView } from '../reactivity/view_effect_runner' ;
70+ import { executeTemplate , handleError } from './shared' ;
71+ import { executeViewQueryFn , refreshContentQueries } from '../queries/query_execution' ;
7372
7473/**
7574 * The maximum number of times the change detection traversal will rerun before throwing an error.
@@ -514,3 +513,38 @@ function detectChangesInChildComponents(
514513 detectChangesInComponent ( hostLView , components [ i ] , mode ) ;
515514 }
516515}
516+
517+ /**
518+ * Invoke `HostBindingsFunction`s for view.
519+ *
520+ * This methods executes `TView.hostBindingOpCodes`. It is used to execute the
521+ * `HostBindingsFunction`s associated with the current `LView`.
522+ *
523+ * @param tView Current `TView`.
524+ * @param lView Current `LView`.
525+ */
526+ function processHostBindingOpCodes ( tView : TView , lView : LView ) : void {
527+ const hostBindingOpCodes = tView . hostBindingOpCodes ;
528+ if ( hostBindingOpCodes === null ) return ;
529+ try {
530+ for ( let i = 0 ; i < hostBindingOpCodes . length ; i ++ ) {
531+ const opCode = hostBindingOpCodes [ i ] as number ;
532+ if ( opCode < 0 ) {
533+ // Negative numbers are element indexes.
534+ setSelectedIndex ( ~ opCode ) ;
535+ } else {
536+ // Positive numbers are NumberTuple which store bindingRootIndex and directiveIndex.
537+ const directiveIdx = opCode ;
538+ const bindingRootIndx = hostBindingOpCodes [ ++ i ] as number ;
539+ const hostBindingFn = hostBindingOpCodes [ ++ i ] as HostBindingsFunction < any > ;
540+ setBindingRootForHostBindings ( bindingRootIndx , directiveIdx ) ;
541+ const context = lView [ directiveIdx ] ;
542+ profiler ( ProfilerEvent . HostBindingsUpdateStart , context ) ;
543+ hostBindingFn ( RenderFlags . Update , context ) ;
544+ profiler ( ProfilerEvent . HostBindingsUpdateEnd , context ) ;
545+ }
546+ }
547+ } finally {
548+ setSelectedIndex ( - 1 ) ;
549+ }
550+ }
0 commit comments