fix(ivy): report results to appropriate content queries (#24673)
PR Close #24673
This commit is contained in:

committed by
Jason Aden

parent
fe8fcc834c
commit
50fb13fb09
@ -127,9 +127,19 @@ let tView: TView;
|
||||
|
||||
let currentQueries: LQueries|null;
|
||||
|
||||
/**
|
||||
* Query instructions can ask for "current queries" in 2 different cases:
|
||||
* - when creating view queries (at the root of a component view, before any node is created - in
|
||||
* this case currentQueries points to view queries)
|
||||
* - when creating content queries (inb this previousOrParentNode points to a node on which we
|
||||
* create content queries).
|
||||
*/
|
||||
export function getCurrentQueries(QueryType: {new (): LQueries}): LQueries {
|
||||
// top level variables should not be exported for performance reasons (PERF_NOTES.md)
|
||||
return currentQueries || (currentQueries = (previousOrParentNode.queries || new QueryType()));
|
||||
return currentQueries ||
|
||||
(currentQueries =
|
||||
(previousOrParentNode.queries && previousOrParentNode.queries.clone() ||
|
||||
new QueryType()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -13,7 +13,14 @@ import {LNode} from './node';
|
||||
/** Used for tracking queries (e.g. ViewChild, ContentChild). */
|
||||
export interface LQueries {
|
||||
/**
|
||||
* Used to ask querieis if those should be cloned to the child element.
|
||||
* Ask queries to prepare copy of itself. This assures that tracking new queries on child nodes
|
||||
* doesn't mutate list of queries tracked on a parent node. We will clone LQueries before
|
||||
* constructing content queries.
|
||||
*/
|
||||
clone(): LQueries|null;
|
||||
|
||||
/**
|
||||
* Used to ask queries if those should be cloned to the child element.
|
||||
*
|
||||
* For example in the case of deep queries the `child()` returns
|
||||
* queries for the child node. In case of shallow queries it returns
|
||||
|
@ -94,8 +94,6 @@ export class LQueries_ implements LQueries {
|
||||
track<T>(
|
||||
queryList: viewEngine_QueryList<T>, predicate: Type<T>|string[], descend?: boolean,
|
||||
read?: QueryReadType<T>|Type<T>): void {
|
||||
// TODO(misko): This is not right. In case of inherited state, a calling track will incorrectly
|
||||
// mutate parent.
|
||||
if (descend) {
|
||||
this.deep = createQuery(this.deep, queryList, predicate, read != null ? read : null);
|
||||
} else {
|
||||
@ -103,6 +101,8 @@ export class LQueries_ implements LQueries {
|
||||
}
|
||||
}
|
||||
|
||||
clone(): LQueries|null { return this.deep ? new LQueries_(this.deep) : null; }
|
||||
|
||||
child(): LQueries|null {
|
||||
if (this.deep === null) {
|
||||
// if we don't have any deep queries then no need to track anything more.
|
||||
|
Reference in New Issue
Block a user