refactor(ivy): move directive, component and pipe factories to ngFactoryFn (#31953)
Reworks the compiler to output the factories for directives, components and pipes under a new static field called `ngFactoryFn`, instead of the usual `factory` property in their respective defs. This should eventually allow us to inject any kind of decorated class (e.g. a pipe). **Note:** these changes are the first part of the refactor and they don't include injectables. I decided to leave injectables for a follow-up PR, because there's some more cases we need to handle when it comes to their factories. Furthermore, directives, components and pipes make up most of the compiler output tests that need to be refactored and it'll make follow-up PRs easier to review if the tests are cleaned up now. This is part of the larger refactor for FW-1468. PR Close #31953
This commit is contained in:

committed by
atscott

parent
14feb56139
commit
c885178d5f
@ -10,6 +10,7 @@ import '../util/ng_dev_mode';
|
||||
|
||||
import {OnDestroy} from '../interface/lifecycle_hooks';
|
||||
import {Type} from '../interface/type';
|
||||
import {getFactoryDef} from '../render3/definition';
|
||||
import {throwCyclicDependencyError, throwInvalidProviderError, throwMixedMultiProviderError} from '../render3/errors';
|
||||
import {deepForEach, newArray} from '../util/array_utils';
|
||||
import {stringify} from '../util/stringify';
|
||||
@ -398,8 +399,10 @@ export class R3Injector {
|
||||
function injectableDefOrInjectorDefFactory(token: Type<any>| InjectionToken<any>): () => any {
|
||||
// Most tokens will have an ngInjectableDef directly on them, which specifies a factory directly.
|
||||
const injectableDef = getInjectableDef(token);
|
||||
if (injectableDef !== null) {
|
||||
return injectableDef.factory;
|
||||
const factory = injectableDef !== null ? injectableDef.factory : getFactoryDef(token);
|
||||
|
||||
if (factory !== null) {
|
||||
return factory;
|
||||
}
|
||||
|
||||
// If the token is an NgModule, it's also injectable but the factory is on its ngInjectorDef.
|
||||
|
Reference in New Issue
Block a user