Skip to content

Commit 74daef1

Browse files
refactor(core): move logic out of shared instructions code (#59453)
This is first of a series of refactorings that moves code around such that logic from the shared instruction file is dispatched to the relevant functional parts. PR Close #59453
1 parent 0d019e9 commit 74daef1

File tree

16 files changed

+230
-222
lines changed

16 files changed

+230
-222
lines changed

packages/core/src/authoring/queries.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
createMultiResultQuerySignalFn,
1313
createSingleResultOptionalQuerySignalFn,
1414
createSingleResultRequiredQuerySignalFn,
15-
} from '../render3/query_reactive';
15+
} from '../render3/queries/query_reactive';
1616
import {Signal} from '../render3/reactivity/api';
1717

1818
function viewChildFn<LocatorT, ReadT>(

packages/core/src/render3/component_ref.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ import {
4343
addToEndOfViewTree,
4444
createLView,
4545
createTView,
46-
executeContentQueries,
4746
getInitialLViewFlagsFromDef,
4847
getOrCreateComponentTView,
4948
getOrCreateTNode,
@@ -89,6 +88,7 @@ import {getComponentLViewByIndex, getNativeByTNode, getTNode} from './util/view_
8988
import {ViewRef} from './view_ref';
9089
import {ChainedInjector} from './chained_injector';
9190
import {unregisterLView} from './interfaces/lview_tracking';
91+
import {executeContentQueries} from './queries/query_execution';
9292

9393
export class ComponentFactoryResolver extends AbstractComponentFactoryResolver {
9494
/**

packages/core/src/render3/instructions/change_detection.ts

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {RuntimeError, RuntimeErrorCode} from '../../errors';
1919
import {assertDefined, assertEqual} from '../../util/assert';
2020
import {executeCheckHooks, executeInitAndCheckHooks, incrementInitPhaseFlags} from '../hooks';
2121
import {CONTAINER_HEADER_OFFSET, LContainerFlags, MOVED_VIEWS} from '../interfaces/container';
22-
import {ComponentTemplate, RenderFlags} from '../interfaces/definition';
22+
import {ComponentTemplate, HostBindingsFunction, RenderFlags} from '../interfaces/definition';
2323
import {
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';
5355
import {getFirstLContainer, getNextLContainer} from '../util/view_traversal_utils';
5456
import {
@@ -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';
7266
import {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+
}

packages/core/src/render3/instructions/element.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import {
4848
createElementNode,
4949
setupStaticAttributes,
5050
} from '../node_manipulation';
51+
import {executeContentQueries} from '../queries/query_execution';
5152
import {
5253
decreaseElementDepthCount,
5354
enterSkipHydrationBlock,
@@ -74,7 +75,6 @@ import {validateElementIsKnown} from './element_validation';
7475
import {setDirectiveInputsWhichShadowsStyling} from './property';
7576
import {
7677
createDirectivesInstances,
77-
executeContentQueries,
7878
getOrCreateTNode,
7979
resolveDirectives,
8080
saveResolvedLocalsInData,

packages/core/src/render3/instructions/element_container.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {isContentQueryHost, isDirectiveHost} from '../interfaces/type_checks';
2424
import {HEADER_OFFSET, HYDRATION, LView, RENDERER, TView} from '../interfaces/view';
2525
import {assertTNodeType} from '../node_assert';
2626
import {appendChild, createCommentNode} from '../node_manipulation';
27+
import {executeContentQueries} from '../queries/query_execution';
2728
import {
2829
getBindingIndex,
2930
getCurrentTNode,
@@ -41,7 +42,6 @@ import {getConstant} from '../util/view_utils';
4142

4243
import {
4344
createDirectivesInstances,
44-
executeContentQueries,
4545
getOrCreateTNode,
4646
resolveDirectives,
4747
saveResolvedLocalsInData,

packages/core/src/render3/instructions/listener.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,16 @@ import {assertTNodeType} from '../node_assert';
1919
import {profiler} from '../profiler';
2020
import {ProfilerEvent} from '../profiler_types';
2121
import {getCurrentDirectiveDef, getCurrentTNode, getLView, getTView} from '../state';
22-
import {getComponentLViewByIndex, getNativeByTNode, unwrapRNode} from '../util/view_utils';
23-
24-
import {markViewDirty} from './mark_view_dirty';
2522
import {
23+
getComponentLViewByIndex,
24+
getNativeByTNode,
2625
getOrCreateLViewCleanup,
2726
getOrCreateTViewCleanup,
28-
handleError,
29-
loadComponentRenderer,
30-
} from './shared';
27+
unwrapRNode,
28+
} from '../util/view_utils';
29+
30+
import {markViewDirty} from './mark_view_dirty';
31+
import {handleError, loadComponentRenderer} from './shared';
3132

3233
/**
3334
* Contains a reference to a function that disables event replay feature

packages/core/src/render3/instructions/queries.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
getQueryResults,
1717
getTQuery,
1818
loadQueryInternal,
19-
} from '../query';
19+
} from '../queries/query';
2020
import {getCurrentQueryIndex, getLView, getTView, setCurrentQueryIndex} from '../state';
2121
import {isCreationMode} from '../util/view_utils';
2222

packages/core/src/render3/instructions/queries_signals.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
import {ProviderToken} from '../../di/provider_token';
1010
import {QueryFlags} from '../interfaces/query';
11-
import {createContentQuery, createViewQuery} from '../query';
12-
import {bindQueryToSignal} from '../query_reactive';
11+
import {createContentQuery, createViewQuery} from '../queries/query';
12+
import {bindQueryToSignal} from '../queries/query_reactive';
1313
import {Signal} from '../reactivity/api';
1414
import {getCurrentQueryIndex, setCurrentQueryIndex} from '../state';
1515

packages/core/src/render3/instructions/render.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ import {
2121
TVIEW,
2222
TView,
2323
} from '../interfaces/view';
24+
import {executeViewQueryFn, refreshContentQueries} from '../queries/query_execution';
2425
import {enterView, leaveView} from '../state';
2526
import {getComponentLViewByIndex, isCreationMode} from '../util/view_utils';
2627

27-
import {executeTemplate, executeViewQueryFn, refreshContentQueries} from './shared';
28+
import {executeTemplate} from './shared';
2829

2930
export function renderComponent(hostLView: LView, componentHostIdx: number) {
3031
ngDevMode && assertEqual(isCreationMode(hostLView), true, 'Should be run in creation mode');

0 commit comments

Comments
 (0)