refactor(ivy): store creationMode in LView.flags (#22417)

PR Close #22417
This commit is contained in:
Kara Erickson 2018-02-20 13:31:31 -08:00 committed by Alex Eagle
parent 930ecacd86
commit e454c5a98e
2 changed files with 14 additions and 7 deletions

View File

@ -12,7 +12,7 @@ import {assertEqual, assertLessThan, assertNotEqual, assertNotNull, assertNull,
import {LContainer, TContainer} from './interfaces/container'; import {LContainer, TContainer} from './interfaces/container';
import {CssSelector, LProjection} from './interfaces/projection'; import {CssSelector, LProjection} from './interfaces/projection';
import {LQueries} from './interfaces/query'; import {LQueries} from './interfaces/query';
import {LView, LifecycleStage, TData, TView} from './interfaces/view'; import {LView, LViewFlags, LifecycleStage, TData, TView} from './interfaces/view';
import {LContainerNode, LElementNode, LNode, LNodeFlags, LProjectionNode, LTextNode, LViewNode, TNode, TContainerNode, InitialInputData, InitialInputs, PropertyAliases, PropertyAliasValue,} from './interfaces/node'; import {LContainerNode, LElementNode, LNode, LNodeFlags, LProjectionNode, LTextNode, LViewNode, TNode, TContainerNode, InitialInputData, InitialInputs, PropertyAliases, PropertyAliasValue,} from './interfaces/node';
import {assertNodeType} from './node_assert'; import {assertNodeType} from './node_assert';
@ -159,7 +159,7 @@ export function enterView(newView: LView, host: LElementNode | LViewNode | null)
data = newView && newView.data; data = newView && newView.data;
bindingIndex = newView && newView.bindingStartIndex || 0; bindingIndex = newView && newView.bindingStartIndex || 0;
tData = newView && newView.tView.data; tData = newView && newView.tView.data;
creationMode = newView && newView.creationMode; creationMode = newView && (newView.flags & LViewFlags.CreationMode) === 1;
cleanup = newView && newView.cleanup; cleanup = newView && newView.cleanup;
renderer = newView && newView.renderer; renderer = newView && newView.renderer;
@ -183,7 +183,7 @@ export function leaveView(newView: LView): void {
executeHooks( executeHooks(
currentView.data, currentView.tView.viewHooks, currentView.tView.viewCheckHooks, currentView.data, currentView.tView.viewHooks, currentView.tView.viewCheckHooks,
creationMode); creationMode);
currentView.creationMode = false; currentView.flags &= ~LViewFlags.CreationMode; // Clear creationMode bit in view flags
currentView.lifecycleStage = LifecycleStage.INIT; currentView.lifecycleStage = LifecycleStage.INIT;
currentView.tView.firstTemplatePass = false; currentView.tView.firstTemplatePass = false;
enterView(newView, null); enterView(newView, null);
@ -194,7 +194,8 @@ export function createLView(
context: any | null): LView { context: any | null): LView {
const newView = { const newView = {
parent: currentView, parent: currentView,
id: viewId, // -1 for component views id: viewId, // -1 for component views
flags: LViewFlags.CreationMode,
node: null !, // until we initialize it in createNode. node: null !, // until we initialize it in createNode.
data: [], data: [],
tView: tView, tView: tView,
@ -204,7 +205,6 @@ export function createLView(
tail: null, tail: null,
next: null, next: null,
bindingStartIndex: null, bindingStartIndex: null,
creationMode: true,
template: template, template: template,
context: context, context: context,
dynamicViewCount: 0, dynamicViewCount: 0,

View File

@ -25,14 +25,16 @@ import {Renderer3} from './renderer';
*/ */
export interface LView { export interface LView {
/** /**
* Whether or not the view is in creationMode. * Flags for this view.
*
* First bit: Whether or not the view is in creationMode.
* *
* This must be stored in the view rather than using `data` as a marker so that * This must be stored in the view rather than using `data` as a marker so that
* we can properly support embedded views. Otherwise, when exiting a child view * we can properly support embedded views. Otherwise, when exiting a child view
* back into the parent view, `data` will be defined and `creationMode` will be * back into the parent view, `data` will be defined and `creationMode` will be
* improperly reported as false. * improperly reported as false.
*/ */
creationMode: boolean; flags: LViewFlags;
/** /**
* The parent view is needed when we exit the view and must restore the previous * The parent view is needed when we exit the view and must restore the previous
@ -180,6 +182,11 @@ export interface LView {
queries: LQueries|null; queries: LQueries|null;
} }
/** Flags associated with an LView (see LView.flags) */
export enum LViewFlags {
CreationMode = 0b001
}
/** Interface necessary to work with view tree traversal */ /** Interface necessary to work with view tree traversal */
export interface LViewOrLContainer { export interface LViewOrLContainer {
next: LView|LContainer|null; next: LView|LContainer|null;