refactor(ivy): remove LView argument from locateDirectiveOrProvider (#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
This commit is contained in:
Pawel Kozlowski 2019-06-12 18:10:25 +02:00 committed by Andrew Kushnir
parent 8f5c396a7c
commit e84b51d2b6
2 changed files with 13 additions and 14 deletions

View File

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

View File

@ -230,11 +230,10 @@ function queryByReadToken(read: any, tNode: TNode, currentView: LView): any {
if (typeof factoryFn === 'function') { if (typeof factoryFn === 'function') {
return factoryFn(); return factoryFn();
} else { } else {
const matchingIdx = const tView = currentView[TVIEW];
locateDirectiveOrProvider(tNode, currentView, read as Type<any>, false, false); const matchingIdx = locateDirectiveOrProvider(tNode, tView, read as Type<any>, false, false);
if (matchingIdx !== null) { if (matchingIdx !== null) {
return getNodeInjectable( return getNodeInjectable(tView.data, currentView, matchingIdx, tNode as TElementNode);
currentView[TVIEW].data, currentView, matchingIdx, tNode as TElementNode);
} }
} }
return null; return null;
@ -285,7 +284,8 @@ function queryRead(tNode: TNode, currentView: LView, read: any, matchingIdx: num
function add( function add(
query: LQuery<any>| null, tNode: TElementNode | TContainerNode | TElementContainerNode, query: LQuery<any>| null, tNode: TElementNode | TContainerNode | TElementContainerNode,
insertBeforeContainer: boolean) { insertBeforeContainer: boolean) {
const currentView = getLView(); const lView = getLView();
const tView = lView[TVIEW];
while (query) { while (query) {
const predicate = query.predicate; const predicate = query.predicate;
@ -293,11 +293,11 @@ function add(
if (type) { if (type) {
let result = null; let result = null;
if (type === ViewEngine_TemplateRef) { if (type === ViewEngine_TemplateRef) {
result = queryByTemplateRef(type, tNode, currentView, predicate.read); result = queryByTemplateRef(type, tNode, lView, predicate.read);
} else { } else {
const matchingIdx = locateDirectiveOrProvider(tNode, currentView, type, false, false); const matchingIdx = locateDirectiveOrProvider(tNode, tView, type, false, false);
if (matchingIdx !== null) { if (matchingIdx !== null) {
result = queryRead(tNode, currentView, predicate.read, matchingIdx); result = queryRead(tNode, lView, predicate.read, matchingIdx);
} }
} }
if (result !== null) { if (result !== null) {
@ -308,7 +308,7 @@ function add(
for (let i = 0; i < selector.length; i++) { for (let i = 0; i < selector.length; i++) {
const matchingIdx = getIdxOfMatchingSelector(tNode, selector[i]); const matchingIdx = getIdxOfMatchingSelector(tNode, selector[i]);
if (matchingIdx !== null) { if (matchingIdx !== null) {
const result = queryRead(tNode, currentView, predicate.read, matchingIdx); const result = queryRead(tNode, lView, predicate.read, matchingIdx);
if (result !== null) { if (result !== null) {
addMatch(query, result, insertBeforeContainer); addMatch(query, result, insertBeforeContainer);
} }