Skip to content

Commit eb93a79

Browse files
committed
refactor(core): store locals in main array in rederer3
1 parent 6e0ab34 commit eb93a79

14 files changed

+556
-243
lines changed

packages/core/src/render3/instructions.ts

Lines changed: 152 additions & 140 deletions
Large diffs are not rendered by default.

packages/core/src/render3/interfaces.ts

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export interface ViewState {
9494
* do this by creating ViewState in incomplete state with nodes == null
9595
* and we initialize it on first run.
9696
*/
97-
readonly nodesAndBindings: any[];
97+
readonly data: any[];
9898

9999
/**
100100
* All directives created inside this view. Stored as an array
@@ -159,8 +159,6 @@ export interface ViewState {
159159
* in the same container. We need a way to link component views as well.
160160
*/
161161
next: ViewState|ContainerState|null;
162-
163-
locals: any[]|null;
164162
}
165163

166164
export interface LNodeInjector {
@@ -291,10 +289,10 @@ export interface LNode {
291289
query: QueryState|null;
292290

293291
/**
294-
* Pointer to the corresponding NodeBindings object, which stores static
292+
* Pointer to the corresponding LNodeStatic object, which stores static
295293
* data about this node.
296294
*/
297-
nodeBindings: NodeBindings|null;
295+
staticData: LNodeStatic|null;
298296
}
299297

300298
/**
@@ -457,7 +455,7 @@ export type InitialInputs = string[];
457455
* - Null: that property's data was already generated and nothing was found.
458456
* - Undefined: that property's data has not yet been generated
459457
*/
460-
export interface NodeBindings {
458+
export interface LNodeStatic {
461459
/** The tag name associated with this node. */
462460
tagName: string|null;
463461

@@ -483,8 +481,31 @@ export interface NodeBindings {
483481

484482
/** Output data for all directives on this node. */
485483
outputs: MinificationData|null|undefined;
484+
485+
/**
486+
* If this LNodeStatic corresponds to an LContainer, the container will
487+
* need to have nested static data for each of its embedded views.
488+
* Otherwise, nodes in embedded views with the same index as nodes
489+
* in their parent views will overwrite each other, as they are in
490+
* the same template.
491+
*
492+
* Each index in this array corresponds to the static data for a certain
493+
* view. So if you had V(0) and V(1) in a container, you might have:
494+
*
495+
* [
496+
* [{tagName: 'div', attrs: ...}, null], // V(0) ngData
497+
* [{tagName: 'button', attrs ...}, null] // V(1) ngData
498+
* ]
499+
*/
500+
containerStatic: (LNodeStatic|null)[][]|null;
486501
}
487502

503+
/** Static data for an LElement */
504+
export interface LElementStatic extends LNodeStatic { containerStatic: null; }
505+
506+
/** Static data for an LContainer */
507+
export interface LContainerStatic extends LNodeStatic { containerStatic: (LNodeStatic|null)[][]; }
508+
488509
/** Interface necessary to work with view tree traversal */
489510
export interface ViewOrContainerState {
490511
next: ViewState|ContainerState|null;

packages/core/src/render3/node_manipulation.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export function findBeforeNode(index: number, state: ContainerState, native: RCo
3737
const children = state.children;
3838
// Find the node to insert in front of
3939
return index + 1 < children.length ?
40-
(children[index + 1].data.nodesAndBindings[0] as LText | LElement | LContainer).native :
40+
(children[index + 1].child as LText | LElement | LContainer).native :
4141
native;
4242
}
4343

@@ -50,7 +50,7 @@ export function addRemoveViewFromContainer(
5050
ngDevMode && assertNodeType(container, LNodeFlags.Container);
5151
ngDevMode && assertNodeType(rootNode, LNodeFlags.View);
5252
const parent = findNativeParent(container);
53-
let node: LNode|null = rootNode.data.nodesAndBindings[0];
53+
let node: LNode|null = rootNode.child;
5454
if (parent) {
5555
while (node) {
5656
const type = node.flags & LNodeFlags.TYPE_MASK;
@@ -78,13 +78,11 @@ export function addRemoveViewFromContainer(
7878
(isFnRenderer ?
7979
(renderer as Renderer3Fn).removeChild !(parent as RElement, node.native !) :
8080
parent.removeChild(node.native !));
81-
nextNode = childContainerData.children.length ?
82-
childContainerData.children[0].data.nodesAndBindings[0] :
83-
null;
81+
nextNode = childContainerData.children.length ? childContainerData.children[0].child : null;
8482
} else if (type === LNodeFlags.Projection) {
8583
nextNode = (node as LProjection).data[0];
8684
} else {
87-
nextNode = (node as LView).data.nodesAndBindings[0];
85+
nextNode = (node as LView).child;
8886
}
8987
if (nextNode === null) {
9088
while (node && !node.next) {
@@ -277,10 +275,12 @@ export function processProjectedNode(
277275
currentParent: LView | LElement, currentView: ViewState) {
278276
if ((node.flags & LNodeFlags.TYPE_MASK) === LNodeFlags.Container &&
279277
(currentParent.flags & LNodeFlags.TYPE_MASK) === LNodeFlags.Element &&
280-
currentParent.data === null) {
281-
// The node we are adding is a Container and we are adding it to Element
282-
// which is not Component (no more re-projection). Assignee the final
283-
// projection location.
278+
(currentParent.data === null || currentParent.data === currentView)) {
279+
// The node we are adding is a Container and we are adding it to Element which
280+
// is not a component (no more re-projection).
281+
// Alternatively a container is projected at the root of a component's template
282+
// and can't be re-projected (as not content of any component).
283+
// Assignee the final projection location in those cases.
284284
const containerState = (node as LContainer).data;
285285
containerState.renderParent = currentParent as LElement;
286286
const views = containerState.children;

packages/core/src/render3/node_selector_matcher.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import './ng_dev_mode';
1010

1111
import {assertNotNull} from './assert';
12-
import {CSSSelector, CSSSelectorWithNegations, NodeBindings, SimpleCSSSelector} from './interfaces';
12+
import {CSSSelector, CSSSelectorWithNegations, LNodeStatic, SimpleCSSSelector} from './interfaces';
1313

1414
function isCssClassMatching(nodeClassAttrVal: string, cssClassToMatch: string): boolean {
1515
const nodeClassesLen = nodeClassAttrVal.length;
@@ -28,12 +28,12 @@ function isCssClassMatching(nodeClassAttrVal: string, cssClassToMatch: string):
2828
/**
2929
* A utility function to match an Ivy node static data against a simple CSS selector
3030
*
31-
* @param {NodeBindings} node static data to match
31+
* @param {LNodeStatic} node static data to match
3232
* @param {SimpleCSSSelector} selector
3333
* @returns {boolean}
3434
*/
3535
export function isNodeMatchingSimpleSelector(
36-
lNodeStaticData: NodeBindings, selector: SimpleCSSSelector): boolean {
36+
lNodeStaticData: LNodeStatic, selector: SimpleCSSSelector): boolean {
3737
const noOfSelectorParts = selector.length;
3838
ngDevMode && assertNotNull(selector[0], 'selector[0]');
3939
const tagNameInSelector = selector[0];
@@ -83,7 +83,7 @@ export function isNodeMatchingSimpleSelector(
8383
}
8484

8585
export function isNodeMatchingSelectorWithNegations(
86-
lNodeStaticData: NodeBindings, selector: CSSSelectorWithNegations): boolean {
86+
lNodeStaticData: LNodeStatic, selector: CSSSelectorWithNegations): boolean {
8787
const positiveSelector = selector[0];
8888
if (positiveSelector != null &&
8989
!isNodeMatchingSimpleSelector(lNodeStaticData, positiveSelector)) {
@@ -105,7 +105,7 @@ export function isNodeMatchingSelectorWithNegations(
105105
}
106106

107107
export function isNodeMatchingSelector(
108-
lNodeStaticData: NodeBindings, selector: CSSSelector): boolean {
108+
lNodeStaticData: LNodeStatic, selector: CSSSelector): boolean {
109109
for (let i = 0; i < selector.length; i++) {
110110
if (isNodeMatchingSelectorWithNegations(lNodeStaticData, selector[i])) {
111111
return true;

packages/core/src/render3/public_interfaces.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {diPublic, refreshComponent} from './instructions';
1414
* Definition of what a template rendering function should look like.
1515
*/
1616
export type ComponentTemplate<T> = {
17-
(ctx: T, creationMode: boolean): void; ngData?: never;
17+
(ctx: T, creationMode: boolean): void; ngStaticData?: never;
1818
};
1919
export type EmbeddedTemplate<T> = (ctx: T) => void;
2020

packages/core/src/render3/query.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
*/
88

99
import {Observable} from 'rxjs/Observable';
10-
1110
import {QueryList as IQueryList, Type} from '../core';
12-
1311
import {assertNotNull} from './assert';
1412
import {LContainer, LNode, LNodeFlags, LView, QueryState} from './interfaces';
1513

0 commit comments

Comments
 (0)