Skip to content

Commit 2adce03

Browse files
committed
refactor: drop ComponentFactoryResolver
This API was deprecated in 2022 and can be replaced by passing the component type directly to `createComponent`.
1 parent 3ad0c35 commit 2adce03

3 files changed

Lines changed: 12 additions & 39 deletions

File tree

tensorboard/webapp/app_routing/views/router_outlet_component.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ limitations under the License.
1515
import {
1616
ChangeDetectionStrategy,
1717
Component,
18-
ComponentFactoryResolver,
1918
Input,
2019
OnChanges,
2120
SimpleChanges,
@@ -35,20 +34,12 @@ export class RouterOutletComponent implements OnChanges {
3534

3635
@Input() activeNgComponent!: unknown | null;
3736

38-
constructor(
39-
private readonly componentFactoryResolver: ComponentFactoryResolver
40-
) {}
41-
4237
ngOnChanges(changes: SimpleChanges) {
4338
const activeComponentChange = changes['activeNgComponent'];
4439
if (activeComponentChange) {
4540
this.routeContainer.clear();
4641
if (activeComponentChange.currentValue) {
47-
const componentFactory =
48-
this.componentFactoryResolver.resolveComponentFactory(
49-
activeComponentChange.currentValue
50-
);
51-
this.routeContainer.createComponent(componentFactory);
42+
this.routeContainer.createComponent(activeComponentChange.currentValue);
5243
}
5344
}
5445
}

tensorboard/webapp/customization/customizable_component.ts

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
See the License for the specific language governing permissions and
1313
limitations under the License.
1414
==============================================================================*/
15-
import {
16-
Component,
17-
ComponentFactoryResolver,
18-
Input,
19-
OnInit,
20-
Type,
21-
ViewContainerRef,
22-
} from '@angular/core';
15+
import {Component, Input, OnInit, Type, ViewContainerRef} from '@angular/core';
2316

2417
/**
2518
* A Component that defines a customization point. Ideal for use for small
@@ -86,18 +79,13 @@ import {
8679
export class CustomizableComponent implements OnInit {
8780
@Input() customizableComponent!: Type<Component> | undefined;
8881

89-
constructor(
90-
private readonly viewContainerRef: ViewContainerRef,
91-
private readonly componentFactoryResolver: ComponentFactoryResolver
92-
) {}
82+
constructor(private readonly viewContainerRef: ViewContainerRef) {}
9383

9484
ngOnInit() {
9585
if (this.customizableComponent) {
96-
const componentFactory =
97-
this.componentFactoryResolver.resolveComponentFactory(
98-
this.customizableComponent.constructor as Type<unknown>
99-
);
100-
this.viewContainerRef.createComponent(componentFactory);
86+
this.viewContainerRef.createComponent(
87+
this.customizableComponent.constructor as Type<unknown>
88+
);
10189
}
10290
}
10391
}

tensorboard/webapp/plugins/plugins_component.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ limitations under the License.
2121
import {
2222
ChangeDetectionStrategy,
2323
Component,
24-
ComponentFactoryResolver,
2524
ElementRef,
2625
Input,
2726
OnChanges,
@@ -31,15 +30,15 @@ import {
3130
ViewChild,
3231
ViewContainerRef,
3332
} from '@angular/core';
34-
import {PluginApiHostModule} from '../../components/experimental/plugin_util/plugin_api_host_module';
35-
import {FeatureFlags} from '../feature_flag/types';
33+
import { PluginApiHostModule } from '../../components/experimental/plugin_util/plugin_api_host_module';
34+
import { FeatureFlags } from '../feature_flag/types';
3635
import {
3736
CustomElementLoadingMechanism,
3837
LoadingMechanismType,
3938
} from '../types/api';
40-
import {DataLoadState} from '../types/data';
41-
import {UiPluginMetadata} from './plugins_container';
42-
import {PluginRegistryModule} from './plugin_registry_module';
39+
import { DataLoadState } from '../types/data';
40+
import { PluginRegistryModule } from './plugin_registry_module';
41+
import { UiPluginMetadata } from './plugins_container';
4342

4443
interface PolymerDashboard extends HTMLElement {
4544
reload?: () => void;
@@ -64,7 +63,6 @@ export enum PluginLoadState {
6463
})
6564
export class PluginsComponent implements OnChanges {
6665
constructor(
67-
private readonly componentFactoryResolver: ComponentFactoryResolver,
6866
private readonly pluginRegistry: PluginRegistryModule,
6967
@Optional() private readonly pluginApiHost: PluginApiHostModule
7068
) {}
@@ -230,12 +228,8 @@ export class PluginsComponent implements OnChanges {
230228
case LoadingMechanismType.NG_COMPONENT:
231229
const ngComponentClass = this.pluginRegistry.getComponent(plugin.id);
232230
if (ngComponentClass) {
233-
const componentFactory =
234-
this.componentFactoryResolver.resolveComponentFactory(
235-
ngComponentClass
236-
);
237231
const pluginComponent =
238-
this.ngPluginContainer.createComponent(componentFactory);
232+
this.ngPluginContainer.createComponent(ngComponentClass);
239233
pluginElement = pluginComponent.location.nativeElement;
240234
} else {
241235
console.error(

0 commit comments

Comments
 (0)