MCPcopy Create free account
hub / github.com/angular/angular / collectQueryResults

Function collectQueryResults

packages/core/src/render3/queries/query.ts:426–463  ·  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

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