refactor(ivy): move parent from LNode to TNode (#24189)

PR Close #24189
This commit is contained in:
Kara Erickson
2018-05-29 15:08:30 -07:00
committed by Matias Niemelä
parent 31795b620f
commit e53179ef8c
8 changed files with 117 additions and 59 deletions

View File

@ -65,12 +65,6 @@ export interface LNode {
*/
readonly native: RElement|RText|null|undefined;
/**
* We need a reference to a node's parent so we can append the node to its parent's native
* element at the appropriate time.
*/
readonly parent: LNode|null;
/**
* If regular LElementNode, then `data` will be null.
* If LElementNode with component, then `data` contains LView.
@ -127,18 +121,12 @@ export interface LElementNode extends LNode {
/** If Component then data has LView (light DOM) */
readonly data: LView|null;
/** LElementNodes can be inside other LElementNodes or inside LViewNodes. */
readonly parent: LElementNode|LViewNode;
}
/** LNode representing a #text node. */
export interface LTextNode extends LNode {
/** The text node associated with this node. */
native: RText;
/** LTextNodes can be inside LElementNodes or inside LViewNodes. */
readonly parent: LElementNode|LViewNode;
readonly data: null;
dynamicLContainerNode: null;
}
@ -146,9 +134,6 @@ export interface LTextNode extends LNode {
/** Abstract node which contains root nodes of a view. */
export interface LViewNode extends LNode {
readonly native: null;
/** LViewNodes can only be added to LContainerNodes. */
readonly parent: LContainerNode|null;
readonly data: LView;
dynamicLContainerNode: null;
}
@ -164,19 +149,12 @@ export interface LContainerNode extends LNode {
*/
native: RElement|RText|null|undefined;
readonly data: LContainer;
/** Containers can be added to elements or views. */
readonly parent: LElementNode|LViewNode|null;
}
export interface LProjectionNode extends LNode {
readonly native: null;
readonly data: LProjection;
/** Projections can be added to elements or views. */
readonly parent: LElementNode|LViewNode;
dynamicLContainerNode: null;
}
@ -201,7 +179,7 @@ export interface TNode {
* This is necessary to get from any TNode to its corresponding LNode when
* traversing the node tree.
*
* If null, this is a view node created from a dynamically created view.
* If null, this is a dynamically created container node or embedded view node.
*/
index: number|null;
@ -307,6 +285,22 @@ export interface TNode {
*/
child: TNode|null;
/**
* Parent node (in the same view only).
*
* We need a reference to a node's parent so we can append the node to its parent's native
* element at the appropriate time.
*
* If the parent would be in a different view (e.g. component host), this property will be null.
* It's important that we don't try to cross component boundaries when retrieving the parent
* because the parent will change (e.g. index, attrs) depending on where the component was
* used (and thus shouldn't be stored on TNode). In these cases, we retrieve the parent through
* LView.node instead (which will be instance-specific).
*
* If this is an inline view node (V), the parent will be its container.
*/
parent: TElementNode|TContainerNode|null;
/**
* A pointer to a TContainerNode created by directives requesting ViewContainerRef
*/
@ -315,31 +309,72 @@ export interface TNode {
/** Static data for an LElementNode */
export interface TElementNode extends TNode {
child: TContainerNode|TElementNode|TProjectionNode|null;
/** Index in the data[] array */
index: number;
child: TElementNode|TTextNode|TContainerNode|TProjectionNode|null;
/**
* Element nodes will have parents unless they are the first node of a component or
* embedded view (which means their parent is in a different view and must be
* retrieved using LView.node).
*/
parent: TElementNode|null;
tViews: null;
}
/** Static data for an LTextNode */
export interface TTextNode extends TNode {
/** Index in the data[] array */
index: number;
child: null;
/**
* Text nodes will have parents unless they are the first node of a component or
* embedded view (which means their parent is in a different view and must be
* retrieved using LView.node).
*/
parent: TElementNode|null;
tViews: null;
}
/** Static data for an LContainerNode */
export interface TContainerNode extends TNode {
/**
* If number, index in the data[] array.
*
* If null, this is a dynamically created container node that isn't stored in
* data[] (e.g. when you inject ViewContainerRef) .
*/
index: number|null;
child: null;
/**
* Container nodes will have parents unless:
*
* - They are the first node of a component or embedded view
* - They are dynamically created
*/
parent: TElementNode|null;
tViews: TView|TView[]|null;
}
/** Static data for an LViewNode */
export interface TViewNode extends TNode {
child: TContainerNode|TElementNode|TProjectionNode|null;
/** If null, it's a dynamically created view*/
index: number|null;
child: TElementNode|TTextNode|TContainerNode|TProjectionNode|null;
parent: TContainerNode|null;
tViews: null;
}
/** Static data for an LProjectionNode */
export interface TProjectionNode extends TNode {
/** Index in the data[] array */
child: null;
/**
* Projection nodes will have parents unless they are the first node of a component
* or embedded view (which means their parent is in a different view and must be
* retrieved using LView.node).
*/
parent: TElementNode|null;
tViews: null;
}