Skip to content

Commit 639fab2

Browse files
pkozlowski-opensourcekara
authored andcommitted
refactor(core): remove _tViewNode field from ViewRef (angular#36814)
The _tViewNode field (that was marked as internal) on the ViewRef is not necessery as a reference to a relevant TView is available as a local variable. PR Close angular#36814
1 parent 0912be4 commit 639fab2

File tree

7 files changed

+11
-16
lines changed

7 files changed

+11
-16
lines changed

goldens/size-tracking/integration-payloads.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"uncompressed": {
55
"runtime-es2015": 1485,
66
"main-es2015": 142794,
7-
"polyfills-es2015": 36657
7+
s "polyfills-es2015": 36657
88
}
99
}
1010
},

packages/core/src/render3/component_ref.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ import {getComponentDef} from './definition';
2626
import {NodeInjector} from './di';
2727
import {assignTViewNodeToLView, createLView, createTView, elementCreate, locateHostElement, renderView} from './instructions/shared';
2828
import {ComponentDef} from './interfaces/definition';
29-
import {TContainerNode, TElementContainerNode, TElementNode, TNode} from './interfaces/node';
29+
import {TContainerNode, TElementContainerNode, TElementNode, TNode, TNodeType} from './interfaces/node';
3030
import {domRendererFactory3, RendererFactory3, RNode} from './interfaces/renderer';
3131
import {LView, LViewFlags, TVIEW, TViewType} from './interfaces/view';
3232
import {MATH_ML_NAMESPACE, SVG_NAMESPACE} from './namespaces';
33+
import {assertNodeOfPossibleTypes} from './node_assert';
3334
import {writeDirectClass} from './node_manipulation';
3435
import {extractAttrsAndClassesFromSelector, stringifyCSSSelectorList} from './node_selector_matcher';
3536
import {enterView, leaveView} from './state';
@@ -234,7 +235,8 @@ export class ComponentFactory<T> extends viewEngine_ComponentFactory<T> {
234235
if (!rootSelectorOrNode || isIsolated) {
235236
// The host element of the internal or isolated root view is attached to the component's host
236237
// view node.
237-
componentRef.hostView._tViewNode!.child = tElementNode;
238+
ngDevMode && assertNodeOfPossibleTypes(rootTView.node, TNodeType.View);
239+
rootTView.node!.child = tElementNode;
238240
}
239241
return componentRef;
240242
}
@@ -275,7 +277,7 @@ export class ComponentRef<T> extends viewEngine_ComponentRef<T> {
275277
super();
276278
this.instance = instance;
277279
this.hostView = this.changeDetectorRef = new RootViewRef<T>(_rootLView);
278-
this.hostView._tViewNode = assignTViewNodeToLView(_rootLView[TVIEW], null, -1, _rootLView);
280+
assignTViewNodeToLView(_rootLView[TVIEW], null, -1, _rootLView);
279281
this.componentType = componentType;
280282
}
281283

packages/core/src/render3/instructions/shared.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ function createTNodeAtIndex(
266266
}
267267

268268
export function assignTViewNodeToLView(
269-
tView: TView, tParentNode: TNode|null, index: number, lView: LView): TViewNode {
269+
tView: TView, tParentNode: TNode|null, index: number, lView: LView): void {
270270
// View nodes are not stored in data because they can be added / removed at runtime (which
271271
// would cause indices to change). Their TNodes are instead stored in tView.node.
272272
let tNode = tView.node;
@@ -279,7 +279,7 @@ export function assignTViewNodeToLView(
279279
TNodeType.View, index, null, null) as TViewNode;
280280
}
281281

282-
return lView[T_HOST] = tNode as TViewNode;
282+
lView[T_HOST] = tNode as TViewNode;
283283
}
284284

285285

packages/core/src/render3/node_assert.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function assertNodeType(tNode: TNode, type: TNodeType): asserts tNode is
2626
assertEqual(tNode.type, type, `should be a ${typeName(type)}`);
2727
}
2828

29-
export function assertNodeOfPossibleTypes(tNode: TNode, ...types: TNodeType[]): void {
29+
export function assertNodeOfPossibleTypes(tNode: TNode|null, ...types: TNodeType[]): void {
3030
assertDefined(tNode, 'should be called with a TNode');
3131
const found = types.some(type => tNode.type === type);
3232
assertEqual(

packages/core/src/render3/view_engine_compatibility.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,7 @@ export function createTemplateRef<T>(
119119

120120
renderView(embeddedTView, embeddedLView, context);
121121

122-
const viewRef = new ViewRef<T>(embeddedLView);
123-
viewRef._tViewNode = embeddedLView[T_HOST] as TViewNode;
124-
return viewRef;
122+
return new ViewRef<T>(embeddedLView);
125123
}
126124
};
127125
}

packages/core/src/render3/view_ref.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@ export class ViewRef<T> implements viewEngine_EmbeddedViewRef<T>, viewEngine_Int
3333
private _appRef: ApplicationRef|null = null;
3434
private _viewContainerRef: viewEngine_ViewContainerRef|null = null;
3535

36-
/**
37-
* @internal
38-
*/
39-
public _tViewNode: TViewNode|null = null;
40-
4136
get rootNodes(): any[] {
4237
const lView = this._lView;
4338
if (lView[HOST] == null) {

packages/core/src/util/assert.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export function assertNotDefined<T>(actual: T, msg: string) {
8686
}
8787
}
8888

89-
export function assertDefined<T>(actual: T, msg: string) {
89+
export function assertDefined<T>(actual: T|null|undefined, msg: string): asserts actual is T {
9090
if (actual == null) {
9191
throwError(msg, actual, null, '!=');
9292
}

0 commit comments

Comments
 (0)