refactor(ivy): rename LQuery to LQueries and associated renames (#21857)

PR Close #21857
This commit is contained in:
Pawel Kozlowski 2018-01-29 14:51:37 +01:00 committed by Jason Aden
parent 285dd6be34
commit 7305e8b45e
7 changed files with 58 additions and 58 deletions

View File

@ -11,7 +11,7 @@ import './ng_dev_mode';
import {assertEqual, assertLessThan, assertNotEqual, assertNotNull} from './assert';
import {LContainer, TContainer} from './interfaces/container';
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 {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`.
currentView = createLView(null !, null !, createTView());
let currentQuery: LQuery|null;
let currentQueries: LQueries|null;
/**
* This property gets set before entering a template.
@ -141,7 +141,7 @@ export function enterView(newView: LView, host: LElementNode | LViewNode | null)
}
currentView = newView;
currentQuery = newView.query;
currentQueries = newView.queries;
return oldView !;
}
@ -178,7 +178,7 @@ export function createLView(
context: context,
dynamicViewCount: 0,
lifecycleStage: LifecycleStage.INIT,
query: null,
queries: null,
};
return newView;
@ -205,8 +205,9 @@ export function createLNode(
LContainerNode&LProjectionNode {
const parent = isParent ? previousOrParentNode :
previousOrParentNode && previousOrParentNode.parent as LNode;
let query = (isParent ? currentQuery : previousOrParentNode && previousOrParentNode.query) ||
parent && parent.query && parent.query.child();
let queries =
(isParent ? currentQueries : previousOrParentNode && previousOrParentNode.queries) ||
parent && parent.queries && parent.queries.child();
const isState = state != null;
const node: LElementNode&LTextNode&LViewNode&LContainerNode&LProjectionNode = {
flags: type,
@ -217,7 +218,7 @@ export function createLNode(
next: null,
nodeInjector: parent ? parent.nodeInjector : null,
data: isState ? state as any : null,
query: query,
queries: queries,
tNode: null,
pNextOrParent: null
};
@ -242,7 +243,7 @@ export function createLNode(
// Now link ourselves into the tree.
if (isParent) {
currentQuery = null;
currentQueries = null;
if (previousOrParentNode.view === currentView ||
(previousOrParentNode.flags & LNodeFlags.TYPE_MASK) === LNodeFlags.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 !;
}
ngDevMode && assertNodeType(previousOrParentNode, LNodeFlags.Element);
const query = previousOrParentNode.query;
query && query.addNode(previousOrParentNode);
const queries = previousOrParentNode.queries;
queries && queries.addNode(previousOrParentNode);
queueLifecycleHooks(previousOrParentNode.flags, currentView);
}
@ -1000,7 +1001,7 @@ export function container(
next: null,
parent: currentView,
dynamicViewCount: 0,
query: null
queries: null
};
const node = createLNode(index, LNodeFlags.Container, undefined, lContainer);
@ -1018,12 +1019,12 @@ export function container(
isParent = false;
ngDevMode && assertNodeType(previousOrParentNode, LNodeFlags.Container);
const query = node.query;
if (query) {
const queries = node.queries;
if (queries) {
// 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
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.
const newView =
createLView(viewBlockId, renderer, getOrCreateEmbeddedTView(viewBlockId, container));
if (lContainer.query) {
newView.query = lContainer.query.enterView(lContainer.nextIndex);
if (lContainer.queries) {
newView.queries = lContainer.queries.enterView(lContainer.nextIndex);
}
enterView(newView, createLNode(null, LNodeFlags.View, null, newView));
@ -1845,8 +1846,8 @@ function valueInData<T>(data: any[], index: number, value?: T): T {
return value !;
}
export function getCurrentQuery(QueryType: {new (): LQuery}): LQuery {
return currentQuery || (currentQuery = new QueryType());
export function getCurrentQueries(QueryType: {new (): LQueries}): LQueries {
return currentQueries || (currentQueries = new QueryType());
}
export function getPreviousOrParentNode(): LNode {

View File

@ -8,7 +8,7 @@
import {ComponentTemplate} from './definition';
import {LElementNode, LViewNode} from './node';
import {LQuery} from './query';
import {LQueries} from './query';
import {LView, TView} from './view';
@ -79,7 +79,7 @@ export interface LContainer {
* Queries active for this container - all the views inserted to / removed from
* this container are reported to queries referenced here.
*/
query: LQuery|null;
queries: LQueries|null;
}
/**

View File

@ -7,10 +7,9 @@
*/
import {LContainer, TContainer} from './container';
import {DirectiveDef} from './definition';
import {LInjector} from './injector';
import {LProjection} from './projection';
import {LQuery} from './query';
import {LQueries} from './query';
import {RElement, RNode, RText} from './renderer';
import {LView, TData, TView} from './view';
@ -116,11 +115,11 @@ export interface LNode {
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

View File

@ -12,36 +12,36 @@ import {LNode} from './node';
/** 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
* 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`.
*/
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.
*/
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.
*/
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.
*/
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.
*/
removeView(removeIndex: number): void;

View File

@ -9,7 +9,7 @@
import {LContainer} from './container';
import {ComponentTemplate, DirectiveDef} from './definition';
import {LElementNode, LViewNode, TNode} from './node';
import {LQuery} from './query';
import {LQueries} from './query';
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
*/
query: LQuery|null;
queries: LQueries|null;
}
/** Interface necessary to work with view tree traversal */

View File

@ -313,7 +313,7 @@ export function removeView(container: LContainerNode, removeIndex: number): LVie
destroyViewTree(viewNode.data);
addRemoveViewFromContainer(container, viewNode, false);
// 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;
}

View File

@ -17,11 +17,11 @@ import {getSymbolIterator} from '../util';
import {assertEqual, assertNotNull} from './assert';
import {ReadFromInjectorFn, getOrCreateNodeInjectorForNode} from './di';
import {assertPreviousIsParent, getCurrentQuery} from './instructions';
import {assertPreviousIsParent, getCurrentQueries} from './instructions';
import {DirectiveDef, unusedValueExportToPlacateAjd as unused1} from './interfaces/definition';
import {LInjector, unusedValueExportToPlacateAjd as unused2} from './interfaces/injector';
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';
const unusedValueToPlacateAjd = unused1 + unused2 + unused3 + unused4;
@ -64,7 +64,7 @@ export interface QueryPredicate<T> {
values: any[];
}
export class LQuery_ implements LQuery {
export class LQueries_ implements LQueries {
shallow: 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 we don't have any deep queries then no need to track anything more.
return null;
@ -94,11 +94,11 @@ export class LQuery_ implements LQuery {
return this;
} else {
// 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 predicate = this.deep;
@ -118,10 +118,10 @@ export class LQuery_ implements LQuery {
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 predicate = this.deep;
@ -141,7 +141,7 @@ export class LQuery_ implements LQuery {
predicate = predicate.next;
}
return result ? new LQuery_(result) : null;
return result ? new LQueries_(result) : null;
}
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.
* Shallow predicates are ignored.
*/
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 predicate = this.deep;
@ -181,7 +181,7 @@ export class LQuery_ implements LQuery {
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> {
ngDevMode && assertPreviousIsParent();
const queryList = new QueryList<T>();
const query = getCurrentQuery(LQuery_);
query.track(queryList, predicate, descend, read);
const queries = getCurrentQueries(LQueries_);
queries.track(queryList, predicate, descend, read);
return queryList;
}
@ -396,11 +396,11 @@ export function query<T>(
* views.
* Returns true if a query got dirty during change detection, false otherwise.
*/
export function queryRefresh(query: QueryList<any>): boolean {
const queryImpl = (query as any as QueryList_<any>);
if (query.dirty) {
query.reset(queryImpl._valuesTree);
query.notifyOnChanges();
export function queryRefresh(queryList: QueryList<any>): boolean {
const queryListImpl = (queryList as any as QueryList_<any>);
if (queryList.dirty) {
queryList.reset(queryListImpl._valuesTree);
queryList.notifyOnChanges();
return true;
}
return false;