Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(core): remove _tViewNode field from ViewRef #36814

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions goldens/size-tracking/integration-payloads.json
Expand Up @@ -3,7 +3,7 @@
"master": {
"uncompressed": {
"runtime-es2015": 1485,
"main-es2015": 143350,
"main-es2015": 142812,
"polyfills-es2015": 36657
}
}
Expand All @@ -21,7 +21,7 @@
"master": {
"uncompressed": {
"runtime-es2015": 1485,
"main-es2015": 149471,
"main-es2015": 148933,
"polyfills-es2015": 36657
}
}
Expand Down
8 changes: 5 additions & 3 deletions packages/core/src/render3/component_ref.ts
Expand Up @@ -26,10 +26,11 @@ import {getComponentDef} from './definition';
import {NodeInjector} from './di';
import {assignTViewNodeToLView, createLView, createTView, elementCreate, locateHostElement, renderView} from './instructions/shared';
import {ComponentDef} from './interfaces/definition';
import {TContainerNode, TElementContainerNode, TElementNode, TNode} from './interfaces/node';
import {TContainerNode, TElementContainerNode, TElementNode, TNode, TNodeType} from './interfaces/node';
import {domRendererFactory3, RendererFactory3, RNode} from './interfaces/renderer';
import {LView, LViewFlags, TVIEW, TViewType} from './interfaces/view';
import {MATH_ML_NAMESPACE, SVG_NAMESPACE} from './namespaces';
import {assertNodeOfPossibleTypes} from './node_assert';
import {writeDirectClass} from './node_manipulation';
import {extractAttrsAndClassesFromSelector, stringifyCSSSelectorList} from './node_selector_matcher';
import {enterView, leaveView} from './state';
Expand Down Expand Up @@ -234,7 +235,8 @@ export class ComponentFactory<T> extends viewEngine_ComponentFactory<T> {
if (!rootSelectorOrNode || isIsolated) {
// The host element of the internal or isolated root view is attached to the component's host
// view node.
componentRef.hostView._tViewNode!.child = tElementNode;
ngDevMode && assertNodeOfPossibleTypes(rootTView.node, TNodeType.View);
rootTView.node!.child = tElementNode;
}
return componentRef;
}
Expand Down Expand Up @@ -275,7 +277,7 @@ export class ComponentRef<T> extends viewEngine_ComponentRef<T> {
super();
this.instance = instance;
this.hostView = this.changeDetectorRef = new RootViewRef<T>(_rootLView);
this.hostView._tViewNode = assignTViewNodeToLView(_rootLView[TVIEW], null, -1, _rootLView);
assignTViewNodeToLView(_rootLView[TVIEW], null, -1, _rootLView);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove the return value from assignTViewNodeToLView now? I can't find anywhere that uses it anymore.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, good catch!

this.componentType = componentType;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/render3/instructions/shared.ts
Expand Up @@ -266,7 +266,7 @@ function createTNodeAtIndex(
}

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

return lView[T_HOST] = tNode as TViewNode;
lView[T_HOST] = tNode as TViewNode;
}


Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/render3/node_assert.ts
Expand Up @@ -26,7 +26,7 @@ export function assertNodeType(tNode: TNode, type: TNodeType): asserts tNode is
assertEqual(tNode.type, type, `should be a ${typeName(type)}`);
}

export function assertNodeOfPossibleTypes(tNode: TNode, ...types: TNodeType[]): void {
export function assertNodeOfPossibleTypes(tNode: TNode|null, ...types: TNodeType[]): void {
assertDefined(tNode, 'should be called with a TNode');
const found = types.some(type => tNode.type === type);
assertEqual(
Expand Down
4 changes: 1 addition & 3 deletions packages/core/src/render3/view_engine_compatibility.ts
Expand Up @@ -119,9 +119,7 @@ export function createTemplateRef<T>(

renderView(embeddedTView, embeddedLView, context);

const viewRef = new ViewRef<T>(embeddedLView);
viewRef._tViewNode = embeddedLView[T_HOST] as TViewNode;
return viewRef;
return new ViewRef<T>(embeddedLView);
}
};
}
Expand Down
5 changes: 0 additions & 5 deletions packages/core/src/render3/view_ref.ts
Expand Up @@ -33,11 +33,6 @@ export class ViewRef<T> implements viewEngine_EmbeddedViewRef<T>, viewEngine_Int
private _appRef: ApplicationRef|null = null;
private _viewContainerRef: viewEngine_ViewContainerRef|null = null;

/**
* @internal
*/
public _tViewNode: TViewNode|null = null;

get rootNodes(): any[] {
const lView = this._lView;
if (lView[HOST] == null) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/util/assert.ts
Expand Up @@ -86,7 +86,7 @@ export function assertNotDefined<T>(actual: T, msg: string) {
}
}

export function assertDefined<T>(actual: T, msg: string) {
export function assertDefined<T>(actual: T|null|undefined, msg: string): asserts actual is T {
if (actual == null) {
throwError(msg, actual, null, '!=');
}
Expand Down