refactor(core): do not publish ɵɵgetFactoryOf()
(#41040)
Previously, `ɵɵgetFactoryOf()` was "privately" published from `@angular/core` since in the past it was assumed that this might be an instruction generated by the compiler. This is not currently the case, so this commit removes it from the private exports and renames it to indicate that it is a local helper function. PR Close #41040
This commit is contained in:
parent
326f167075
commit
11e16c7b41
@ -145,7 +145,6 @@ export {
|
|||||||
ɵɵenableBindings,
|
ɵɵenableBindings,
|
||||||
ɵɵFactoryDef,
|
ɵɵFactoryDef,
|
||||||
ɵɵgetCurrentView,
|
ɵɵgetCurrentView,
|
||||||
ɵɵgetFactoryOf,
|
|
||||||
ɵɵgetInheritedFactory,
|
ɵɵgetInheritedFactory,
|
||||||
ɵɵhostProperty,
|
ɵɵhostProperty,
|
||||||
ɵɵi18n,
|
ɵɵi18n,
|
||||||
|
@ -698,40 +698,19 @@ export class NodeInjector implements Injector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @codeGenApi
|
|
||||||
*/
|
|
||||||
export function ɵɵgetFactoryOf<T>(type: Type<any>): FactoryFn<T>|null {
|
|
||||||
const typeAny = type as any;
|
|
||||||
|
|
||||||
if (isForwardRef(type)) {
|
|
||||||
return (() => {
|
|
||||||
const factory = ɵɵgetFactoryOf<T>(resolveForwardRef(typeAny));
|
|
||||||
return factory ? factory() : null;
|
|
||||||
}) as any;
|
|
||||||
}
|
|
||||||
|
|
||||||
let factory = getFactoryDef<T>(typeAny);
|
|
||||||
if (factory === null) {
|
|
||||||
const injectorDef = getInjectorDef<T>(typeAny);
|
|
||||||
factory = injectorDef && injectorDef.factory;
|
|
||||||
}
|
|
||||||
return factory || null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @codeGenApi
|
* @codeGenApi
|
||||||
*/
|
*/
|
||||||
export function ɵɵgetInheritedFactory<T>(type: Type<any>): (type: Type<T>) => T {
|
export function ɵɵgetInheritedFactory<T>(type: Type<any>): (type: Type<T>) => T {
|
||||||
return noSideEffects(() => {
|
return noSideEffects(() => {
|
||||||
const ownConstructor = type.prototype.constructor;
|
const ownConstructor = type.prototype.constructor;
|
||||||
const ownFactory = ownConstructor[NG_FACTORY_DEF] || ɵɵgetFactoryOf(ownConstructor);
|
const ownFactory = ownConstructor[NG_FACTORY_DEF] || getFactoryOf(ownConstructor);
|
||||||
const objectPrototype = Object.prototype;
|
const objectPrototype = Object.prototype;
|
||||||
let parent = Object.getPrototypeOf(type.prototype).constructor;
|
let parent = Object.getPrototypeOf(type.prototype).constructor;
|
||||||
|
|
||||||
// Go up the prototype until we hit `Object`.
|
// Go up the prototype until we hit `Object`.
|
||||||
while (parent && parent !== objectPrototype) {
|
while (parent && parent !== objectPrototype) {
|
||||||
const factory = parent[NG_FACTORY_DEF] || ɵɵgetFactoryOf(parent);
|
const factory = parent[NG_FACTORY_DEF] || getFactoryOf(parent);
|
||||||
|
|
||||||
// If we hit something that has a factory and the factory isn't the same as the type,
|
// If we hit something that has a factory and the factory isn't the same as the type,
|
||||||
// we've found the inherited factory. Note the check that the factory isn't the type's
|
// we've found the inherited factory. Note the check that the factory isn't the type's
|
||||||
@ -752,3 +731,21 @@ export function ɵɵgetInheritedFactory<T>(type: Type<any>): (type: Type<T>) =>
|
|||||||
return t => new t();
|
return t => new t();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getFactoryOf<T>(type: Type<any>): FactoryFn<T>|null {
|
||||||
|
const typeAny = type as any;
|
||||||
|
|
||||||
|
if (isForwardRef(type)) {
|
||||||
|
return (() => {
|
||||||
|
const factory = getFactoryOf<T>(resolveForwardRef(typeAny));
|
||||||
|
return factory ? factory() : null;
|
||||||
|
}) as any;
|
||||||
|
}
|
||||||
|
|
||||||
|
let factory = getFactoryDef<T>(typeAny);
|
||||||
|
if (factory === null) {
|
||||||
|
const injectorDef = getInjectorDef<T>(typeAny);
|
||||||
|
factory = injectorDef && injectorDef.factory;
|
||||||
|
}
|
||||||
|
return factory || null;
|
||||||
|
}
|
||||||
|
@ -16,7 +16,7 @@ import {getComponent, getDirectives, getHostElement, getRenderedText} from './ut
|
|||||||
|
|
||||||
export {NgModuleType} from '../metadata/ng_module_def';
|
export {NgModuleType} from '../metadata/ng_module_def';
|
||||||
export {ComponentFactory, ComponentFactoryResolver, ComponentRef, injectComponentFactoryResolver} from './component_ref';
|
export {ComponentFactory, ComponentFactoryResolver, ComponentRef, injectComponentFactoryResolver} from './component_ref';
|
||||||
export {ɵɵgetFactoryOf, ɵɵgetInheritedFactory} from './di';
|
export {ɵɵgetInheritedFactory} from './di';
|
||||||
export {getLocaleId, setLocaleId} from './i18n/i18n_locale_id';
|
export {getLocaleId, setLocaleId} from './i18n/i18n_locale_id';
|
||||||
// clang-format off
|
// clang-format off
|
||||||
export {
|
export {
|
||||||
|
@ -1004,6 +1004,9 @@
|
|||||||
{
|
{
|
||||||
"name": "getFactoryDef"
|
"name": "getFactoryDef"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "getFactoryOf"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "getFirstLContainer"
|
"name": "getFirstLContainer"
|
||||||
},
|
},
|
||||||
@ -1718,9 +1721,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ɵɵelementStart"
|
"name": "ɵɵelementStart"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"name": "ɵɵgetFactoryOf"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "ɵɵgetInheritedFactory"
|
"name": "ɵɵgetInheritedFactory"
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user