refactor(ivy): rename QueryPredicate to LQuery (#21857)
PR Close #21857
This commit is contained in:
parent
7305e8b45e
commit
4c1743cce3
|
@ -28,13 +28,16 @@ const unusedValueToPlacateAjd = unused1 + unused2 + unused3 + unused4;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A predicate which determines if a given element/directive should be included in the query
|
* An object representing a query, which is a combination of:
|
||||||
|
* - query predicate to determines if a given element/directive should be included in the query
|
||||||
|
* - values collected based on a predicate
|
||||||
|
* - `QueryList` to which collected values should be reported
|
||||||
*/
|
*/
|
||||||
export interface QueryPredicate<T> {
|
export interface LQuery<T> {
|
||||||
/**
|
/**
|
||||||
* Next predicate
|
* Next query. Used when queries are stored as a linked list in `LQueries`.
|
||||||
*/
|
*/
|
||||||
next: QueryPredicate<any>|null;
|
next: LQuery<any>|null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destination to which the value should be added.
|
* Destination to which the value should be added.
|
||||||
|
@ -65,10 +68,10 @@ export interface QueryPredicate<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class LQueries_ implements LQueries {
|
export class LQueries_ implements LQueries {
|
||||||
shallow: QueryPredicate<any>|null = null;
|
shallow: LQuery<any>|null = null;
|
||||||
deep: QueryPredicate<any>|null = null;
|
deep: LQuery<any>|null = null;
|
||||||
|
|
||||||
constructor(deep?: QueryPredicate<any>) { this.deep = deep == null ? null : deep; }
|
constructor(deep?: LQuery<any>) { this.deep = deep == null ? null : deep; }
|
||||||
|
|
||||||
track<T>(
|
track<T>(
|
||||||
queryList: viewEngine_QueryList<T>, predicate: Type<T>|string[], descend?: boolean,
|
queryList: viewEngine_QueryList<T>, predicate: Type<T>|string[], descend?: boolean,
|
||||||
|
@ -76,10 +79,9 @@ export class LQueries_ implements LQueries {
|
||||||
// TODO(misko): This is not right. In case of inherited state, a calling track will incorrectly
|
// TODO(misko): This is not right. In case of inherited state, a calling track will incorrectly
|
||||||
// mutate parent.
|
// mutate parent.
|
||||||
if (descend) {
|
if (descend) {
|
||||||
this.deep = createPredicate(this.deep, queryList, predicate, read != null ? read : null);
|
this.deep = createQuery(this.deep, queryList, predicate, read != null ? read : null);
|
||||||
} else {
|
} else {
|
||||||
this.shallow =
|
this.shallow = createQuery(this.shallow, queryList, predicate, read != null ? read : null);
|
||||||
createPredicate(this.shallow, queryList, predicate, read != null ? read : null);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,46 +101,46 @@ export class LQueries_ implements LQueries {
|
||||||
}
|
}
|
||||||
|
|
||||||
container(): LQueries|null {
|
container(): LQueries|null {
|
||||||
let result: QueryPredicate<any>|null = null;
|
let result: LQuery<any>|null = null;
|
||||||
let predicate = this.deep;
|
let query = this.deep;
|
||||||
|
|
||||||
while (predicate) {
|
while (query) {
|
||||||
const containerValues: any[] = []; // prepare room for views
|
const containerValues: any[] = []; // prepare room for views
|
||||||
predicate.values.push(containerValues);
|
query.values.push(containerValues);
|
||||||
const clonedPredicate: QueryPredicate<any> = {
|
const clonedQuery: LQuery<any> = {
|
||||||
next: null,
|
next: null,
|
||||||
list: predicate.list,
|
list: query.list,
|
||||||
type: predicate.type,
|
type: query.type,
|
||||||
selector: predicate.selector,
|
selector: query.selector,
|
||||||
read: predicate.read,
|
read: query.read,
|
||||||
values: containerValues
|
values: containerValues
|
||||||
};
|
};
|
||||||
clonedPredicate.next = result;
|
clonedQuery.next = result;
|
||||||
result = clonedPredicate;
|
result = clonedQuery;
|
||||||
predicate = predicate.next;
|
query = query.next;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result ? new LQueries_(result) : null;
|
return result ? new LQueries_(result) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
enterView(index: number): LQueries|null {
|
enterView(index: number): LQueries|null {
|
||||||
let result: QueryPredicate<any>|null = null;
|
let result: LQuery<any>|null = null;
|
||||||
let predicate = this.deep;
|
let query = this.deep;
|
||||||
|
|
||||||
while (predicate) {
|
while (query) {
|
||||||
const viewValues: any[] = []; // prepare room for view nodes
|
const viewValues: any[] = []; // prepare room for view nodes
|
||||||
predicate.values.splice(index, 0, viewValues);
|
query.values.splice(index, 0, viewValues);
|
||||||
const clonedPredicate: QueryPredicate<any> = {
|
const clonedQuery: LQuery<any> = {
|
||||||
next: null,
|
next: null,
|
||||||
list: predicate.list,
|
list: query.list,
|
||||||
type: predicate.type,
|
type: query.type,
|
||||||
selector: predicate.selector,
|
selector: query.selector,
|
||||||
read: predicate.read,
|
read: query.read,
|
||||||
values: viewValues
|
values: viewValues
|
||||||
};
|
};
|
||||||
clonedPredicate.next = result;
|
clonedQuery.next = result;
|
||||||
result = clonedPredicate;
|
result = clonedQuery;
|
||||||
predicate = predicate.next;
|
query = query.next;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result ? new LQueries_(result) : null;
|
return result ? new LQueries_(result) : null;
|
||||||
|
@ -150,39 +152,19 @@ export class LQueries_ implements LQueries {
|
||||||
}
|
}
|
||||||
|
|
||||||
removeView(index: number): void {
|
removeView(index: number): void {
|
||||||
let predicate = this.deep;
|
let query = this.deep;
|
||||||
while (predicate) {
|
while (query) {
|
||||||
const removed = predicate.values.splice(index, 1);
|
const removed = query.values.splice(index, 1);
|
||||||
|
|
||||||
// mark a query as dirty only when removed view had matching modes
|
// mark a query as dirty only when removed view had matching modes
|
||||||
ngDevMode && assertEqual(removed.length, 1, 'removed.length');
|
ngDevMode && assertEqual(removed.length, 1, 'removed.length');
|
||||||
if (removed[0].length) {
|
if (removed[0].length) {
|
||||||
predicate.list.setDirty();
|
query.list.setDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
predicate = predicate.next;
|
query = query.next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Clone LQueries by taking all the deep query predicates and cloning those using a provided clone
|
|
||||||
* function.
|
|
||||||
* Shallow predicates are ignored.
|
|
||||||
*/
|
|
||||||
private _clonePredicates(
|
|
||||||
predicateCloneFn: (predicate: QueryPredicate<any>) => QueryPredicate<any>): LQueries|null {
|
|
||||||
let result: QueryPredicate<any>|null = null;
|
|
||||||
let predicate = this.deep;
|
|
||||||
|
|
||||||
while (predicate) {
|
|
||||||
const clonedPredicate = predicateCloneFn(predicate);
|
|
||||||
clonedPredicate.next = result;
|
|
||||||
result = clonedPredicate;
|
|
||||||
predicate = predicate.next;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result ? new LQueries_(result) : null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -240,49 +222,48 @@ function readFromNodeInjector(
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function add(predicate: QueryPredicate<any>| null, node: LNode) {
|
function add(query: LQuery<any>| null, node: LNode) {
|
||||||
const nodeInjector = getOrCreateNodeInjectorForNode(node as LElementNode | LContainerNode);
|
const nodeInjector = getOrCreateNodeInjectorForNode(node as LElementNode | LContainerNode);
|
||||||
while (predicate) {
|
while (query) {
|
||||||
const type = predicate.type;
|
const type = query.type;
|
||||||
if (type) {
|
if (type) {
|
||||||
const directiveIdx = geIdxOfMatchingDirective(node, type);
|
const directiveIdx = geIdxOfMatchingDirective(node, type);
|
||||||
if (directiveIdx !== null) {
|
if (directiveIdx !== null) {
|
||||||
// a node is matching a predicate - determine what to read
|
// a node is matching a predicate - determine what to read
|
||||||
// if read token and / or strategy is not specified, use type as read token
|
// if read token and / or strategy is not specified, use type as read token
|
||||||
const result =
|
const result = readFromNodeInjector(nodeInjector, node, query.read || type, directiveIdx);
|
||||||
readFromNodeInjector(nodeInjector, node, predicate.read || type, directiveIdx);
|
|
||||||
if (result !== null) {
|
if (result !== null) {
|
||||||
addMatch(predicate, result);
|
addMatch(query, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const selector = predicate.selector !;
|
const selector = query.selector !;
|
||||||
for (let i = 0; i < selector.length; i++) {
|
for (let i = 0; i < selector.length; i++) {
|
||||||
ngDevMode && assertNotNull(node.tNode, 'node.tNode');
|
ngDevMode && assertNotNull(node.tNode, 'node.tNode');
|
||||||
const directiveIdx = getIdxOfMatchingSelector(node.tNode !, selector[i]);
|
const directiveIdx = getIdxOfMatchingSelector(node.tNode !, selector[i]);
|
||||||
if (directiveIdx !== null) {
|
if (directiveIdx !== null) {
|
||||||
// a node is matching a predicate - determine what to read
|
// a node is matching a predicate - determine what to read
|
||||||
// note that queries using name selector must specify read strategy
|
// note that queries using name selector must specify read strategy
|
||||||
ngDevMode && assertNotNull(predicate.read, 'predicate.read');
|
ngDevMode && assertNotNull(query.read, 'query.read');
|
||||||
const result = readFromNodeInjector(nodeInjector, node, predicate.read !, directiveIdx);
|
const result = readFromNodeInjector(nodeInjector, node, query.read !, directiveIdx);
|
||||||
if (result !== null) {
|
if (result !== null) {
|
||||||
addMatch(predicate, result);
|
addMatch(query, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
predicate = predicate.next;
|
query = query.next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function addMatch(predicate: QueryPredicate<any>, matchingValue: any): void {
|
function addMatch(query: LQuery<any>, matchingValue: any): void {
|
||||||
predicate.values.push(matchingValue);
|
query.values.push(matchingValue);
|
||||||
predicate.list.setDirty();
|
query.list.setDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
function createPredicate<T>(
|
function createQuery<T>(
|
||||||
previous: QueryPredicate<any>| null, queryList: QueryList<T>, predicate: Type<T>| string[],
|
previous: LQuery<any>| null, queryList: QueryList<T>, predicate: Type<T>| string[],
|
||||||
read: QueryReadType<T>| Type<T>| null): QueryPredicate<T> {
|
read: QueryReadType<T>| Type<T>| null): LQuery<T> {
|
||||||
const isArray = Array.isArray(predicate);
|
const isArray = Array.isArray(predicate);
|
||||||
return {
|
return {
|
||||||
next: previous,
|
next: previous,
|
||||||
|
|
Loading…
Reference in New Issue