MCPcopy Index your code
hub / github.com/angular/angular / registerPostOrderHooks

Function registerPostOrderHooks

packages/core/src/render3/hooks.ts:97–140  ·  view source on GitHub ↗
(tView: TView, tNode: TNode)

Source from the content-addressed store, hash-verified

95 * @param tNode The TNode whose directives are to be searched for hooks to queue
96 */
97export function registerPostOrderHooks(tView: TView, tNode: TNode): void {
98 ngDevMode && assertFirstCreatePass(tView);
99 // It's necessary to loop through the directives at elementEnd() (rather than processing in
100 // directiveCreate) so we can preserve the current hook order. Content, view, and destroy
101 // hooks for projected components and directives must be called *before* their hosts.
102 for (let i = tNode.directiveStart, end = tNode.directiveEnd; i < end; i++) {
103 const directiveDef = tView.data[i] as DirectiveDef<any>;
104 ngDevMode && assertDefined(directiveDef, 'Expecting DirectiveDef');
105 const lifecycleHooks: AfterContentInit &
106 AfterContentChecked &
107 AfterViewInit &
108 AfterViewChecked &
109 OnDestroy = directiveDef.type.prototype;
110 const {
111 ngAfterContentInit,
112 ngAfterContentChecked,
113 ngAfterViewInit,
114 ngAfterViewChecked,
115 ngOnDestroy,
116 } = lifecycleHooks;
117
118 if (ngAfterContentInit) {
119 (tView.contentHooks ??= []).push(-i, ngAfterContentInit);
120 }
121
122 if (ngAfterContentChecked) {
123 (tView.contentHooks ??= []).push(i, ngAfterContentChecked);
124 (tView.contentCheckHooks ??= []).push(i, ngAfterContentChecked);
125 }
126
127 if (ngAfterViewInit) {
128 (tView.viewHooks ??= []).push(-i, ngAfterViewInit);
129 }
130
131 if (ngAfterViewChecked) {
132 (tView.viewHooks ??= []).push(i, ngAfterViewChecked);
133 (tView.viewCheckHooks ??= []).push(i, ngAfterViewChecked);
134 }
135
136 if (ngOnDestroy != null) {
137 (tView.destroyHooks ??= []).push(i, ngOnDestroy);
138 }
139 }
140}
141
142/**
143 * Executing hooks requires complex logic as we need to deal with 2 constraints.

Callers 2

Calls 3

assertFirstCreatePassFunction · 0.90
assertDefinedFunction · 0.90
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…