Skip to content

Commit e84b51d

Browse files
refactor(ivy): remove LView argument from locateDirectiveOrProvider (angular#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 angular#31006
1 parent 8f5c396 commit e84b51d

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

packages/core/src/render3/di.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -481,8 +481,8 @@ function searchTokensOnInjector<T>(
481481
// on the host element node.
482482
const isHostSpecialCase = (flags & InjectFlags.Host) && hostTElementNode === tNode;
483483

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

packages/core/src/render3/query.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,10 @@ function queryByReadToken(read: any, tNode: TNode, currentView: LView): any {
230230
if (typeof factoryFn === 'function') {
231231
return factoryFn();
232232
} else {
233-
const matchingIdx =
234-
locateDirectiveOrProvider(tNode, currentView, read as Type<any>, false, false);
233+
const tView = currentView[TVIEW];
234+
const matchingIdx = locateDirectiveOrProvider(tNode, tView, read as Type<any>, false, false);
235235
if (matchingIdx !== null) {
236-
return getNodeInjectable(
237-
currentView[TVIEW].data, currentView, matchingIdx, tNode as TElementNode);
236+
return getNodeInjectable(tView.data, currentView, matchingIdx, tNode as TElementNode);
238237
}
239238
}
240239
return null;
@@ -285,19 +284,20 @@ function queryRead(tNode: TNode, currentView: LView, read: any, matchingIdx: num
285284
function add(
286285
query: LQuery<any>| null, tNode: TElementNode | TContainerNode | TElementContainerNode,
287286
insertBeforeContainer: boolean) {
288-
const currentView = getLView();
287+
const lView = getLView();
288+
const tView = lView[TVIEW];
289289

290290
while (query) {
291291
const predicate = query.predicate;
292292
const type = predicate.type as any;
293293
if (type) {
294294
let result = null;
295295
if (type === ViewEngine_TemplateRef) {
296-
result = queryByTemplateRef(type, tNode, currentView, predicate.read);
296+
result = queryByTemplateRef(type, tNode, lView, predicate.read);
297297
} else {
298-
const matchingIdx = locateDirectiveOrProvider(tNode, currentView, type, false, false);
298+
const matchingIdx = locateDirectiveOrProvider(tNode, tView, type, false, false);
299299
if (matchingIdx !== null) {
300-
result = queryRead(tNode, currentView, predicate.read, matchingIdx);
300+
result = queryRead(tNode, lView, predicate.read, matchingIdx);
301301
}
302302
}
303303
if (result !== null) {
@@ -308,7 +308,7 @@ function add(
308308
for (let i = 0; i < selector.length; i++) {
309309
const matchingIdx = getIdxOfMatchingSelector(tNode, selector[i]);
310310
if (matchingIdx !== null) {
311-
const result = queryRead(tNode, currentView, predicate.read, matchingIdx);
311+
const result = queryRead(tNode, lView, predicate.read, matchingIdx);
312312
if (result !== null) {
313313
addMatch(query, result, insertBeforeContainer);
314314
}

0 commit comments

Comments
 (0)