Skip to content

Commit d8280ac

Browse files
atscottalxhub
authored andcommitted
refactor(core): Remove RootViewRef<T> because it is the same as ViewRef<T> (angular#52430)
`RootViewRef<T>` extends `ViewRef<T>` and overrides 3 methods with behavior that is identical to `ViewRef<T>`. This commit removes `RootViewRef<T>` because it is not needed. PR Close angular#52430
1 parent b2c3839 commit d8280ac

File tree

13 files changed

+44
-130
lines changed

13 files changed

+44
-130
lines changed

packages/core/src/render3/component_ref.ts

Lines changed: 6 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 {InternalViewRef, RootViewRef} from './view_ref';
54+
import {InternalViewRef} from './view_ref';
5555

5656
export class ComponentFactoryResolver extends AbstractComponentFactoryResolver {
5757
/**
@@ -319,7 +319,11 @@ export class ComponentRef<T> extends AbstractComponentRef<T> {
319319
private _tNode: TElementNode|TContainerNode|TElementContainerNode) {
320320
super();
321321
this.instance = instance;
322-
this.hostView = this.changeDetectorRef = new RootViewRef<T>(_rootLView);
322+
this.hostView = this.changeDetectorRef = new InternalViewRef<T>(
323+
_rootLView,
324+
undefined, /* _cdRefInjectingView */
325+
false, /* notifyErrorHandler */
326+
);
323327
this.componentType = componentType;
324328
}
325329

packages/core/src/render3/view_ref.ts

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export class InternalViewRef<T> implements EmbeddedViewRef<T>, ChangeDetectorRef
5555
*
5656
* This may be different from `_lView` if the `_cdRefInjectingView` is an embedded view.
5757
*/
58-
private _cdRefInjectingView?: LView) {}
58+
private _cdRefInjectingView?: LView, private readonly notifyErrorHandler = true) {}
5959

6060
get context(): T {
6161
return this._lView[CONTEXT] as unknown as T;
@@ -282,7 +282,8 @@ export class InternalViewRef<T> implements EmbeddedViewRef<T>, ChangeDetectorRef
282282
* See {@link ChangeDetectorRef#detach} for more information.
283283
*/
284284
detectChanges(): void {
285-
detectChangesInternal(this._lView[TVIEW], this._lView, this.context as unknown as {});
285+
detectChangesInternal(
286+
this._lView[TVIEW], this._lView, this.context as unknown as {}, this.notifyErrorHandler);
286287
}
287288

288289
/**
@@ -293,7 +294,8 @@ export class InternalViewRef<T> implements EmbeddedViewRef<T>, ChangeDetectorRef
293294
*/
294295
checkNoChanges(): void {
295296
if (ngDevMode) {
296-
checkNoChangesInternal(this._lView[TVIEW], this._lView, this.context as unknown as {});
297+
checkNoChangesInternal(
298+
this._lView[TVIEW], this._lView, this.context as unknown as {}, this.notifyErrorHandler);
297299
}
298300
}
299301

@@ -320,29 +322,3 @@ export class InternalViewRef<T> implements EmbeddedViewRef<T>, ChangeDetectorRef
320322
this._appRef = appRef;
321323
}
322324
}
323-
324-
export class RootViewRef<T> extends InternalViewRef<T> {
325-
constructor(public _view: LView) {
326-
super(_view);
327-
}
328-
329-
override detectChanges(): void {
330-
const lView = this._view;
331-
const tView = lView[TVIEW];
332-
const context = lView[CONTEXT];
333-
detectChangesInternal(tView, lView, context, false);
334-
}
335-
336-
override checkNoChanges(): void {
337-
if (ngDevMode) {
338-
const lView = this._view;
339-
const tView = lView[TVIEW];
340-
const context = lView[CONTEXT];
341-
checkNoChangesInternal(tView, lView, context, false);
342-
}
343-
}
344-
345-
override get context(): T {
346-
return null!;
347-
}
348-
}

packages/core/test/bundling/animations-standalone/bundle.golden_symbols.json

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,9 @@
266266
{
267267
"name": "Injector"
268268
},
269+
{
270+
"name": "InternalViewRef"
271+
},
269272
{
270273
"name": "LEAVE_TOKEN_REGEX"
271274
},
@@ -440,9 +443,6 @@
440443
{
441444
"name": "RendererStyleFlags2"
442445
},
443-
{
444-
"name": "RootViewRef"
445-
},
446446
{
447447
"name": "RuntimeError"
448448
},
@@ -545,9 +545,6 @@
545545
{
546546
"name": "ViewEncapsulation"
547547
},
548-
{
549-
"name": "ViewRef"
550-
},
551548
{
552549
"name": "WebAnimationsDriver"
553550
},
@@ -821,9 +818,6 @@
821818
{
822819
"name": "detectChangesInViewIfAttached"
823820
},
824-
{
825-
"name": "detectChangesInternal"
826-
},
827821
{
828822
"name": "diPublicInInjector"
829823
},

packages/core/test/bundling/animations/bundle.golden_symbols.json

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,9 @@
287287
{
288288
"name": "Injector"
289289
},
290+
{
291+
"name": "InternalViewRef"
292+
},
290293
{
291294
"name": "KeyEventsPlugin"
292295
},
@@ -482,9 +485,6 @@
482485
{
483486
"name": "RootComponent"
484487
},
485-
{
486-
"name": "RootViewRef"
487-
},
488488
{
489489
"name": "RuntimeError"
490490
},
@@ -599,9 +599,6 @@
599599
{
600600
"name": "ViewEncapsulation"
601601
},
602-
{
603-
"name": "ViewRef"
604-
},
605602
{
606603
"name": "WebAnimationsDriver"
607604
},
@@ -884,9 +881,6 @@
884881
{
885882
"name": "detectChangesInViewIfAttached"
886883
},
887-
{
888-
"name": "detectChangesInternal"
889-
},
890884
{
891885
"name": "diPublicInInjector"
892886
},

packages/core/test/bundling/cyclic_import/bundle.golden_symbols.json

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@
194194
{
195195
"name": "Injector"
196196
},
197+
{
198+
"name": "InternalViewRef"
199+
},
197200
{
198201
"name": "KeyEventsPlugin"
199202
},
@@ -368,9 +371,6 @@
368371
{
369372
"name": "RendererStyleFlags2"
370373
},
371-
{
372-
"name": "RootViewRef"
373-
},
374374
{
375375
"name": "RuntimeError"
376376
},
@@ -458,9 +458,6 @@
458458
{
459459
"name": "ViewEncapsulation"
460460
},
461-
{
462-
"name": "ViewRef"
463-
},
464461
{
465462
"name": "ZONE_IS_STABLE_OBSERVABLE"
466463
},
@@ -668,9 +665,6 @@
668665
{
669666
"name": "detectChangesInViewIfAttached"
670667
},
671-
{
672-
"name": "detectChangesInternal"
673-
},
674668
{
675669
"name": "diPublicInInjector"
676670
},

packages/core/test/bundling/defer/bundle.golden_symbols.json

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,9 @@
227227
{
228228
"name": "Injector"
229229
},
230+
{
231+
"name": "InternalViewRef"
232+
},
230233
{
231234
"name": "KeyEventsPlugin"
232235
},
@@ -419,9 +422,6 @@
419422
{
420423
"name": "RendererStyleFlags2"
421424
},
422-
{
423-
"name": "RootViewRef"
424-
},
425425
{
426426
"name": "RuntimeError"
427427
},
@@ -509,9 +509,6 @@
509509
{
510510
"name": "ViewEncapsulation"
511511
},
512-
{
513-
"name": "ViewRef"
514-
},
515512
{
516513
"name": "ZONE_IS_STABLE_OBSERVABLE"
517514
},
@@ -758,9 +755,6 @@
758755
{
759756
"name": "detectChangesInViewIfAttached"
760757
},
761-
{
762-
"name": "detectChangesInternal"
763-
},
764758
{
765759
"name": "diPublicInInjector"
766760
},

packages/core/test/bundling/forms_reactive/bundle.golden_symbols.json

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,9 @@
272272
{
273273
"name": "Injector"
274274
},
275+
{
276+
"name": "InternalViewRef"
277+
},
275278
{
276279
"name": "IterableChangeRecord_"
277280
},
@@ -506,9 +509,6 @@
506509
{
507510
"name": "RootComponent"
508511
},
509-
{
510-
"name": "RootViewRef"
511-
},
512512
{
513513
"name": "RuntimeError"
514514
},
@@ -614,9 +614,6 @@
614614
{
615615
"name": "ViewEngineTemplateRef"
616616
},
617-
{
618-
"name": "ViewRef"
619-
},
620617
{
621618
"name": "ZONE_IS_STABLE_OBSERVABLE"
622619
},
@@ -911,9 +908,6 @@
911908
{
912909
"name": "detectChangesInViewIfAttached"
913910
},
914-
{
915-
"name": "detectChangesInternal"
916-
},
917911
{
918912
"name": "diPublicInInjector"
919913
},

packages/core/test/bundling/forms_template_driven/bundle.golden_symbols.json

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,9 @@
257257
{
258258
"name": "Injector"
259259
},
260+
{
261+
"name": "InternalViewRef"
262+
},
260263
{
261264
"name": "IterableChangeRecord_"
262265
},
@@ -494,9 +497,6 @@
494497
{
495498
"name": "RootComponent"
496499
},
497-
{
498-
"name": "RootViewRef"
499-
},
500500
{
501501
"name": "RuntimeError"
502502
},
@@ -605,9 +605,6 @@
605605
{
606606
"name": "ViewEngineTemplateRef"
607607
},
608-
{
609-
"name": "ViewRef"
610-
},
611608
{
612609
"name": "ZONE_IS_STABLE_OBSERVABLE"
613610
},
@@ -881,9 +878,6 @@
881878
{
882879
"name": "detectChangesInViewIfAttached"
883880
},
884-
{
885-
"name": "detectChangesInternal"
886-
},
887881
{
888882
"name": "diPublicInInjector"
889883
},

packages/core/test/bundling/hello_world/bundle.golden_symbols.json

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@
137137
{
138138
"name": "Injector"
139139
},
140+
{
141+
"name": "InternalViewRef"
142+
},
140143
{
141144
"name": "LOCALE_ID2"
142145
},
@@ -281,9 +284,6 @@
281284
{
282285
"name": "RendererFactory2"
283286
},
284-
{
285-
"name": "RootViewRef"
286-
},
287287
{
288288
"name": "RuntimeError"
289289
},
@@ -350,9 +350,6 @@
350350
{
351351
"name": "ViewEncapsulation"
352352
},
353-
{
354-
"name": "ViewRef"
355-
},
356353
{
357354
"name": "ZONE_IS_STABLE_OBSERVABLE"
358355
},
@@ -527,9 +524,6 @@
527524
{
528525
"name": "detectChangesInViewIfAttached"
529526
},
530-
{
531-
"name": "detectChangesInternal"
532-
},
533527
{
534528
"name": "diPublicInInjector"
535529
},

0 commit comments

Comments
 (0)