refactor(ivy): avoid calling query instructions from static query instructions (#30587)
PR Close #30587
This commit is contained in:
parent
2fe6f350cb
commit
b613f90146
|
@ -24,7 +24,7 @@ import {unusedValueExportToPlacateAjd as unused1} from './interfaces/definition'
|
|||
import {unusedValueExportToPlacateAjd as unused2} from './interfaces/injector';
|
||||
import {TContainerNode, TElementContainerNode, TElementNode, TNode, TNodeType, unusedValueExportToPlacateAjd as unused3} from './interfaces/node';
|
||||
import {LQueries, unusedValueExportToPlacateAjd as unused4} from './interfaces/query';
|
||||
import {CONTENT_QUERIES, HEADER_OFFSET, LView, QUERIES, TVIEW} from './interfaces/view';
|
||||
import {CONTENT_QUERIES, HEADER_OFFSET, LView, QUERIES, TVIEW, TView} from './interfaces/view';
|
||||
import {getCurrentQueryIndex, getIsParent, getLView, isCreationMode, setCurrentQueryIndex} from './state';
|
||||
import {loadInternal} from './util/view_utils';
|
||||
import {createElementRef, createTemplateRef} from './view_engine_compatibility';
|
||||
|
@ -370,12 +370,13 @@ type QueryList_<T> = QueryList<T>& {_valuesTree: any[], _static: boolean};
|
|||
*/
|
||||
function query<T>(
|
||||
// TODO: "read" should be an AbstractType (FW-486)
|
||||
lView: LView, predicate: Type<any>| string[], descend: boolean, read: any): QueryList<T> {
|
||||
lView: LView, predicate: Type<any>| string[], descend: boolean, read: any,
|
||||
isStatic: boolean): QueryList<T> {
|
||||
ngDevMode && assertPreviousIsParent(getIsParent());
|
||||
const queryList = new QueryList<T>() as QueryList_<T>;
|
||||
const queries = lView[QUERIES] || (lView[QUERIES] = new LQueries_(null, null, null));
|
||||
queryList._valuesTree = [];
|
||||
queryList._static = false;
|
||||
queryList._static = isStatic;
|
||||
queries.track(queryList, predicate, descend, read);
|
||||
storeCleanupWithContext(lView, queryList, queryList.destroy);
|
||||
return queryList;
|
||||
|
@ -415,12 +416,10 @@ export function ɵɵqueryRefresh(queryList: QueryList<any>): boolean {
|
|||
export function ɵɵstaticViewQuery<T>(
|
||||
// TODO(FW-486): "read" should be an AbstractType
|
||||
predicate: Type<any>| string[], descend: boolean, read: any): void {
|
||||
const queryList = ɵɵviewQuery(predicate, descend, read) as QueryList_<T>;
|
||||
const tView = getLView()[TVIEW];
|
||||
queryList._static = true;
|
||||
if (!tView.staticViewQueries) {
|
||||
tView.staticViewQueries = true;
|
||||
}
|
||||
const lView = getLView();
|
||||
const tView = lView[TVIEW];
|
||||
viewQueryInternal(lView, tView, predicate, descend, read, true);
|
||||
tView.staticViewQueries = true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -438,14 +437,20 @@ export function ɵɵviewQuery<T>(
|
|||
predicate: Type<any>| string[], descend: boolean, read: any): QueryList<T> {
|
||||
const lView = getLView();
|
||||
const tView = lView[TVIEW];
|
||||
return viewQueryInternal(lView, tView, predicate, descend, read, false);
|
||||
}
|
||||
|
||||
function viewQueryInternal<T>(
|
||||
lView: LView, tView: TView, predicate: Type<any>| string[], descend: boolean, read: any,
|
||||
isStatic: boolean): QueryList<T> {
|
||||
if (tView.firstTemplatePass) {
|
||||
tView.expandoStartIndex++;
|
||||
}
|
||||
const index = getCurrentQueryIndex();
|
||||
const viewQuery: QueryList<T> = query<T>(lView, predicate, descend, read);
|
||||
store(index - HEADER_OFFSET, viewQuery);
|
||||
const queryList: QueryList<T> = query<T>(lView, predicate, descend, read, isStatic);
|
||||
store(index - HEADER_OFFSET, queryList);
|
||||
setCurrentQueryIndex(index + 1);
|
||||
return viewQuery;
|
||||
return queryList;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -477,7 +482,15 @@ export function ɵɵcontentQuery<T>(
|
|||
read: any): QueryList<T> {
|
||||
const lView = getLView();
|
||||
const tView = lView[TVIEW];
|
||||
const contentQuery: QueryList<T> = query<T>(lView, predicate, descend, read);
|
||||
return contentQueryInternal(lView, tView, directiveIndex, predicate, descend, read, false);
|
||||
}
|
||||
|
||||
function contentQueryInternal<T>(
|
||||
lView: LView, tView: TView, directiveIndex: number, predicate: Type<any>| string[],
|
||||
descend: boolean,
|
||||
// TODO(FW-486): "read" should be an AbstractType
|
||||
read: any, isStatic: boolean): QueryList<T> {
|
||||
const contentQuery: QueryList<T> = query<T>(lView, predicate, descend, read, isStatic);
|
||||
(lView[CONTENT_QUERIES] || (lView[CONTENT_QUERIES] = [])).push(contentQuery);
|
||||
if (tView.firstTemplatePass) {
|
||||
const tViewContentQueries = tView.contentQueries || (tView.contentQueries = []);
|
||||
|
@ -506,12 +519,10 @@ export function ɵɵstaticContentQuery<T>(
|
|||
directiveIndex: number, predicate: Type<any>| string[], descend: boolean,
|
||||
// TODO(FW-486): "read" should be an AbstractType
|
||||
read: any): void {
|
||||
const queryList = ɵɵcontentQuery(directiveIndex, predicate, descend, read) as QueryList_<T>;
|
||||
const tView = getLView()[TVIEW];
|
||||
queryList._static = true;
|
||||
if (!tView.staticContentQueries) {
|
||||
tView.staticContentQueries = true;
|
||||
}
|
||||
const lView = getLView();
|
||||
const tView = lView[TVIEW];
|
||||
contentQueryInternal(lView, tView, directiveIndex, predicate, descend, read, true);
|
||||
tView.staticContentQueries = true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue