From b6aeaceb8e20927d024be108579fc4544c20fc8f Mon Sep 17 00:00:00 2001 From: Pawel Kozlowski Date: Tue, 23 Jul 2019 16:32:48 +0200 Subject: [PATCH] refactor(ivy): minor code cleanup (#31798) PR Close #31798 --- .../core/src/render3/instructions/shared.ts | 26 +++++++++---------- .../src/render3/view_engine_compatibility.ts | 7 +---- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/packages/core/src/render3/instructions/shared.ts b/packages/core/src/render3/instructions/shared.ts index 239e701e34..b9fec7ed51 100644 --- a/packages/core/src/render3/instructions/shared.ts +++ b/packages/core/src/render3/instructions/shared.ts @@ -103,7 +103,7 @@ export function refreshDescendantViews(lView: LView) { executeViewQueryFn(RenderFlags.Update, tView, lView[CONTEXT]); } - refreshChildComponents(tView.components); + refreshChildComponents(lView, tView.components); } @@ -179,10 +179,10 @@ function refreshContentQueries(tView: TView, lView: LView): void { } /** Refreshes child components in the current view. */ -function refreshChildComponents(components: number[] | null): void { +function refreshChildComponents(hostLView: LView, components: number[] | null): void { if (components != null) { for (let i = 0; i < components.length; i++) { - componentRefresh(components[i]); + componentRefresh(hostLView, components[i]); } } } @@ -418,7 +418,7 @@ export function renderEmbeddedTemplate(viewToRender: LView, tView: TView, con // ngFor loop, all the views will be created together before update mode runs and turns // off firstTemplatePass. If we don't set it here, instances will perform directive // matching, etc again and again. - viewToRender[TVIEW].firstTemplatePass = false; + tView.firstTemplatePass = false; refreshDescendantViews(viewToRender); safeToRunHooks = true; @@ -1519,18 +1519,18 @@ function refreshDynamicEmbeddedViews(lView: LView) { * * @param adjustedElementIndex Element index in LView[] (adjusted for HEADER_OFFSET) */ -export function componentRefresh(adjustedElementIndex: number): void { - const lView = getLView(); - ngDevMode && assertDataInRange(lView, adjustedElementIndex); - const hostView = getComponentViewByIndex(adjustedElementIndex, lView); - ngDevMode && assertNodeType(lView[TVIEW].data[adjustedElementIndex] as TNode, TNodeType.Element); +export function componentRefresh(hostLView: LView, adjustedElementIndex: number): void { + ngDevMode && assertDataInRange(hostLView, adjustedElementIndex); + const componentView = getComponentViewByIndex(adjustedElementIndex, hostLView); + ngDevMode && + assertNodeType(hostLView[TVIEW].data[adjustedElementIndex] as TNode, TNodeType.Element); // Only components in creation mode, attached CheckAlways // components or attached, dirty OnPush components should be checked - if ((viewAttachedToChangeDetector(hostView) || isCreationMode(lView)) && - hostView[FLAGS] & (LViewFlags.CheckAlways | LViewFlags.Dirty)) { - syncViewWithBlueprint(hostView); - checkView(hostView, hostView[CONTEXT]); + if ((viewAttachedToChangeDetector(componentView) || isCreationMode(hostLView)) && + componentView[FLAGS] & (LViewFlags.CheckAlways | LViewFlags.Dirty)) { + syncViewWithBlueprint(componentView); + checkView(componentView, componentView[CONTEXT]); } } diff --git a/packages/core/src/render3/view_engine_compatibility.ts b/packages/core/src/render3/view_engine_compatibility.ts index 7ac384a845..4f6aca6783 100644 --- a/packages/core/src/render3/view_engine_compatibility.ts +++ b/packages/core/src/render3/view_engine_compatibility.ts @@ -210,12 +210,7 @@ export function createContainerRef( return this._lContainer[VIEW_REFS] !== null && this._lContainer[VIEW_REFS] ![index] || null; } - get length(): number { - // Note that if there are no views, the container - // length will be smaller than the header offset. - const viewAmount = this._lContainer.length - CONTAINER_HEADER_OFFSET; - return viewAmount > 0 ? viewAmount : 0; - } + get length(): number { return this._lContainer.length - CONTAINER_HEADER_OFFSET; } createEmbeddedView(templateRef: ViewEngine_TemplateRef, context?: C, index?: number): viewEngine_EmbeddedViewRef {