fix(ivy): restore missing match operation in View and Content Queries (#26847)
PR Close #26847
This commit is contained in:
@ -269,7 +269,7 @@ function getIdxOfMatchingDirective(tNode: TNode, currentView: LViewData, type: T
|
||||
}
|
||||
|
||||
// TODO: "read" should be an AbstractType (FW-486)
|
||||
function queryRead(tNode: TNode, currentView: LViewData, read: any): any {
|
||||
function queryByReadToken(read: any, tNode: TNode, currentView: LViewData): any {
|
||||
const factoryFn = (read as any)[NG_ELEMENT_ID];
|
||||
if (typeof factoryFn === 'function') {
|
||||
return factoryFn();
|
||||
@ -282,7 +282,7 @@ function queryRead(tNode: TNode, currentView: LViewData, read: any): any {
|
||||
return null;
|
||||
}
|
||||
|
||||
function queryReadByTNodeType(tNode: TNode, currentView: LViewData): any {
|
||||
function queryByTNodeType(tNode: TNode, currentView: LViewData): any {
|
||||
if (tNode.type === TNodeType.Element || tNode.type === TNodeType.ElementContainer) {
|
||||
return createElementRef(ViewEngine_ElementRef, tNode, currentView);
|
||||
}
|
||||
@ -292,37 +292,54 @@ function queryReadByTNodeType(tNode: TNode, currentView: LViewData): any {
|
||||
return null;
|
||||
}
|
||||
|
||||
function queryByTemplateRef(
|
||||
templateRefToken: ViewEngine_TemplateRef<any>, tNode: TNode, currentView: LViewData,
|
||||
read: any): any {
|
||||
const templateRefResult = (templateRefToken as any)[NG_ELEMENT_ID]();
|
||||
if (read) {
|
||||
return templateRefResult ? queryByReadToken(read, tNode, currentView) : null;
|
||||
}
|
||||
return templateRefResult;
|
||||
}
|
||||
|
||||
function queryRead(tNode: TNode, currentView: LViewData, read: any, matchingIdx: number): any {
|
||||
if (read) {
|
||||
return queryByReadToken(read, tNode, currentView);
|
||||
}
|
||||
if (matchingIdx > -1) {
|
||||
return currentView[matchingIdx];
|
||||
}
|
||||
// if read token and / or strategy is not specified,
|
||||
// detect it using appropriate tNode type
|
||||
return queryByTNodeType(tNode, currentView);
|
||||
}
|
||||
|
||||
function add(
|
||||
query: LQuery<any>| null, tNode: TElementNode | TContainerNode | TElementContainerNode) {
|
||||
const currentView = getViewData();
|
||||
|
||||
while (query) {
|
||||
const predicate = query.predicate;
|
||||
const type = predicate.type;
|
||||
const type = predicate.type as any;
|
||||
if (type) {
|
||||
// if read token and / or strategy is not specified, use type as read token
|
||||
const result = queryRead(tNode, currentView, predicate.read || type);
|
||||
let result = null;
|
||||
if (type === ViewEngine_TemplateRef) {
|
||||
result = queryByTemplateRef(type, tNode, currentView, predicate.read);
|
||||
} else {
|
||||
const matchingIdx = getIdxOfMatchingDirective(tNode, currentView, type);
|
||||
if (matchingIdx !== null) {
|
||||
result = queryRead(tNode, currentView, predicate.read, matchingIdx);
|
||||
}
|
||||
}
|
||||
if (result !== null) {
|
||||
addMatch(query, result);
|
||||
}
|
||||
} else {
|
||||
const selector = predicate.selector !;
|
||||
for (let i = 0; i < selector.length; i++) {
|
||||
const directiveIdx = getIdxOfMatchingSelector(tNode, selector[i]);
|
||||
if (directiveIdx !== null) {
|
||||
let result: any = null;
|
||||
if (predicate.read) {
|
||||
result = queryRead(tNode, currentView, predicate.read);
|
||||
} else {
|
||||
if (directiveIdx > -1) {
|
||||
result = currentView[directiveIdx];
|
||||
} else {
|
||||
// if read token and / or strategy is not specified,
|
||||
// detect it using appropriate tNode type
|
||||
result = queryReadByTNodeType(tNode, currentView);
|
||||
}
|
||||
}
|
||||
|
||||
const matchingIdx = getIdxOfMatchingSelector(tNode, selector[i]);
|
||||
if (matchingIdx !== null) {
|
||||
const result = queryRead(tNode, currentView, predicate.read, matchingIdx);
|
||||
if (result !== null) {
|
||||
addMatch(query, result);
|
||||
}
|
||||
|
Reference in New Issue
Block a user