Skip to content

Commit cd6f7f6

Browse files
committed
refactor(core): simplifying the ComponentFactory usage
The `ComponentFactory` has been removed from the public API in #68055. This commit continues the cleanup and also removes `ModuleWithComponentFactories` from the public API.
1 parent 39e382a commit cd6f7f6

17 files changed

Lines changed: 15 additions & 154 deletions

File tree

goldens/public-api/core/index.api.md

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,6 @@ export interface ClassSansProvider {
243243
export class Compiler {
244244
clearCache(): void;
245245
clearCacheFor(type: Type<any>): void;
246-
compileModuleAndAllComponentsAsync<T>(moduleType: Type<T>): Promise<ModuleWithComponentFactories<T>>;
247-
compileModuleAndAllComponentsSync<T>(moduleType: Type<T>): ModuleWithComponentFactories<T>;
248246
compileModuleAsync<T>(moduleType: Type<T>): Promise<NgModuleFactory<T>>;
249247
compileModuleSync<T>(moduleType: Type<T>): NgModuleFactory<T>;
250248
getModuleId(moduleType: Type<any>): string | undefined;
@@ -1221,15 +1219,6 @@ export interface ModelSignal<T> extends WritableSignal<T>, InputSignal<T>, Outpu
12211219
[SIGNAL]: InputSignalNode<T, T>;
12221220
}
12231221

1224-
// @public @deprecated
1225-
export class ModuleWithComponentFactories<T> {
1226-
constructor(ngModuleFactory: NgModuleFactory<T>, componentFactories: ComponentFactory<any>[]);
1227-
// (undocumented)
1228-
componentFactories: ComponentFactory<any>[];
1229-
// (undocumented)
1230-
ngModuleFactory: NgModuleFactory<T>;
1231-
}
1232-
12331222
// @public
12341223
export interface ModuleWithProviders<T> {
12351224
// (undocumented)

packages/core/src/core_private_export.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ export {
121121
} from './i18n/locale_data_api';
122122
export {DEFAULT_LOCALE_ID as ɵDEFAULT_LOCALE_ID} from './i18n/localization';
123123
export {Writable as ɵWritable} from './interface/type';
124-
export {ComponentFactory as ɵComponentFactory} from './linker/component_factory';
125124
export {
126125
clearResolutionOfComponentResourcesQueue as ɵclearResolutionOfComponentResourcesQueue,
127126
isComponentDefPendingResolution as ɵisComponentDefPendingResolution,

packages/core/src/linker.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,8 @@
77
*/
88

99
// Public API for compiler
10-
export {
11-
Compiler,
12-
COMPILER_OPTIONS,
13-
CompilerFactory,
14-
CompilerOptions,
15-
ModuleWithComponentFactories,
16-
} from './linker/compiler';
17-
export {ComponentRef, ComponentFactory as ɵComponentFactory} from './linker/component_factory';
10+
export {Compiler, COMPILER_OPTIONS, CompilerFactory, CompilerOptions} from './linker/compiler';
11+
export {ComponentRef} from './linker/component_factory';
1812
export {DestroyRef} from './linker/destroy_ref';
1913
export {ElementRef} from './linker/element_ref';
2014
export {NgModuleFactory, NgModuleRef} from './linker/ng_module_factory';

packages/core/src/linker/compiler.ts

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,13 @@ import {InjectionToken} from '../di/injection_token';
1111
import {StaticProvider} from '../di/interface/provider';
1212
import {Type} from '../interface/type';
1313
import {ViewEncapsulation} from '../metadata/view';
14-
import {ComponentFactory as ComponentFactoryR3} from '../render3/component_ref';
15-
import {getComponentDef, getNgModuleDef} from '../render3/def_getters';
1614
import {NgModuleFactory as NgModuleFactoryR3} from '../render3/ng_module_ref';
17-
import {maybeUnwrapFn} from '../render3/util/misc_utils';
1815

19-
import {ComponentFactory} from './component_factory';
2016
import {NgModuleFactory} from './ng_module_factory';
2117

22-
/**
23-
* Combination of NgModuleFactory and ComponentFactories.
24-
*
25-
* @publicApi
26-
*
27-
* @deprecated
28-
* Ivy JIT mode doesn't require accessing this symbol.
29-
*/
30-
export class ModuleWithComponentFactories<T> {
31-
constructor(
32-
public ngModuleFactory: NgModuleFactory<T>,
33-
public componentFactories: ComponentFactory<any>[],
34-
) {}
35-
}
36-
3718
/**
3819
* Low-level service for running the angular compiler during runtime
39-
* to create {@link ComponentFactory}s, which
20+
* to create {@link AbstractComponentFactory}s, which
4021
* can later be used to create and render a Component instance.
4122
*
4223
* Each `@NgModule` provides an own `Compiler` to its injector,
@@ -65,32 +46,6 @@ export class Compiler {
6546
return Promise.resolve(this.compileModuleSync(moduleType));
6647
}
6748

68-
/**
69-
* Same as {@link Compiler#compileModuleSync compileModuleSync} but also creates ComponentFactories for all components.
70-
*/
71-
compileModuleAndAllComponentsSync<T>(moduleType: Type<T>): ModuleWithComponentFactories<T> {
72-
const ngModuleFactory = this.compileModuleSync(moduleType);
73-
const moduleDef = getNgModuleDef(moduleType)!;
74-
const componentFactories = maybeUnwrapFn(moduleDef.declarations).reduce(
75-
(factories: ComponentFactory<any>[], declaration: Type<any>) => {
76-
const componentDef = getComponentDef(declaration);
77-
componentDef && factories.push(new ComponentFactoryR3(componentDef));
78-
return factories;
79-
},
80-
[] as ComponentFactory<any>[],
81-
);
82-
return new ModuleWithComponentFactories(ngModuleFactory, componentFactories);
83-
}
84-
85-
/**
86-
* Same as {@link Compiler#compileModuleAsync compileModuleAsync} but also creates ComponentFactories for all components.
87-
*/
88-
compileModuleAndAllComponentsAsync<T>(
89-
moduleType: Type<T>,
90-
): Promise<ModuleWithComponentFactories<T>> {
91-
return Promise.resolve(this.compileModuleAndAllComponentsSync(moduleType));
92-
}
93-
9449
/**
9550
* Clears all caches.
9651
*/

packages/core/src/linker/component_factory.ts

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@
88

99
import type {ChangeDetectorRef} from '../change_detection/change_detection';
1010
import type {Injector} from '../di/injector';
11-
import type {EnvironmentInjector} from '../di/r3_injector';
1211
import type {Type} from '../interface/type';
13-
import type {Binding, DirectiveWithBindings} from '../render3/dynamic_bindings';
1412

1513
import type {ElementRef} from './element_ref';
16-
import type {NgModuleRef} from './ng_module_factory';
1714
import type {ViewRef} from './view_ref';
1815

1916
/**
@@ -80,47 +77,3 @@ export abstract class ComponentRef<C> {
8077
*/
8178
abstract onDestroy(callback: Function): void;
8279
}
83-
84-
/**
85-
* Base class for a factory that can create a component dynamically.
86-
* Instantiate a factory for a given type of component with `resolveComponentFactory()`.
87-
* Use the resulting `ComponentFactory.create()` method to create a component of that type.
88-
*/
89-
export abstract class ComponentFactory<C> {
90-
/**
91-
* The component's HTML selector.
92-
*/
93-
abstract get selector(): string;
94-
/**
95-
* The type of component the factory will create.
96-
*/
97-
abstract get componentType(): Type<any>;
98-
/**
99-
* Selector for all <ng-content> elements in the component.
100-
*/
101-
abstract get ngContentSelectors(): string[];
102-
/**
103-
* The inputs of the component.
104-
*/
105-
abstract get inputs(): {
106-
propName: string;
107-
templateName: string;
108-
transform?: (value: any) => any;
109-
isSignal: boolean;
110-
}[];
111-
/**
112-
* The outputs of the component.
113-
*/
114-
abstract get outputs(): {propName: string; templateName: string}[];
115-
/**
116-
* Creates a new component.
117-
*/
118-
abstract create(
119-
injector: Injector,
120-
projectableNodes?: any[][],
121-
rootSelectorOrNode?: string | any,
122-
environmentInjector?: EnvironmentInjector | NgModuleRef<any>,
123-
directives?: (Type<unknown> | DirectiveWithBindings<unknown>)[],
124-
bindings?: Binding[],
125-
): ComponentRef<C>;
126-
}

packages/core/src/linker/view_container_ref.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
import {findMatchingDehydratedView, locateDehydratedViewsInContainer} from '../hydration/views';
2020
import {Type} from '../interface/type';
2121
import {assertNodeInjector} from '../render3/assert';
22-
import {ComponentFactory as R3ComponentFactory} from '../render3/component_ref';
22+
import {ComponentFactory} from '../render3/component_ref';
2323
import {getComponentDef} from '../render3/def_getters';
2424
import {getParentInjectorLocation, NodeInjector} from '../render3/di';
2525
import {nativeInsertBefore} from '../render3/dom_node_manipulation';
@@ -461,7 +461,7 @@ class R3ViewContainerRef extends ViewContainerRef {
461461
directives = options.directives;
462462
bindings = options.bindings;
463463

464-
const componentFactory = new R3ComponentFactory(getComponentDef(componentType)!);
464+
const componentFactory = new ComponentFactory(getComponentDef(componentType)!);
465465
const contextInjector = injector || this.parentInjector;
466466

467467
// If an `NgModuleRef` is not provided explicitly, try retrieving it from the DI tree.

packages/core/src/render3/component_ref.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ import {Injector} from '../di/injector';
1717
import {EnvironmentInjector} from '../di/r3_injector';
1818
import {RuntimeError, RuntimeErrorCode} from '../errors';
1919
import {Type} from '../interface/type';
20-
import {
21-
ComponentFactory as AbstractComponentFactory,
22-
ComponentRef as AbstractComponentRef,
23-
} from '../linker/component_factory';
20+
import {ComponentRef as AbstractComponentRef} from '../linker/component_factory';
2421
import {createElementRef, ElementRef} from '../linker/element_ref';
2522
import {NgModuleRef} from '../linker/ng_module_factory';
2623
import {RendererFactory2} from '../render/api';
@@ -199,10 +196,10 @@ export function inferTagNameFromDefinition(componentDef: ComponentDef<unknown>):
199196
/**
200197
* ComponentFactory interface implementation.
201198
*/
202-
export class ComponentFactory<T> extends AbstractComponentFactory<T> {
203-
override selector: string;
204-
override componentType: Type<any>;
205-
override ngContentSelectors: string[];
199+
export class ComponentFactory<T> {
200+
selector: string;
201+
componentType: Type<any>;
202+
ngContentSelectors: string[];
206203
isBoundToModule: boolean;
207204
private cachedInputs:
208205
| {
@@ -214,7 +211,7 @@ export class ComponentFactory<T> extends AbstractComponentFactory<T> {
214211
| null = null;
215212
private cachedOutputs: {propName: string; templateName: string}[] | null = null;
216213

217-
override get inputs(): {
214+
get inputs(): {
218215
propName: string;
219216
templateName: string;
220217
isSignal: boolean;
@@ -224,7 +221,7 @@ export class ComponentFactory<T> extends AbstractComponentFactory<T> {
224221
return this.cachedInputs;
225222
}
226223

227-
override get outputs(): {propName: string; templateName: string}[] {
224+
get outputs(): {propName: string; templateName: string}[] {
228225
this.cachedOutputs ??= toOutputRefArray(this.componentDef.outputs);
229226
return this.cachedOutputs;
230227
}
@@ -237,14 +234,13 @@ export class ComponentFactory<T> extends AbstractComponentFactory<T> {
237234
private componentDef: ComponentDef<any>,
238235
private ngModule?: NgModuleRef<any>,
239236
) {
240-
super();
241237
this.componentType = componentDef.type;
242238
this.selector = stringifyCSSSelectorList(componentDef.selectors);
243239
this.ngContentSelectors = componentDef.ngContentSelectors ?? [];
244240
this.isBoundToModule = !!ngModule;
245241
}
246242

247-
override create(
243+
create(
248244
injector: Injector,
249245
projectableNodes?: any[][] | undefined,
250246
rootSelectorOrNode?: any,

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
"ChangeDetectionSchedulerImpl",
6060
"ChangeDetectionStrategy",
6161
"ComponentFactory",
62-
"ComponentFactory2",
6362
"ComponentRef",
6463
"ComponentRef2",
6564
"ConsumerObserver",

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
"ChangeDetectionSchedulerImpl",
3737
"ChangeDetectionStrategy",
3838
"ComponentFactory",
39-
"ComponentFactory2",
4039
"ComponentRef",
4140
"ComponentRef2",
4241
"ConsumerObserver",

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@
8686
"ChangeDetectionSchedulerImpl",
8787
"ChangeDetectionStrategy",
8888
"ComponentFactory",
89-
"ComponentFactory2",
9089
"ComponentRef",
9190
"ComponentRef2",
9291
"ConsumerObserver",

0 commit comments

Comments
 (0)