MCPcopy
hub / github.com/angular/angular / collectQueryResults

Function collectQueryResults

packages/core/src/render3/queries/query.ts:422–459  ·  view source on GitHub ↗

* A helper function that collects (already materialized) query results from a tree of views, * starting with a provided LView.

(tView: TView, lView: LView, queryIndex: number, result: T[])

Source from the content-addressed store, hash-verified

420 * starting with a provided LView.
421 */
422function collectQueryResults<T>(tView: TView, lView: LView, queryIndex: number, result: T[]): T[] {
423 const tQuery = tView.queries!.getByIndex(queryIndex);
424 const tQueryMatches = tQuery.matches;
425 if (tQueryMatches !== null) {
426 const lViewResults = materializeViewResults<T>(tView, lView, tQuery, queryIndex);
427
428 for (let i = 0; i < tQueryMatches.length; i += 2) {
429 const tNodeIdx = tQueryMatches[i];
430 if (tNodeIdx > 0) {
431 result.push(lViewResults[i / 2] as T);
432 } else {
433 const childQueryIndex = tQueryMatches[i + 1];
434
435 const declarationLContainer = lView[-tNodeIdx] as LContainer;
436 ngDevMode && assertLContainer(declarationLContainer);
437
438 // collect matches for views inserted in this container
439 for (let i = CONTAINER_HEADER_OFFSET; i < declarationLContainer.length; i++) {
440 const embeddedLView = declarationLContainer[i];
441 if (embeddedLView[DECLARATION_LCONTAINER] === embeddedLView[PARENT]) {
442 collectQueryResults(embeddedLView[TVIEW], embeddedLView, childQueryIndex, result);
443 }
444 }
445
446 // collect matches for views created from this declaration container and inserted into
447 // different containers
448 if (declarationLContainer[MOVED_VIEWS] !== null) {
449 const embeddedLViews = declarationLContainer[MOVED_VIEWS]!;
450 for (let i = 0; i < embeddedLViews.length; i++) {
451 const embeddedLView = embeddedLViews[i];
452 collectQueryResults(embeddedLView[TVIEW], embeddedLView, childQueryIndex, result);
453 }
454 }
455 }
456 }
457 }
458 return result;
459}
460
461export function loadQueryInternal<T>(lView: LView, queryIndex: number): QueryList<T> {
462 ngDevMode &&

Callers 1

getQueryResultsFunction · 0.85

Calls 4

assertLContainerFunction · 0.90
materializeViewResultsFunction · 0.85
getByIndexMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…