Skip to content

Commit b2c3839

Browse files
atscottalxhub
authored andcommitted
refactor(core): rename ViewRef<T> to InternalViewRef<T> and remove existing InternalViewRef (angular#52430)
The `ViewRef<T>` interface extends `InternalViewRef` and is already not part of the public API. There is no need for the extra `InternalViewRef` interface. This confusing setup is likely leftover from the types necessary to support both Ivy and ViewEngine. PR Close angular#52430
1 parent 65ccaa4 commit b2c3839

File tree

14 files changed

+34
-38
lines changed

14 files changed

+34
-38
lines changed

packages/core/src/application_ref.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import {COMPILER_OPTIONS, CompilerOptions} from './linker/compiler';
3434
import {ComponentFactory, ComponentRef} from './linker/component_factory';
3535
import {ComponentFactoryResolver} from './linker/component_factory_resolver';
3636
import {InternalNgModuleRef, NgModuleFactory, NgModuleRef} from './linker/ng_module_factory';
37-
import {InternalViewRef, ViewRef} from './linker/view_ref';
37+
import {ViewRef} from './linker/view_ref';
3838
import {isComponentResourceResolutionQueueEmpty, resolveComponentResources} from './metadata/resource_loading';
3939
import {assertNgModuleType} from './render3/assert';
4040
import {ComponentFactory as R3ComponentFactory} from './render3/component_ref';
@@ -44,6 +44,7 @@ import {setLocaleId} from './render3/i18n/i18n_locale_id';
4444
import {setJitOptions} from './render3/jit/jit_options';
4545
import {createNgModuleRefWithProviders, EnvironmentNgModuleRefAdapter, NgModuleFactory as R3NgModuleFactory} from './render3/ng_module_ref';
4646
import {publishDefaultGlobalUtils as _publishDefaultGlobalUtils} from './render3/util/global_utils';
47+
import {InternalViewRef} from './render3/view_ref';
4748
import {TESTABILITY} from './testability/testability';
4849
import {isPromise} from './util/lang';
4950
import {stringify} from './util/stringify';
@@ -825,7 +826,7 @@ export class ApplicationRef {
825826
private _destroyed = false;
826827
private _destroyListeners: Array<() => void> = [];
827828
/** @internal */
828-
_views: InternalViewRef[] = [];
829+
_views: InternalViewRef<unknown>[] = [];
829830
private readonly internalErrorHandler = inject(INTERNAL_APPLICATION_ERROR_HANDLER);
830831
private readonly zoneIsStable = inject(ZONE_IS_STABLE_OBSERVABLE);
831832

@@ -1077,7 +1078,7 @@ export class ApplicationRef {
10771078
*/
10781079
attachView(viewRef: ViewRef): void {
10791080
(typeof ngDevMode === 'undefined' || ngDevMode) && this.warnIfDestroyed();
1080-
const view = (viewRef as InternalViewRef);
1081+
const view = (viewRef as InternalViewRef<unknown>);
10811082
this._views.push(view);
10821083
view.attachToAppRef(this);
10831084
}
@@ -1087,7 +1088,7 @@ export class ApplicationRef {
10871088
*/
10881089
detachView(viewRef: ViewRef): void {
10891090
(typeof ngDevMode === 'undefined' || ngDevMode) && this.warnIfDestroyed();
1090-
const view = (viewRef as InternalViewRef);
1091+
const view = (viewRef as InternalViewRef<unknown>);
10911092
remove(this._views, view);
10921093
view.detachFromAppRef();
10931094
}

packages/core/src/change_detection/change_detector_ref.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {isComponentHost} from '../render3/interfaces/type_checks';
1313
import {DECLARATION_COMPONENT_VIEW, LView} from '../render3/interfaces/view';
1414
import {getCurrentTNode, getLView} from '../render3/state';
1515
import {getComponentLViewByIndex} from '../render3/util/view_utils';
16-
import {ViewRef} from '../render3/view_ref';
16+
import {InternalViewRef} from '../render3/view_ref';
1717

1818
/**
1919
* Base class that provides change detection functionality.
@@ -145,12 +145,12 @@ function createViewRef(tNode: TNode, lView: LView, isPipe: boolean): ChangeDetec
145145
// The LView represents the location where the component is declared.
146146
// Instead we want the LView for the component View and so we need to look it up.
147147
const componentView = getComponentLViewByIndex(tNode.index, lView); // look down
148-
return new ViewRef(componentView, componentView);
148+
return new InternalViewRef(componentView, componentView);
149149
} else if (tNode.type & (TNodeType.AnyRNode | TNodeType.AnyContainer | TNodeType.Icu)) {
150150
// The LView represents the location where the injection is requested from.
151151
// We need to locate the containing LView (in case where the `lView` is an embedded view)
152152
const hostComponentView = lView[DECLARATION_COMPONENT_VIEW]; // look up
153-
return new ViewRef(hostComponentView, lView);
153+
return new InternalViewRef(hostComponentView, lView);
154154
}
155155
return null!;
156156
}

packages/core/src/core_private_export.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export {clearResolutionOfComponentResourcesQueue as ɵclearResolutionOfComponent
3333
export {ReflectionCapabilities as ɵReflectionCapabilities} from './reflection/reflection_capabilities';
3434
export {AnimationRendererType as ɵAnimationRendererType} from './render/api';
3535
export {InjectorProfilerContext as ɵInjectorProfilerContext, setInjectorProfilerContext as ɵsetInjectorProfilerContext} from './render3/debug/injector_profiler';
36+
export {InternalViewRef as ɵInternalViewRef} from './render3/view_ref';
3637
export {allowSanitizationBypassAndThrow as ɵallowSanitizationBypassAndThrow, BypassType as ɵBypassType, getSanitizationBypassType as ɵgetSanitizationBypassType, SafeHtml as ɵSafeHtml, SafeResourceUrl as ɵSafeResourceUrl, SafeScript as ɵSafeScript, SafeStyle as ɵSafeStyle, SafeUrl as ɵSafeUrl, SafeValue as ɵSafeValue, unwrapSafeValue as ɵunwrapSafeValue} from './sanitization/bypass';
3738
export {_sanitizeHtml as ɵ_sanitizeHtml} from './sanitization/html_sanitizer';
3839
export {_sanitizeUrl as ɵ_sanitizeUrl} from './sanitization/url_sanitizer';

packages/core/src/core_render3_private_export.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ export {
289289
publishDefaultGlobalUtils as ɵpublishDefaultGlobalUtils
290290
,
291291
publishGlobalUtil as ɵpublishGlobalUtil} from './render3/util/global_utils';
292-
export {ViewRef as ɵViewRef} from './render3/view_ref';
292+
export {InternalViewRef as ɵViewRef} from './render3/view_ref';
293293
export {
294294
bypassSanitizationTrustHtml as ɵbypassSanitizationTrustHtml,
295295
bypassSanitizationTrustResourceUrl as ɵbypassSanitizationTrustResourceUrl,

packages/core/src/hydration/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ export function retrieveHydrationInfo(
180180
*/
181181
export function getLNodeForHydration(viewRef: ViewRef): LView|LContainer|null {
182182
// Reading an internal field from `ViewRef` instance.
183-
let lView = (viewRef as any)._lView as LView;
183+
// TODO(atscott): This should be `as InternalViewRef<unknown>` but creates a circular dependency
184+
let lView = (viewRef as any)._lView;
184185
const tView = lView[TVIEW];
185186
// A registered ViewRef might represent an instance of an
186187
// embedded view, in which case we do not need to annotate it.

packages/core/src/linker/template_ref.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {TContainerNode, TNode, TNodeType} from '../render3/interfaces/node';
1212
import {LView} from '../render3/interfaces/view';
1313
import {getCurrentTNode, getLView} from '../render3/state';
1414
import {createAndRenderEmbeddedLView} from '../render3/view_manipulation';
15-
import {ViewRef as R3_ViewRef} from '../render3/view_ref';
15+
import {InternalViewRef as R3_ViewRef} from '../render3/view_ref';
1616
import {assertDefined} from '../util/assert';
1717

1818
import {createElementRef, ElementRef} from './element_ref';

packages/core/src/linker/view_container_ref.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {getCurrentTNode, getLView} from '../render3/state';
3131
import {getParentInjectorIndex, getParentInjectorView, hasParentInjector} from '../render3/util/injector_utils';
3232
import {getNativeByTNode, unwrapRNode, viewAttachedToContainer} from '../render3/util/view_utils';
3333
import {addLViewToLContainer, shouldAddViewToDom} from '../render3/view_manipulation';
34-
import {ViewRef as R3ViewRef} from '../render3/view_ref';
34+
import {InternalViewRef} from '../render3/view_ref';
3535
import {addToArray, removeFromArray} from '../util/array_utils';
3636
import {assertDefined, assertEqual, assertGreaterThan, assertLessThan, throwError} from '../util/assert';
3737

@@ -474,7 +474,7 @@ const R3ViewContainerRef = class ViewContainerRef extends VE_ViewContainerRef {
474474
}
475475

476476
private insertImpl(viewRef: ViewRef, index?: number, addToDOM?: boolean): ViewRef {
477-
const lView = (viewRef as R3ViewRef<any>)._lView!;
477+
const lView = (viewRef as InternalViewRef<unknown>)._lView;
478478

479479
if (ngDevMode && viewRef.destroyed) {
480480
throw new Error('Cannot insert a destroyed View in a ViewContainer!');
@@ -514,7 +514,7 @@ const R3ViewContainerRef = class ViewContainerRef extends VE_ViewContainerRef {
514514

515515
addLViewToLContainer(lContainer, lView, adjustedIdx, addToDOM);
516516

517-
(viewRef as R3ViewRef<any>).attachToViewContainerRef();
517+
(viewRef as InternalViewRef<any>).attachToViewContainerRef();
518518
addToArray(getOrCreateViewRefs(lContainer), adjustedIdx, viewRef);
519519

520520
return viewRef;
@@ -554,7 +554,7 @@ const R3ViewContainerRef = class ViewContainerRef extends VE_ViewContainerRef {
554554

555555
const wasDetached =
556556
view && removeFromArray(getOrCreateViewRefs(this._lContainer), adjustedIdx) != null;
557-
return wasDetached ? new R3ViewRef(view!) : null;
557+
return wasDetached ? new InternalViewRef(view!) : null;
558558
}
559559

560560
private _adjustIndex(index?: number, shift: number = 0) {

packages/core/src/linker/view_ref.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
import {ChangeDetectorRef} from '../change_detection/change_detector_ref';
10+
import {LView} from '../render3/interfaces/view';
1011

1112
/**
1213
* Represents an Angular [view](guide/glossary#view "Definition").
@@ -101,11 +102,6 @@ export abstract class EmbeddedViewRef<C> extends ViewRef {
101102
abstract get rootNodes(): any[];
102103
}
103104

104-
export interface InternalViewRef extends ViewRef {
105-
detachFromAppRef(): void;
106-
attachToAppRef(appRef: ViewRefTracker): void;
107-
}
108-
109105
/**
110106
* Interface for tracking root `ViewRef`s in `ApplicationRef`.
111107
*

packages/core/src/render3/component_ref.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import {computeStaticStyling} from './styling/static_styling';
5151
import {mergeHostAttrs, setUpAttributes} from './util/attrs_utils';
5252
import {debugStringifyTypeForError, stringifyForError} from './util/stringify_utils';
5353
import {getComponentLViewByIndex, getNativeByTNode, getTNode} from './util/view_utils';
54-
import {RootViewRef, ViewRef} from './view_ref';
54+
import {InternalViewRef, RootViewRef} from './view_ref';
5555

5656
export class ComponentFactoryResolver extends AbstractComponentFactoryResolver {
5757
/**
@@ -309,7 +309,7 @@ export class ComponentFactory<T> extends AbstractComponentFactory<T> {
309309
*/
310310
export class ComponentRef<T> extends AbstractComponentRef<T> {
311311
override instance: T;
312-
override hostView: ViewRef<T>;
312+
override hostView: InternalViewRef<T>;
313313
override changeDetectorRef: ChangeDetectorRef;
314314
override componentType: Type<T>;
315315
private previousInputValues: Map<string, unknown>|null = null;

packages/core/src/render3/di.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ function shouldSearchParent(flags: InjectFlags, isFirstHostTNode: boolean): bool
739739
}
740740

741741
export function getNodeInjectorLView(nodeInjector: NodeInjector): LView {
742-
return (nodeInjector as any)._lView as LView;
742+
return nodeInjector._lView;
743743
}
744744

745745
export function getNodeInjectorTNode(nodeInjector: NodeInjector): TElementNode|TContainerNode|
@@ -751,7 +751,7 @@ export function getNodeInjectorTNode(nodeInjector: NodeInjector): TElementNode|T
751751
export class NodeInjector implements Injector {
752752
constructor(
753753
private _tNode: TElementNode|TContainerNode|TElementContainerNode|null,
754-
private _lView: LView) {}
754+
public _lView: LView) {}
755755

756756
get(token: any, notFoundValue?: any, flags?: InjectFlags|InjectOptions): any {
757757
return getOrCreateInjectable(
@@ -761,7 +761,7 @@ export class NodeInjector implements Injector {
761761

762762
/** Creates a `NodeInjector` for the current node. */
763763
export function createNodeInjector(): Injector {
764-
return new NodeInjector(getCurrentTNode()! as TDirectiveHostNode, getLView()) as any;
764+
return new NodeInjector(getCurrentTNode()! as TDirectiveHostNode, getLView());
765765
}
766766

767767
/**

0 commit comments

Comments
 (0)