Navigation Menu

Skip to content

Commit

Permalink
refactor(ivy): remove LView argument from locateDirectiveOrProvider (#…
Browse files Browse the repository at this point in the history
…31006)

The DI's `locateDirectiveOrProvider` function operates on `TView` / `TNode`
data structures only so doesn't need to access `LView`. This refactoring
changes the argument list so the mentioned function takes less info to do
its work.

This refactoring is also mandatory for the upcoming query matching move
to TView.

PR Close #31006
  • Loading branch information
pkozlowski-opensource authored and AndrewKushnir committed Jun 14, 2019
1 parent 8f5c396 commit e84b51d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
9 changes: 4 additions & 5 deletions packages/core/src/render3/di.ts
Expand Up @@ -481,8 +481,8 @@ function searchTokensOnInjector<T>(
// on the host element node.
const isHostSpecialCase = (flags & InjectFlags.Host) && hostTElementNode === tNode;

const injectableIdx =
locateDirectiveOrProvider(tNode, lView, token, canAccessViewProviders, isHostSpecialCase);
const injectableIdx = locateDirectiveOrProvider(
tNode, currentTView, token, canAccessViewProviders, isHostSpecialCase);
if (injectableIdx !== null) {
return getNodeInjectable(currentTView.data, lView, injectableIdx, tNode as TElementNode);
} else {
Expand All @@ -494,16 +494,15 @@ function searchTokensOnInjector<T>(
* Searches for the given token among the node's directives and providers.
*
* @param tNode TNode on which directives are present.
* @param lView The view we are currently processing
* @param tView The tView we are currently processing
* @param token Provider token or type of a directive to look for.
* @param canAccessViewProviders Whether view providers should be considered.
* @param isHostSpecialCase Whether the host special case applies.
* @returns Index of a found directive or provider, or null when none found.
*/
export function locateDirectiveOrProvider<T>(
tNode: TNode, lView: LView, token: Type<T>| InjectionToken<T>, canAccessViewProviders: boolean,
tNode: TNode, tView: TView, token: Type<T>| InjectionToken<T>, canAccessViewProviders: boolean,
isHostSpecialCase: boolean | number): number|null {
const tView = lView[TVIEW];
const nodeProviderIndexes = tNode.providerIndexes;
const tInjectables = tView.data;

Expand Down
18 changes: 9 additions & 9 deletions packages/core/src/render3/query.ts
Expand Up @@ -230,11 +230,10 @@ function queryByReadToken(read: any, tNode: TNode, currentView: LView): any {
if (typeof factoryFn === 'function') {
return factoryFn();
} else {
const matchingIdx =
locateDirectiveOrProvider(tNode, currentView, read as Type<any>, false, false);
const tView = currentView[TVIEW];
const matchingIdx = locateDirectiveOrProvider(tNode, tView, read as Type<any>, false, false);
if (matchingIdx !== null) {
return getNodeInjectable(
currentView[TVIEW].data, currentView, matchingIdx, tNode as TElementNode);
return getNodeInjectable(tView.data, currentView, matchingIdx, tNode as TElementNode);
}
}
return null;
Expand Down Expand Up @@ -285,19 +284,20 @@ function queryRead(tNode: TNode, currentView: LView, read: any, matchingIdx: num
function add(
query: LQuery<any>| null, tNode: TElementNode | TContainerNode | TElementContainerNode,
insertBeforeContainer: boolean) {
const currentView = getLView();
const lView = getLView();
const tView = lView[TVIEW];

while (query) {
const predicate = query.predicate;
const type = predicate.type as any;
if (type) {
let result = null;
if (type === ViewEngine_TemplateRef) {
result = queryByTemplateRef(type, tNode, currentView, predicate.read);
result = queryByTemplateRef(type, tNode, lView, predicate.read);
} else {
const matchingIdx = locateDirectiveOrProvider(tNode, currentView, type, false, false);
const matchingIdx = locateDirectiveOrProvider(tNode, tView, type, false, false);
if (matchingIdx !== null) {
result = queryRead(tNode, currentView, predicate.read, matchingIdx);
result = queryRead(tNode, lView, predicate.read, matchingIdx);
}
}
if (result !== null) {
Expand All @@ -308,7 +308,7 @@ function add(
for (let i = 0; i < selector.length; i++) {
const matchingIdx = getIdxOfMatchingSelector(tNode, selector[i]);
if (matchingIdx !== null) {
const result = queryRead(tNode, currentView, predicate.read, matchingIdx);
const result = queryRead(tNode, lView, predicate.read, matchingIdx);
if (result !== null) {
addMatch(query, result, insertBeforeContainer);
}
Expand Down

0 comments on commit e84b51d

Please sign in to comment.