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

Function triggerResourceLoading

packages/core/src/defer/triggering.ts:169–313  ·  view source on GitHub ↗
(
  tDetails: TDeferBlockDetails,
  lView: LView,
  tNode: TNode,
)

Source from the content-addressed store, hash-verified

167 * @param lView LView of a host view.
168 */
169export function triggerResourceLoading(
170 tDetails: TDeferBlockDetails,
171 lView: LView,
172 tNode: TNode,
173): Promise<unknown> {
174 const injector = lView[INJECTOR];
175 const tView = lView[TVIEW];
176
177 if (tDetails.loadingState !== DeferDependenciesLoadingState.NOT_STARTED) {
178 // If the loading status is different from initial one, it means that
179 // the loading of dependencies is in progress and there is nothing to do
180 // in this function. All details can be obtained from the `tDetails` object.
181 return tDetails.loadingPromise ?? Promise.resolve();
182 }
183
184 const lDetails = getLDeferBlockDetails(lView, tNode);
185 const primaryBlockTNode = getPrimaryBlockTNode(tView, tDetails);
186
187 // Switch from NOT_STARTED -> IN_PROGRESS state.
188 tDetails.loadingState = DeferDependenciesLoadingState.IN_PROGRESS;
189
190 // Prefetching is triggered, cleanup all registered prefetch triggers.
191 invokeTriggerCleanupFns(TriggerType.Prefetch, lDetails);
192
193 let dependenciesFn = tDetails.dependencyResolverFn;
194
195 if (ngDevMode) {
196 // Check if dependency function interceptor is configured.
197 const deferDependencyInterceptor = injector.get(DEFER_BLOCK_DEPENDENCY_INTERCEPTOR, null, {
198 optional: true,
199 });
200
201 if (deferDependencyInterceptor) {
202 dependenciesFn = deferDependencyInterceptor.intercept(dependenciesFn);
203 }
204 }
205
206 // Indicate that an application is not stable and has a pending task.
207 const removeTask = injector.get(PendingTasks).add();
208
209 // The `dependenciesFn` might be `null` when all dependencies within
210 // a given defer block were eagerly referenced elsewhere in a file,
211 // thus no dynamic `import()`s were produced.
212 if (!dependenciesFn) {
213 tDetails.loadingPromise = Promise.resolve().then(() => {
214 tDetails.loadingPromise = null;
215 tDetails.loadingState = DeferDependenciesLoadingState.COMPLETE;
216 removeTask();
217 });
218 return tDetails.loadingPromise;
219 }
220
221 // Start downloading of defer block dependencies.
222 tDetails.loadingPromise = Promise.allSettled(dependenciesFn()).then((results) => {
223 let failed = false;
224 let failedReason: Error | null = null;
225 const directiveDefs: DirectiveDefList = [];
226 const pipeDefs: PipeDefList = [];

Callers 4

triggerPrefetchingFunction · 0.85
triggerDeferBlockFunction · 0.85
renderMethod · 0.85

Calls 15

getLDeferBlockDetailsFunction · 0.90
getPrimaryBlockTNodeFunction · 0.90
invokeTriggerCleanupFnsFunction · 0.90
getComponentDefFunction · 0.90
getDirectiveDefFunction · 0.90
getPipeDefFunction · 0.90
handleUncaughtErrorFunction · 0.90
addDepsToRegistryFunction · 0.90
allSettledMethod · 0.80
mapMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…