refactor(ivy): minor improvements / cleanup in the DI code (#33794)
PR Close #33794
This commit is contained in:
parent
f4cdd35b3c
commit
784fd26473
|
@ -326,10 +326,9 @@ export function injectAttributeImpl(tNode: TNode, attrNameToInject: string): str
|
|||
* @returns the value from the injector, `null` when not found, or `notFoundValue` if provided
|
||||
*/
|
||||
export function getOrCreateInjectable<T>(
|
||||
tNode: TElementNode | TContainerNode | TElementContainerNode | null, lView: LView,
|
||||
token: Type<T>| InjectionToken<T>, flags: InjectFlags = InjectFlags.Default,
|
||||
notFoundValue?: any): T|null {
|
||||
if (tNode) {
|
||||
tNode: TDirectiveHostNode | null, lView: LView, token: Type<T>| InjectionToken<T>,
|
||||
flags: InjectFlags = InjectFlags.Default, notFoundValue?: any): T|null {
|
||||
if (tNode !== null) {
|
||||
const bloomHash = bloomHashBitOrFactory(token);
|
||||
// If the ID stored here is a function, this is a special object like ElementRef or TemplateRef
|
||||
// so just call the factory function to create it.
|
||||
|
|
|
@ -9,7 +9,8 @@ import {InjectFlags, InjectionToken, resolveForwardRef} from '../../di';
|
|||
import {ɵɵinject} from '../../di/injector_compatibility';
|
||||
import {Type} from '../../interface/type';
|
||||
import {getOrCreateInjectable, injectAttributeImpl} from '../di';
|
||||
import {TContainerNode, TElementContainerNode, TElementNode} from '../interfaces/node';
|
||||
import {TDirectiveHostNode, TNodeType} from '../interfaces/node';
|
||||
import {assertNodeOfPossibleTypes} from '../node_assert';
|
||||
import {getLView, getPreviousOrParentTNode} from '../state';
|
||||
|
||||
/**
|
||||
|
@ -40,15 +41,15 @@ export function ɵɵdirectiveInject<T>(token: Type<T>| InjectionToken<T>): T;
|
|||
export function ɵɵdirectiveInject<T>(token: Type<T>| InjectionToken<T>, flags: InjectFlags): T;
|
||||
export function ɵɵdirectiveInject<T>(
|
||||
token: Type<T>| InjectionToken<T>, flags = InjectFlags.Default): T|null {
|
||||
token = resolveForwardRef(token);
|
||||
const lView = getLView();
|
||||
// Fall back to inject() if view hasn't been created. This situation can happen in tests
|
||||
// if inject utilities are used before bootstrapping.
|
||||
if (lView == null) return ɵɵinject(token, flags);
|
||||
|
||||
const tNode = getPreviousOrParentTNode();
|
||||
ngDevMode && assertNodeOfPossibleTypes(
|
||||
tNode, TNodeType.Container, TNodeType.Element, TNodeType.ElementContainer);
|
||||
return getOrCreateInjectable<T>(
|
||||
getPreviousOrParentTNode() as TElementNode | TContainerNode | TElementContainerNode, lView,
|
||||
token, flags);
|
||||
tNode as TDirectiveHostNode, lView, resolveForwardRef(token), flags);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue