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); -1, templateFn, consts, vars, tView.directiveRegistry, tView.pipeRegistry, null, null);
} }
createDirectivesAndLocals(tView, lView, localRefs, localRefExtractor); createDirectivesAndLocals(tView, lView, tContainerNode, localRefs, localRefExtractor);
addTContainerToQueries(lView, tContainerNode); addTContainerToQueries(lView, tContainerNode);
attachPatchData(getNativeByTNode(tContainerNode, lView), lView); attachPatchData(getNativeByTNode(tContainerNode, lView), lView);
registerPostOrderHooks(tView, tContainerNode); registerPostOrderHooks(tView, tContainerNode);

View File

@ -85,7 +85,7 @@ export function ɵɵelementStart(
} }
appendChild(native, tNode, lView); 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 // 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 // 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); appendChild(native, tNode, lView);
createDirectivesAndLocals(tView, lView, localRefs); createDirectivesAndLocals(tView, lView, tNode, localRefs);
attachPatchData(native, lView); attachPatchData(native, lView);
const currentQueries = lView[QUERIES]; 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 * @param localRefExtractor mapping function that extracts local ref value from TNode
*/ */
export function createDirectivesAndLocals( 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) { localRefExtractor: LocalRefExtractor = getNativeByTNode) {
if (!getBindingsEnabled()) return; if (!getBindingsEnabled()) return;
const previousOrParentTNode = getPreviousOrParentTNode();
if (tView.firstTemplatePass) { if (tView.firstTemplatePass) {
ngDevMode && ngDevMode.firstTemplatePass++; ngDevMode && ngDevMode.firstTemplatePass++;
resolveDirectives( resolveDirectives(
tView, lView, findDirectiveMatches(tView, lView, previousOrParentTNode), tView, lView, findDirectiveMatches(tView, lView, tNode), tNode, localRefs || null);
previousOrParentTNode, localRefs || null);
} }
instantiateAllDirectives(tView, lView, previousOrParentTNode); instantiateAllDirectives(tView, lView, tNode);
invokeDirectivesHostBindings(tView, lView, previousOrParentTNode); invokeDirectivesHostBindings(tView, lView, tNode);
saveResolvedLocalsInData(lView, previousOrParentTNode, localRefExtractor); saveResolvedLocalsInData(lView, tNode, localRefExtractor);
setActiveHostElement(null); setActiveHostElement(null);
} }
@ -1194,8 +1193,9 @@ function postProcessBaseDirective<T>(
* Matches the current node against all available selectors. * 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. * 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>[]| function findDirectiveMatches(
null { tView: TView, viewData: LView,
tNode: TElementNode | TContainerNode | TElementContainerNode): DirectiveDef<any>[]|null {
ngDevMode && assertEqual(tView.firstTemplatePass, true, 'should run on first template pass only'); ngDevMode && assertEqual(tView.firstTemplatePass, true, 'should run on first template pass only');
const registry = tView.directiveRegistry; const registry = tView.directiveRegistry;
let matches: any[]|null = null; 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>; const def = registry[i] as ComponentDef<any>| DirectiveDef<any>;
if (isNodeMatchingSelectorList(tNode, def.selectors !, /* isProjectionMode */ false)) { if (isNodeMatchingSelectorList(tNode, def.selectors !, /* isProjectionMode */ false)) {
matches || (matches = ngDevMode ? new MatchesArray !() : []); matches || (matches = ngDevMode ? new MatchesArray !() : []);
diPublicInInjector( diPublicInInjector(getOrCreateNodeInjectorForNode(tNode, viewData), tView, def.type);
getOrCreateNodeInjectorForNode(
getPreviousOrParentTNode() as TElementNode | TContainerNode | TElementContainerNode,
viewData),
tView, def.type);
if (isComponentDef(def)) { if (isComponentDef(def)) {
if (tNode.flags & TNodeFlags.isComponent) throwMultipleComponentError(tNode); if (tNode.flags & TNodeFlags.isComponent) throwMultipleComponentError(tNode);