refactor(ivy): limit usage of global state (#31490)

PR Close #31490
This commit is contained in:
Pawel Kozlowski 2019-07-10 18:02:19 +02:00 committed by Matias Niemelä
parent 7014b67e51
commit 565a58e261
4 changed files with 13 additions and 17 deletions

View File

@ -75,7 +75,7 @@ export function ɵɵtemplate(
-1, templateFn, consts, vars, tView.directiveRegistry, tView.pipeRegistry, null, null);
}
createDirectivesAndLocals(tView, lView, localRefs, localRefExtractor);
createDirectivesAndLocals(tView, lView, tContainerNode, localRefs, localRefExtractor);
addTContainerToQueries(lView, tContainerNode);
attachPatchData(getNativeByTNode(tContainerNode, lView), lView);
registerPostOrderHooks(tView, tContainerNode);

View File

@ -85,7 +85,7 @@ export function ɵɵelementStart(
}
appendChild(native, tNode, lView);
createDirectivesAndLocals(tView, lView, localRefs);
createDirectivesAndLocals(tView, lView, tNode, localRefs);
// any immediate children of a component or template container must be pre-emptively
// monkey-patched with the component view data so that the element can be inspected

View File

@ -59,7 +59,7 @@ export function ɵɵelementContainerStart(
}
appendChild(native, tNode, lView);
createDirectivesAndLocals(tView, lView, localRefs);
createDirectivesAndLocals(tView, lView, tNode, localRefs);
attachPatchData(native, lView);
const currentQueries = lView[QUERIES];

View File

@ -528,19 +528,18 @@ export function executeContentQueries(tView: TView, tNode: TNode, lView: LView)
* @param localRefExtractor mapping function that extracts local ref value from TNode
*/
export function createDirectivesAndLocals(
tView: TView, lView: LView, localRefs: string[] | null | undefined,
tView: TView, lView: LView, tNode: TElementNode | TContainerNode | TElementContainerNode,
localRefs: string[] | null | undefined,
localRefExtractor: LocalRefExtractor = getNativeByTNode) {
if (!getBindingsEnabled()) return;
const previousOrParentTNode = getPreviousOrParentTNode();
if (tView.firstTemplatePass) {
ngDevMode && ngDevMode.firstTemplatePass++;
resolveDirectives(
tView, lView, findDirectiveMatches(tView, lView, previousOrParentTNode),
previousOrParentTNode, localRefs || null);
tView, lView, findDirectiveMatches(tView, lView, tNode), tNode, localRefs || null);
}
instantiateAllDirectives(tView, lView, previousOrParentTNode);
invokeDirectivesHostBindings(tView, lView, previousOrParentTNode);
saveResolvedLocalsInData(lView, previousOrParentTNode, localRefExtractor);
instantiateAllDirectives(tView, lView, tNode);
invokeDirectivesHostBindings(tView, lView, tNode);
saveResolvedLocalsInData(lView, tNode, localRefExtractor);
setActiveHostElement(null);
}
@ -1194,8 +1193,9 @@ function postProcessBaseDirective<T>(
* Matches the current node against all available selectors.
* If a component is matched (at most one), it is returned in first position in the array.
*/
function findDirectiveMatches(tView: TView, viewData: LView, tNode: TNode): DirectiveDef<any>[]|
null {
function findDirectiveMatches(
tView: TView, viewData: LView,
tNode: TElementNode | TContainerNode | TElementContainerNode): DirectiveDef<any>[]|null {
ngDevMode && assertEqual(tView.firstTemplatePass, true, 'should run on first template pass only');
const registry = tView.directiveRegistry;
let matches: any[]|null = null;
@ -1204,11 +1204,7 @@ function findDirectiveMatches(tView: TView, viewData: LView, tNode: TNode): Dire
const def = registry[i] as ComponentDef<any>| DirectiveDef<any>;
if (isNodeMatchingSelectorList(tNode, def.selectors !, /* isProjectionMode */ false)) {
matches || (matches = ngDevMode ? new MatchesArray !() : []);
diPublicInInjector(
getOrCreateNodeInjectorForNode(
getPreviousOrParentTNode() as TElementNode | TContainerNode | TElementContainerNode,
viewData),
tView, def.type);
diPublicInInjector(getOrCreateNodeInjectorForNode(tNode, viewData), tView, def.type);
if (isComponentDef(def)) {
if (tNode.flags & TNodeFlags.isComponent) throwMultipleComponentError(tNode);