refactor(ivy): minor code cleanup (#31798)

PR Close #31798
This commit is contained in:
Pawel Kozlowski 2019-07-23 16:32:48 +02:00 committed by Misko Hevery
parent 5ae9b76a9b
commit b6aeaceb8e
2 changed files with 14 additions and 19 deletions

View File

@ -103,7 +103,7 @@ export function refreshDescendantViews(lView: LView) {
executeViewQueryFn(RenderFlags.Update, tView, lView[CONTEXT]); 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. */ /** Refreshes child components in the current view. */
function refreshChildComponents(components: number[] | null): void { function refreshChildComponents(hostLView: LView, components: number[] | null): void {
if (components != null) { if (components != null) {
for (let i = 0; i < components.length; i++) { for (let i = 0; i < components.length; i++) {
componentRefresh(components[i]); componentRefresh(hostLView, components[i]);
} }
} }
} }
@ -418,7 +418,7 @@ export function renderEmbeddedTemplate<T>(viewToRender: LView, tView: TView, con
// ngFor loop, all the views will be created together before update mode runs and turns // 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 // off firstTemplatePass. If we don't set it here, instances will perform directive
// matching, etc again and again. // matching, etc again and again.
viewToRender[TVIEW].firstTemplatePass = false; tView.firstTemplatePass = false;
refreshDescendantViews(viewToRender); refreshDescendantViews(viewToRender);
safeToRunHooks = true; safeToRunHooks = true;
@ -1519,18 +1519,18 @@ function refreshDynamicEmbeddedViews(lView: LView) {
* *
* @param adjustedElementIndex Element index in LView[] (adjusted for HEADER_OFFSET) * @param adjustedElementIndex Element index in LView[] (adjusted for HEADER_OFFSET)
*/ */
export function componentRefresh(adjustedElementIndex: number): void { export function componentRefresh(hostLView: LView, adjustedElementIndex: number): void {
const lView = getLView(); ngDevMode && assertDataInRange(hostLView, adjustedElementIndex);
ngDevMode && assertDataInRange(lView, adjustedElementIndex); const componentView = getComponentViewByIndex(adjustedElementIndex, hostLView);
const hostView = getComponentViewByIndex(adjustedElementIndex, lView); ngDevMode &&
ngDevMode && assertNodeType(lView[TVIEW].data[adjustedElementIndex] as TNode, TNodeType.Element); assertNodeType(hostLView[TVIEW].data[adjustedElementIndex] as TNode, TNodeType.Element);
// Only components in creation mode, attached CheckAlways // Only components in creation mode, attached CheckAlways
// components or attached, dirty OnPush components should be checked // components or attached, dirty OnPush components should be checked
if ((viewAttachedToChangeDetector(hostView) || isCreationMode(lView)) && if ((viewAttachedToChangeDetector(componentView) || isCreationMode(hostLView)) &&
hostView[FLAGS] & (LViewFlags.CheckAlways | LViewFlags.Dirty)) { componentView[FLAGS] & (LViewFlags.CheckAlways | LViewFlags.Dirty)) {
syncViewWithBlueprint(hostView); syncViewWithBlueprint(componentView);
checkView(hostView, hostView[CONTEXT]); checkView(componentView, componentView[CONTEXT]);
} }
} }

View File

@ -210,12 +210,7 @@ export function createContainerRef(
return this._lContainer[VIEW_REFS] !== null && this._lContainer[VIEW_REFS] ![index] || null; return this._lContainer[VIEW_REFS] !== null && this._lContainer[VIEW_REFS] ![index] || null;
} }
get length(): number { get length(): number { return this._lContainer.length - CONTAINER_HEADER_OFFSET; }
// 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;
}
createEmbeddedView<C>(templateRef: ViewEngine_TemplateRef<C>, context?: C, index?: number): createEmbeddedView<C>(templateRef: ViewEngine_TemplateRef<C>, context?: C, index?: number):
viewEngine_EmbeddedViewRef<C> { viewEngine_EmbeddedViewRef<C> {