refactor(ivy): rename LQuery to LQueries and associated renames (#21857)
PR Close #21857
This commit is contained in:
parent
285dd6be34
commit
7305e8b45e
@ -11,7 +11,7 @@ import './ng_dev_mode';
|
|||||||
import {assertEqual, assertLessThan, assertNotEqual, assertNotNull} from './assert';
|
import {assertEqual, assertLessThan, assertNotEqual, assertNotNull} from './assert';
|
||||||
import {LContainer, TContainer} from './interfaces/container';
|
import {LContainer, TContainer} from './interfaces/container';
|
||||||
import {CssSelector, LProjection} from './interfaces/projection';
|
import {CssSelector, LProjection} from './interfaces/projection';
|
||||||
import {LQuery, QueryReadType} from './interfaces/query';
|
import {LQueries} from './interfaces/query';
|
||||||
import {LView, LifecycleStage, TData, TView} from './interfaces/view';
|
import {LView, LifecycleStage, TData, TView} from './interfaces/view';
|
||||||
|
|
||||||
import {LContainerNode, LElementNode, LNode, LNodeFlags, LProjectionNode, LTextNode, LViewNode, TNode, TContainerNode, InitialInputData, InitialInputs, PropertyAliases, PropertyAliasValue,} from './interfaces/node';
|
import {LContainerNode, LElementNode, LNode, LNodeFlags, LProjectionNode, LTextNode, LViewNode, TNode, TContainerNode, InitialInputData, InitialInputs, PropertyAliases, PropertyAliasValue,} from './interfaces/node';
|
||||||
@ -76,7 +76,7 @@ let currentView: LView;
|
|||||||
// The initialization has to be after the `let`, otherwise `createLView` can't see `let`.
|
// The initialization has to be after the `let`, otherwise `createLView` can't see `let`.
|
||||||
currentView = createLView(null !, null !, createTView());
|
currentView = createLView(null !, null !, createTView());
|
||||||
|
|
||||||
let currentQuery: LQuery|null;
|
let currentQueries: LQueries|null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This property gets set before entering a template.
|
* This property gets set before entering a template.
|
||||||
@ -141,7 +141,7 @@ export function enterView(newView: LView, host: LElementNode | LViewNode | null)
|
|||||||
}
|
}
|
||||||
|
|
||||||
currentView = newView;
|
currentView = newView;
|
||||||
currentQuery = newView.query;
|
currentQueries = newView.queries;
|
||||||
|
|
||||||
return oldView !;
|
return oldView !;
|
||||||
}
|
}
|
||||||
@ -178,7 +178,7 @@ export function createLView(
|
|||||||
context: context,
|
context: context,
|
||||||
dynamicViewCount: 0,
|
dynamicViewCount: 0,
|
||||||
lifecycleStage: LifecycleStage.INIT,
|
lifecycleStage: LifecycleStage.INIT,
|
||||||
query: null,
|
queries: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
return newView;
|
return newView;
|
||||||
@ -205,8 +205,9 @@ export function createLNode(
|
|||||||
LContainerNode&LProjectionNode {
|
LContainerNode&LProjectionNode {
|
||||||
const parent = isParent ? previousOrParentNode :
|
const parent = isParent ? previousOrParentNode :
|
||||||
previousOrParentNode && previousOrParentNode.parent as LNode;
|
previousOrParentNode && previousOrParentNode.parent as LNode;
|
||||||
let query = (isParent ? currentQuery : previousOrParentNode && previousOrParentNode.query) ||
|
let queries =
|
||||||
parent && parent.query && parent.query.child();
|
(isParent ? currentQueries : previousOrParentNode && previousOrParentNode.queries) ||
|
||||||
|
parent && parent.queries && parent.queries.child();
|
||||||
const isState = state != null;
|
const isState = state != null;
|
||||||
const node: LElementNode<extNode&LViewNode&LContainerNode&LProjectionNode = {
|
const node: LElementNode<extNode&LViewNode&LContainerNode&LProjectionNode = {
|
||||||
flags: type,
|
flags: type,
|
||||||
@ -217,7 +218,7 @@ export function createLNode(
|
|||||||
next: null,
|
next: null,
|
||||||
nodeInjector: parent ? parent.nodeInjector : null,
|
nodeInjector: parent ? parent.nodeInjector : null,
|
||||||
data: isState ? state as any : null,
|
data: isState ? state as any : null,
|
||||||
query: query,
|
queries: queries,
|
||||||
tNode: null,
|
tNode: null,
|
||||||
pNextOrParent: null
|
pNextOrParent: null
|
||||||
};
|
};
|
||||||
@ -242,7 +243,7 @@ export function createLNode(
|
|||||||
|
|
||||||
// Now link ourselves into the tree.
|
// Now link ourselves into the tree.
|
||||||
if (isParent) {
|
if (isParent) {
|
||||||
currentQuery = null;
|
currentQueries = null;
|
||||||
if (previousOrParentNode.view === currentView ||
|
if (previousOrParentNode.view === currentView ||
|
||||||
(previousOrParentNode.flags & LNodeFlags.TYPE_MASK) === LNodeFlags.View) {
|
(previousOrParentNode.flags & LNodeFlags.TYPE_MASK) === LNodeFlags.View) {
|
||||||
// We are in the same view, which means we are adding content node to the parent View.
|
// We are in the same view, which means we are adding content node to the parent View.
|
||||||
@ -606,8 +607,8 @@ export function elementEnd() {
|
|||||||
previousOrParentNode = previousOrParentNode.parent !;
|
previousOrParentNode = previousOrParentNode.parent !;
|
||||||
}
|
}
|
||||||
ngDevMode && assertNodeType(previousOrParentNode, LNodeFlags.Element);
|
ngDevMode && assertNodeType(previousOrParentNode, LNodeFlags.Element);
|
||||||
const query = previousOrParentNode.query;
|
const queries = previousOrParentNode.queries;
|
||||||
query && query.addNode(previousOrParentNode);
|
queries && queries.addNode(previousOrParentNode);
|
||||||
queueLifecycleHooks(previousOrParentNode.flags, currentView);
|
queueLifecycleHooks(previousOrParentNode.flags, currentView);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1000,7 +1001,7 @@ export function container(
|
|||||||
next: null,
|
next: null,
|
||||||
parent: currentView,
|
parent: currentView,
|
||||||
dynamicViewCount: 0,
|
dynamicViewCount: 0,
|
||||||
query: null
|
queries: null
|
||||||
};
|
};
|
||||||
|
|
||||||
const node = createLNode(index, LNodeFlags.Container, undefined, lContainer);
|
const node = createLNode(index, LNodeFlags.Container, undefined, lContainer);
|
||||||
@ -1018,12 +1019,12 @@ export function container(
|
|||||||
|
|
||||||
isParent = false;
|
isParent = false;
|
||||||
ngDevMode && assertNodeType(previousOrParentNode, LNodeFlags.Container);
|
ngDevMode && assertNodeType(previousOrParentNode, LNodeFlags.Container);
|
||||||
const query = node.query;
|
const queries = node.queries;
|
||||||
if (query) {
|
if (queries) {
|
||||||
// check if a given container node matches
|
// check if a given container node matches
|
||||||
query.addNode(node);
|
queries.addNode(node);
|
||||||
// prepare place for matching nodes from views inserted into a given container
|
// prepare place for matching nodes from views inserted into a given container
|
||||||
lContainer.query = query.container();
|
lContainer.queries = queries.container();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1109,8 +1110,8 @@ export function viewStart(viewBlockId: number): boolean {
|
|||||||
// When we create a new LView, we always reset the state of the instructions.
|
// When we create a new LView, we always reset the state of the instructions.
|
||||||
const newView =
|
const newView =
|
||||||
createLView(viewBlockId, renderer, getOrCreateEmbeddedTView(viewBlockId, container));
|
createLView(viewBlockId, renderer, getOrCreateEmbeddedTView(viewBlockId, container));
|
||||||
if (lContainer.query) {
|
if (lContainer.queries) {
|
||||||
newView.query = lContainer.query.enterView(lContainer.nextIndex);
|
newView.queries = lContainer.queries.enterView(lContainer.nextIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
enterView(newView, createLNode(null, LNodeFlags.View, null, newView));
|
enterView(newView, createLNode(null, LNodeFlags.View, null, newView));
|
||||||
@ -1845,8 +1846,8 @@ function valueInData<T>(data: any[], index: number, value?: T): T {
|
|||||||
return value !;
|
return value !;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getCurrentQuery(QueryType: {new (): LQuery}): LQuery {
|
export function getCurrentQueries(QueryType: {new (): LQueries}): LQueries {
|
||||||
return currentQuery || (currentQuery = new QueryType());
|
return currentQueries || (currentQueries = new QueryType());
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getPreviousOrParentNode(): LNode {
|
export function getPreviousOrParentNode(): LNode {
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
import {ComponentTemplate} from './definition';
|
import {ComponentTemplate} from './definition';
|
||||||
import {LElementNode, LViewNode} from './node';
|
import {LElementNode, LViewNode} from './node';
|
||||||
import {LQuery} from './query';
|
import {LQueries} from './query';
|
||||||
import {LView, TView} from './view';
|
import {LView, TView} from './view';
|
||||||
|
|
||||||
|
|
||||||
@ -79,7 +79,7 @@ export interface LContainer {
|
|||||||
* Queries active for this container - all the views inserted to / removed from
|
* Queries active for this container - all the views inserted to / removed from
|
||||||
* this container are reported to queries referenced here.
|
* this container are reported to queries referenced here.
|
||||||
*/
|
*/
|
||||||
query: LQuery|null;
|
queries: LQueries|null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -7,10 +7,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {LContainer, TContainer} from './container';
|
import {LContainer, TContainer} from './container';
|
||||||
import {DirectiveDef} from './definition';
|
|
||||||
import {LInjector} from './injector';
|
import {LInjector} from './injector';
|
||||||
import {LProjection} from './projection';
|
import {LProjection} from './projection';
|
||||||
import {LQuery} from './query';
|
import {LQueries} from './query';
|
||||||
import {RElement, RNode, RText} from './renderer';
|
import {RElement, RNode, RText} from './renderer';
|
||||||
import {LView, TData, TView} from './view';
|
import {LView, TData, TView} from './view';
|
||||||
|
|
||||||
@ -116,11 +115,11 @@ export interface LNode {
|
|||||||
nodeInjector: LInjector|null;
|
nodeInjector: LInjector|null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Optional `QueryState` used for tracking queries.
|
* Optional set of queries that track query-related events for this node.
|
||||||
*
|
*
|
||||||
* If present the node creation/updates are reported to the `QueryState`.
|
* If present the node creation/updates are reported to the `LQueries`.
|
||||||
*/
|
*/
|
||||||
query: LQuery|null;
|
queries: LQueries|null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If this node is projected, pointer to the next node in the same projection parent
|
* If this node is projected, pointer to the next node in the same projection parent
|
||||||
|
@ -12,36 +12,36 @@ import {LNode} from './node';
|
|||||||
|
|
||||||
|
|
||||||
/** Used for tracking queries (e.g. ViewChild, ContentChild). */
|
/** Used for tracking queries (e.g. ViewChild, ContentChild). */
|
||||||
export interface LQuery {
|
export interface LQueries {
|
||||||
/**
|
/**
|
||||||
* Used to ask query if it should be cloned to the child element.
|
* Used to ask queries if those should be cloned to the child element.
|
||||||
*
|
*
|
||||||
* For example in the case of deep queries the `child()` returns
|
* For example in the case of deep queries the `child()` returns
|
||||||
* query for the child node. In case of shallow queries it returns
|
* queries for the child node. In case of shallow queries it returns
|
||||||
* `null`.
|
* `null`.
|
||||||
*/
|
*/
|
||||||
child(): LQuery|null;
|
child(): LQueries|null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notify `LQuery` that a new `LNode` has been created and needs to be added to query results
|
* Notify `LQueries` that a new `LNode` has been created and needs to be added to query results
|
||||||
* if matching query predicate.
|
* if matching query predicate.
|
||||||
*/
|
*/
|
||||||
addNode(node: LNode): void;
|
addNode(node: LNode): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notify `LQuery` that a `LNode` has been created and needs to be added to query results
|
* Notify `LQueries` that a `LNode` has been created and needs to be added to query results
|
||||||
* if matching query predicate.
|
* if matching query predicate.
|
||||||
*/
|
*/
|
||||||
container(): LQuery|null;
|
container(): LQueries|null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notify `LQuery` that a new view was created and is being entered in the creation mode.
|
* Notify `LQueries` that a new view was created and is being entered in the creation mode.
|
||||||
* This allow queries to prepare space for matching nodes from views.
|
* This allow queries to prepare space for matching nodes from views.
|
||||||
*/
|
*/
|
||||||
enterView(newViewIndex: number): LQuery|null;
|
enterView(newViewIndex: number): LQueries|null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notify `LQuery` that an `LViewNode` has been removed from `LContainerNode`. As a result all
|
* Notify `LQueries` that an `LViewNode` has been removed from `LContainerNode`. As a result all
|
||||||
* the matching nodes from this view should be removed from container's queries.
|
* the matching nodes from this view should be removed from container's queries.
|
||||||
*/
|
*/
|
||||||
removeView(removeIndex: number): void;
|
removeView(removeIndex: number): void;
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
import {LContainer} from './container';
|
import {LContainer} from './container';
|
||||||
import {ComponentTemplate, DirectiveDef} from './definition';
|
import {ComponentTemplate, DirectiveDef} from './definition';
|
||||||
import {LElementNode, LViewNode, TNode} from './node';
|
import {LElementNode, LViewNode, TNode} from './node';
|
||||||
import {LQuery} from './query';
|
import {LQueries} from './query';
|
||||||
import {Renderer3} from './renderer';
|
import {Renderer3} from './renderer';
|
||||||
|
|
||||||
|
|
||||||
@ -175,7 +175,7 @@ export interface LView {
|
|||||||
/**
|
/**
|
||||||
* Queries active for this view - nodes from a view are reported to those queries
|
* Queries active for this view - nodes from a view are reported to those queries
|
||||||
*/
|
*/
|
||||||
query: LQuery|null;
|
queries: LQueries|null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Interface necessary to work with view tree traversal */
|
/** Interface necessary to work with view tree traversal */
|
||||||
|
@ -313,7 +313,7 @@ export function removeView(container: LContainerNode, removeIndex: number): LVie
|
|||||||
destroyViewTree(viewNode.data);
|
destroyViewTree(viewNode.data);
|
||||||
addRemoveViewFromContainer(container, viewNode, false);
|
addRemoveViewFromContainer(container, viewNode, false);
|
||||||
// Notify query that view has been removed
|
// Notify query that view has been removed
|
||||||
container.data.query && container.data.query.removeView(removeIndex);
|
container.data.queries && container.data.queries.removeView(removeIndex);
|
||||||
return viewNode;
|
return viewNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,11 +17,11 @@ import {getSymbolIterator} from '../util';
|
|||||||
|
|
||||||
import {assertEqual, assertNotNull} from './assert';
|
import {assertEqual, assertNotNull} from './assert';
|
||||||
import {ReadFromInjectorFn, getOrCreateNodeInjectorForNode} from './di';
|
import {ReadFromInjectorFn, getOrCreateNodeInjectorForNode} from './di';
|
||||||
import {assertPreviousIsParent, getCurrentQuery} from './instructions';
|
import {assertPreviousIsParent, getCurrentQueries} from './instructions';
|
||||||
import {DirectiveDef, unusedValueExportToPlacateAjd as unused1} from './interfaces/definition';
|
import {DirectiveDef, unusedValueExportToPlacateAjd as unused1} from './interfaces/definition';
|
||||||
import {LInjector, unusedValueExportToPlacateAjd as unused2} from './interfaces/injector';
|
import {LInjector, unusedValueExportToPlacateAjd as unused2} from './interfaces/injector';
|
||||||
import {LContainerNode, LElementNode, LNode, LNodeFlags, TNode, unusedValueExportToPlacateAjd as unused3} from './interfaces/node';
|
import {LContainerNode, LElementNode, LNode, LNodeFlags, TNode, unusedValueExportToPlacateAjd as unused3} from './interfaces/node';
|
||||||
import {LQuery, QueryReadType, unusedValueExportToPlacateAjd as unused4} from './interfaces/query';
|
import {LQueries, QueryReadType, unusedValueExportToPlacateAjd as unused4} from './interfaces/query';
|
||||||
import {flatten} from './util';
|
import {flatten} from './util';
|
||||||
|
|
||||||
const unusedValueToPlacateAjd = unused1 + unused2 + unused3 + unused4;
|
const unusedValueToPlacateAjd = unused1 + unused2 + unused3 + unused4;
|
||||||
@ -64,7 +64,7 @@ export interface QueryPredicate<T> {
|
|||||||
values: any[];
|
values: any[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export class LQuery_ implements LQuery {
|
export class LQueries_ implements LQueries {
|
||||||
shallow: QueryPredicate<any>|null = null;
|
shallow: QueryPredicate<any>|null = null;
|
||||||
deep: QueryPredicate<any>|null = null;
|
deep: QueryPredicate<any>|null = null;
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ export class LQuery_ implements LQuery {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
child(): LQuery|null {
|
child(): LQueries|null {
|
||||||
if (this.deep === null) {
|
if (this.deep === null) {
|
||||||
// if we don't have any deep queries then no need to track anything more.
|
// if we don't have any deep queries then no need to track anything more.
|
||||||
return null;
|
return null;
|
||||||
@ -94,11 +94,11 @@ export class LQuery_ implements LQuery {
|
|||||||
return this;
|
return this;
|
||||||
} else {
|
} else {
|
||||||
// We need to create new state
|
// We need to create new state
|
||||||
return new LQuery_(this.deep);
|
return new LQueries_(this.deep);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
container(): LQuery|null {
|
container(): LQueries|null {
|
||||||
let result: QueryPredicate<any>|null = null;
|
let result: QueryPredicate<any>|null = null;
|
||||||
let predicate = this.deep;
|
let predicate = this.deep;
|
||||||
|
|
||||||
@ -118,10 +118,10 @@ export class LQuery_ implements LQuery {
|
|||||||
predicate = predicate.next;
|
predicate = predicate.next;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result ? new LQuery_(result) : null;
|
return result ? new LQueries_(result) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
enterView(index: number): LQuery|null {
|
enterView(index: number): LQueries|null {
|
||||||
let result: QueryPredicate<any>|null = null;
|
let result: QueryPredicate<any>|null = null;
|
||||||
let predicate = this.deep;
|
let predicate = this.deep;
|
||||||
|
|
||||||
@ -141,7 +141,7 @@ export class LQuery_ implements LQuery {
|
|||||||
predicate = predicate.next;
|
predicate = predicate.next;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result ? new LQuery_(result) : null;
|
return result ? new LQueries_(result) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
addNode(node: LNode): void {
|
addNode(node: LNode): void {
|
||||||
@ -165,12 +165,12 @@ export class LQuery_ implements LQuery {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clone LQuery by taking all the deep query predicates and cloning those using a provided clone
|
* Clone LQueries by taking all the deep query predicates and cloning those using a provided clone
|
||||||
* function.
|
* function.
|
||||||
* Shallow predicates are ignored.
|
* Shallow predicates are ignored.
|
||||||
*/
|
*/
|
||||||
private _clonePredicates(
|
private _clonePredicates(
|
||||||
predicateCloneFn: (predicate: QueryPredicate<any>) => QueryPredicate<any>): LQuery|null {
|
predicateCloneFn: (predicate: QueryPredicate<any>) => QueryPredicate<any>): LQueries|null {
|
||||||
let result: QueryPredicate<any>|null = null;
|
let result: QueryPredicate<any>|null = null;
|
||||||
let predicate = this.deep;
|
let predicate = this.deep;
|
||||||
|
|
||||||
@ -181,7 +181,7 @@ export class LQuery_ implements LQuery {
|
|||||||
predicate = predicate.next;
|
predicate = predicate.next;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result ? new LQuery_(result) : null;
|
return result ? new LQueries_(result) : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -386,8 +386,8 @@ export function query<T>(
|
|||||||
read?: QueryReadType<T>| Type<T>): QueryList<T> {
|
read?: QueryReadType<T>| Type<T>): QueryList<T> {
|
||||||
ngDevMode && assertPreviousIsParent();
|
ngDevMode && assertPreviousIsParent();
|
||||||
const queryList = new QueryList<T>();
|
const queryList = new QueryList<T>();
|
||||||
const query = getCurrentQuery(LQuery_);
|
const queries = getCurrentQueries(LQueries_);
|
||||||
query.track(queryList, predicate, descend, read);
|
queries.track(queryList, predicate, descend, read);
|
||||||
return queryList;
|
return queryList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -396,11 +396,11 @@ export function query<T>(
|
|||||||
* views.
|
* views.
|
||||||
* Returns true if a query got dirty during change detection, false otherwise.
|
* Returns true if a query got dirty during change detection, false otherwise.
|
||||||
*/
|
*/
|
||||||
export function queryRefresh(query: QueryList<any>): boolean {
|
export function queryRefresh(queryList: QueryList<any>): boolean {
|
||||||
const queryImpl = (query as any as QueryList_<any>);
|
const queryListImpl = (queryList as any as QueryList_<any>);
|
||||||
if (query.dirty) {
|
if (queryList.dirty) {
|
||||||
query.reset(queryImpl._valuesTree);
|
queryList.reset(queryListImpl._valuesTree);
|
||||||
query.notifyOnChanges();
|
queryList.notifyOnChanges();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user