refactor(core): Cleanup circular dependency between ViewEngine and Ivy `ElementRef`. (#39621)
`ElementRef` is declared in ViewEngine but it sub-classed in Ivy. This creates a circular dependency between ViewEngine `ElementRef` which needs to declare `__NG_ELEMENT_ID__` and ivy factory which needs to create it. The workaround used to be to pass the `ElementRef` through stack but that created a very convoluted code. This refactoring simply bundles the two files together and removes the stack workaround making the code simpler to follow. PR Close #39621
This commit is contained in:
parent
b0c4ecf563
commit
aa4924513b
|
@ -152,6 +152,93 @@
|
|||
"packages/core/src/render3/definition.ts",
|
||||
"packages/core/src/metadata/ng_module.ts"
|
||||
],
|
||||
[
|
||||
"packages/core/src/application_ref.ts",
|
||||
"packages/core/src/application_tokens.ts",
|
||||
"packages/core/src/linker/component_factory.ts",
|
||||
"packages/core/src/change_detection/change_detection.ts",
|
||||
"packages/core/src/change_detection/change_detector_ref.ts",
|
||||
"packages/core/src/render3/view_engine_compatibility.ts",
|
||||
"packages/core/src/linker/element_ref.ts",
|
||||
"packages/core/src/render3/interfaces/node.ts",
|
||||
"packages/core/src/render3/interfaces/view.ts",
|
||||
"packages/core/src/di/injector.ts",
|
||||
"packages/core/src/di/r3_injector.ts",
|
||||
"packages/core/src/render3/definition.ts",
|
||||
"packages/core/src/metadata/ng_module.ts"
|
||||
],
|
||||
[
|
||||
"packages/core/src/application_ref.ts",
|
||||
"packages/core/src/application_tokens.ts",
|
||||
"packages/core/src/linker/component_factory.ts",
|
||||
"packages/core/src/change_detection/change_detection.ts",
|
||||
"packages/core/src/change_detection/change_detector_ref.ts",
|
||||
"packages/core/src/render3/view_engine_compatibility.ts",
|
||||
"packages/core/src/linker/element_ref.ts",
|
||||
"packages/core/src/render3/interfaces/node.ts",
|
||||
"packages/core/src/render3/interfaces/view.ts",
|
||||
"packages/core/src/metadata.ts",
|
||||
"packages/core/src/di.ts",
|
||||
"packages/core/src/di/index.ts",
|
||||
"packages/core/src/di/injectable.ts",
|
||||
"packages/core/src/di/jit/injectable.ts",
|
||||
"packages/core/src/di/jit/environment.ts",
|
||||
"packages/core/src/di/injector_compatibility.ts",
|
||||
"packages/core/src/di/injector.ts",
|
||||
"packages/core/src/di/r3_injector.ts",
|
||||
"packages/core/src/render3/definition.ts",
|
||||
"packages/core/src/metadata/ng_module.ts"
|
||||
],
|
||||
[
|
||||
"packages/core/src/application_ref.ts",
|
||||
"packages/core/src/application_tokens.ts",
|
||||
"packages/core/src/linker/component_factory.ts",
|
||||
"packages/core/src/change_detection/change_detection.ts",
|
||||
"packages/core/src/change_detection/change_detector_ref.ts",
|
||||
"packages/core/src/render3/view_engine_compatibility.ts",
|
||||
"packages/core/src/linker/element_ref.ts",
|
||||
"packages/core/src/render3/interfaces/node.ts",
|
||||
"packages/core/src/render3/interfaces/view.ts",
|
||||
"packages/core/src/render3/interfaces/container.ts",
|
||||
"packages/core/src/linker/view_ref.ts"
|
||||
],
|
||||
[
|
||||
"packages/core/src/application_ref.ts",
|
||||
"packages/core/src/application_tokens.ts",
|
||||
"packages/core/src/linker/component_factory.ts",
|
||||
"packages/core/src/change_detection/change_detection.ts",
|
||||
"packages/core/src/change_detection/change_detector_ref.ts",
|
||||
"packages/core/src/render3/view_engine_compatibility.ts",
|
||||
"packages/core/src/linker/element_ref.ts",
|
||||
"packages/core/src/render3/interfaces/node.ts",
|
||||
"packages/core/src/render3/interfaces/view.ts",
|
||||
"packages/core/src/render3/interfaces/definition.ts",
|
||||
"packages/core/src/core.ts",
|
||||
"packages/core/src/metadata.ts",
|
||||
"packages/core/src/di.ts",
|
||||
"packages/core/src/di/index.ts",
|
||||
"packages/core/src/di/injectable.ts",
|
||||
"packages/core/src/di/jit/injectable.ts",
|
||||
"packages/core/src/di/jit/environment.ts",
|
||||
"packages/core/src/di/injector_compatibility.ts",
|
||||
"packages/core/src/di/injector.ts",
|
||||
"packages/core/src/di/r3_injector.ts",
|
||||
"packages/core/src/render3/definition.ts",
|
||||
"packages/core/src/metadata/ng_module.ts"
|
||||
],
|
||||
[
|
||||
"packages/core/src/application_ref.ts",
|
||||
"packages/core/src/application_tokens.ts",
|
||||
"packages/core/src/linker/component_factory.ts",
|
||||
"packages/core/src/change_detection/change_detection.ts",
|
||||
"packages/core/src/change_detection/change_detector_ref.ts",
|
||||
"packages/core/src/render3/view_engine_compatibility.ts",
|
||||
"packages/core/src/linker/element_ref.ts",
|
||||
"packages/core/src/render3/state.ts",
|
||||
"packages/core/src/render3/assert.ts",
|
||||
"packages/core/src/render3/definition.ts",
|
||||
"packages/core/src/metadata/ng_module.ts"
|
||||
],
|
||||
[
|
||||
"packages/core/src/application_ref.ts",
|
||||
"packages/core/src/application_tokens.ts",
|
||||
|
@ -179,16 +266,6 @@
|
|||
"packages/core/src/render3/definition.ts",
|
||||
"packages/core/src/metadata/ng_module.ts"
|
||||
],
|
||||
[
|
||||
"packages/core/src/application_ref.ts",
|
||||
"packages/core/src/application_tokens.ts",
|
||||
"packages/core/src/linker/component_factory.ts",
|
||||
"packages/core/src/change_detection/change_detection.ts",
|
||||
"packages/core/src/change_detection/change_detector_ref.ts",
|
||||
"packages/core/src/render3/view_engine_compatibility.ts",
|
||||
"packages/core/src/linker/template_ref.ts",
|
||||
"packages/core/src/linker/view_ref.ts"
|
||||
],
|
||||
[
|
||||
"packages/core/src/application_ref.ts",
|
||||
"packages/core/src/application_tokens.ts",
|
||||
|
@ -202,81 +279,6 @@
|
|||
"packages/core/src/render3/definition.ts",
|
||||
"packages/core/src/metadata/ng_module.ts"
|
||||
],
|
||||
[
|
||||
"packages/core/src/application_ref.ts",
|
||||
"packages/core/src/application_tokens.ts",
|
||||
"packages/core/src/linker/component_factory.ts",
|
||||
"packages/core/src/change_detection/change_detection.ts",
|
||||
"packages/core/src/change_detection/change_detector_ref.ts",
|
||||
"packages/core/src/render3/view_engine_compatibility.ts",
|
||||
"packages/core/src/render3/assert.ts",
|
||||
"packages/core/src/render3/definition.ts",
|
||||
"packages/core/src/metadata/ng_module.ts"
|
||||
],
|
||||
[
|
||||
"packages/core/src/application_ref.ts",
|
||||
"packages/core/src/application_tokens.ts",
|
||||
"packages/core/src/linker/component_factory.ts",
|
||||
"packages/core/src/change_detection/change_detection.ts",
|
||||
"packages/core/src/change_detection/change_detector_ref.ts",
|
||||
"packages/core/src/render3/view_engine_compatibility.ts",
|
||||
"packages/core/src/render3/assert.ts",
|
||||
"packages/core/src/render3/interfaces/container.ts",
|
||||
"packages/core/src/render3/interfaces/node.ts",
|
||||
"packages/core/src/render3/interfaces/view.ts",
|
||||
"packages/core/src/di/injector.ts",
|
||||
"packages/core/src/di/r3_injector.ts",
|
||||
"packages/core/src/render3/definition.ts",
|
||||
"packages/core/src/metadata/ng_module.ts"
|
||||
],
|
||||
[
|
||||
"packages/core/src/application_ref.ts",
|
||||
"packages/core/src/application_tokens.ts",
|
||||
"packages/core/src/linker/component_factory.ts",
|
||||
"packages/core/src/change_detection/change_detection.ts",
|
||||
"packages/core/src/change_detection/change_detector_ref.ts",
|
||||
"packages/core/src/render3/view_engine_compatibility.ts",
|
||||
"packages/core/src/render3/assert.ts",
|
||||
"packages/core/src/render3/interfaces/container.ts",
|
||||
"packages/core/src/render3/interfaces/node.ts",
|
||||
"packages/core/src/render3/interfaces/view.ts",
|
||||
"packages/core/src/metadata.ts",
|
||||
"packages/core/src/di.ts",
|
||||
"packages/core/src/di/index.ts",
|
||||
"packages/core/src/di/injectable.ts",
|
||||
"packages/core/src/di/jit/injectable.ts",
|
||||
"packages/core/src/di/jit/environment.ts",
|
||||
"packages/core/src/di/injector_compatibility.ts",
|
||||
"packages/core/src/di/injector.ts",
|
||||
"packages/core/src/di/r3_injector.ts",
|
||||
"packages/core/src/render3/definition.ts",
|
||||
"packages/core/src/metadata/ng_module.ts"
|
||||
],
|
||||
[
|
||||
"packages/core/src/application_ref.ts",
|
||||
"packages/core/src/application_tokens.ts",
|
||||
"packages/core/src/linker/component_factory.ts",
|
||||
"packages/core/src/change_detection/change_detection.ts",
|
||||
"packages/core/src/change_detection/change_detector_ref.ts",
|
||||
"packages/core/src/render3/view_engine_compatibility.ts",
|
||||
"packages/core/src/render3/assert.ts",
|
||||
"packages/core/src/render3/interfaces/container.ts",
|
||||
"packages/core/src/render3/interfaces/node.ts",
|
||||
"packages/core/src/render3/interfaces/view.ts",
|
||||
"packages/core/src/render3/interfaces/definition.ts",
|
||||
"packages/core/src/core.ts",
|
||||
"packages/core/src/metadata.ts",
|
||||
"packages/core/src/di.ts",
|
||||
"packages/core/src/di/index.ts",
|
||||
"packages/core/src/di/injectable.ts",
|
||||
"packages/core/src/di/jit/injectable.ts",
|
||||
"packages/core/src/di/jit/environment.ts",
|
||||
"packages/core/src/di/injector_compatibility.ts",
|
||||
"packages/core/src/di/injector.ts",
|
||||
"packages/core/src/di/r3_injector.ts",
|
||||
"packages/core/src/render3/definition.ts",
|
||||
"packages/core/src/metadata/ng_module.ts"
|
||||
],
|
||||
[
|
||||
"packages/core/src/application_ref.ts",
|
||||
"packages/core/src/application_tokens.ts",
|
||||
|
@ -867,7 +869,10 @@
|
|||
[
|
||||
"packages/core/src/change_detection/change_detector_ref.ts",
|
||||
"packages/core/src/render3/view_engine_compatibility.ts",
|
||||
"packages/core/src/linker/template_ref.ts",
|
||||
"packages/core/src/linker/element_ref.ts",
|
||||
"packages/core/src/render3/interfaces/node.ts",
|
||||
"packages/core/src/render3/interfaces/view.ts",
|
||||
"packages/core/src/render3/interfaces/container.ts",
|
||||
"packages/core/src/linker/view_ref.ts"
|
||||
],
|
||||
[
|
||||
|
@ -929,6 +934,9 @@
|
|||
],
|
||||
[
|
||||
"packages/core/src/linker/element_ref.ts",
|
||||
"packages/core/src/render3/interfaces/node.ts",
|
||||
"packages/core/src/render3/interfaces/renderer.ts",
|
||||
"packages/core/src/render/api.ts",
|
||||
"packages/core/src/render3/view_engine_compatibility.ts"
|
||||
],
|
||||
[
|
||||
|
@ -962,12 +970,12 @@
|
|||
"packages/core/src/render3/jit/pipe.ts"
|
||||
],
|
||||
[
|
||||
"packages/core/src/render/api.ts",
|
||||
"packages/core/src/render3/view_engine_compatibility.ts"
|
||||
"packages/core/src/render3/interfaces/container.ts",
|
||||
"packages/core/src/render3/interfaces/node.ts",
|
||||
"packages/core/src/render3/interfaces/view.ts"
|
||||
],
|
||||
[
|
||||
"packages/core/src/render3/interfaces/container.ts",
|
||||
"packages/core/src/render3/interfaces/node.ts",
|
||||
"packages/core/src/render3/interfaces/view.ts"
|
||||
],
|
||||
[
|
||||
|
|
|
@ -6,9 +6,37 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {injectElementRef as render3InjectElementRef} from '../render3/view_engine_compatibility';
|
||||
import {TNode} from '../render3/interfaces/node';
|
||||
import {RElement} from '../render3/interfaces/renderer';
|
||||
import {LView} from '../render3/interfaces/view';
|
||||
import {getCurrentTNode, getLView} from '../render3/state';
|
||||
import {getNativeByTNode} from '../render3/util/view_utils';
|
||||
import {noop} from '../util/noop';
|
||||
|
||||
/**
|
||||
* Creates an ElementRef from the most recent node.
|
||||
*
|
||||
* @returns The ElementRef instance to use
|
||||
*/
|
||||
export function injectElementRef(): ElementRef {
|
||||
return createElementRef(getCurrentTNode()!, getLView());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an ElementRef given a node.
|
||||
*
|
||||
* @param tNode The node for which you'd like an ElementRef
|
||||
* @param lView The view to which the node belongs
|
||||
* @returns The ElementRef instance to use
|
||||
*/
|
||||
export function createElementRef(tNode: TNode, lView: LView): ElementRef {
|
||||
return new ElementRef(getNativeByTNode(tNode, lView) as RElement);
|
||||
}
|
||||
|
||||
export const SWITCH_ELEMENT_REF_FACTORY__POST_R3__ = injectElementRef;
|
||||
const SWITCH_ELEMENT_REF_FACTORY__PRE_R3__ = noop;
|
||||
const SWITCH_ELEMENT_REF_FACTORY: typeof injectElementRef = SWITCH_ELEMENT_REF_FACTORY__PRE_R3__;
|
||||
|
||||
/**
|
||||
* A wrapper around a native element inside of a View.
|
||||
*
|
||||
|
@ -56,10 +84,5 @@ export class ElementRef<T = any> {
|
|||
* @internal
|
||||
* @nocollapse
|
||||
*/
|
||||
static __NG_ELEMENT_ID__: () => ElementRef = () => SWITCH_ELEMENT_REF_FACTORY(ElementRef);
|
||||
static __NG_ELEMENT_ID__: () => ElementRef = SWITCH_ELEMENT_REF_FACTORY;
|
||||
}
|
||||
|
||||
export const SWITCH_ELEMENT_REF_FACTORY__POST_R3__ = render3InjectElementRef;
|
||||
const SWITCH_ELEMENT_REF_FACTORY__PRE_R3__ = noop;
|
||||
const SWITCH_ELEMENT_REF_FACTORY: typeof render3InjectElementRef =
|
||||
SWITCH_ELEMENT_REF_FACTORY__PRE_R3__;
|
||||
|
|
|
@ -60,7 +60,7 @@ export abstract class TemplateRef<C> {
|
|||
* @nocollapse
|
||||
*/
|
||||
static __NG_ELEMENT_ID__:
|
||||
() => TemplateRef<any>| null = () => SWITCH_TEMPLATE_REF_FACTORY(TemplateRef, ElementRef)
|
||||
() => TemplateRef<any>| null = () => SWITCH_TEMPLATE_REF_FACTORY(TemplateRef)
|
||||
}
|
||||
|
||||
export const SWITCH_TEMPLATE_REF_FACTORY__POST_R3__ = render3InjectTemplateRef;
|
||||
|
|
|
@ -149,7 +149,7 @@ export abstract class ViewContainerRef {
|
|||
* @nocollapse
|
||||
*/
|
||||
static __NG_ELEMENT_ID__:
|
||||
() => ViewContainerRef = () => SWITCH_VIEW_CONTAINER_REF_FACTORY(ViewContainerRef, ElementRef)
|
||||
() => ViewContainerRef = () => SWITCH_VIEW_CONTAINER_REF_FACTORY(ViewContainerRef)
|
||||
}
|
||||
|
||||
export const SWITCH_VIEW_CONTAINER_REF_FACTORY__POST_R3__ = render3InjectViewContainerRef;
|
||||
|
|
|
@ -13,7 +13,7 @@ import {InjectFlags} from '../di/interface/injector';
|
|||
import {Type} from '../interface/type';
|
||||
import {ComponentFactory as viewEngine_ComponentFactory, ComponentRef as viewEngine_ComponentRef} from '../linker/component_factory';
|
||||
import {ComponentFactoryResolver as viewEngine_ComponentFactoryResolver} from '../linker/component_factory_resolver';
|
||||
import {ElementRef as viewEngine_ElementRef} from '../linker/element_ref';
|
||||
import {createElementRef, ElementRef as viewEngine_ElementRef} from '../linker/element_ref';
|
||||
import {NgModuleRef as viewEngine_NgModuleRef} from '../linker/ng_module_factory';
|
||||
import {RendererFactory2} from '../render/api';
|
||||
import {Sanitizer} from '../sanitization/sanitizer';
|
||||
|
@ -35,7 +35,6 @@ import {enterView, leaveView} from './state';
|
|||
import {setUpAttributes} from './util/attrs_utils';
|
||||
import {defaultScheduler} from './util/misc_utils';
|
||||
import {getTNode} from './util/view_utils';
|
||||
import {createElementRef} from './view_engine_compatibility';
|
||||
import {RootViewRef, ViewRef} from './view_ref';
|
||||
|
||||
export class ComponentFactoryResolver extends viewEngine_ComponentFactoryResolver {
|
||||
|
@ -219,8 +218,8 @@ export class ComponentFactory<T> extends viewEngine_ComponentFactory<T> {
|
|||
}
|
||||
|
||||
return new ComponentRef(
|
||||
this.componentType, component,
|
||||
createElementRef(viewEngine_ElementRef, tElementNode, rootLView), rootLView, tElementNode);
|
||||
this.componentType, component, createElementRef(tElementNode, rootLView), rootLView,
|
||||
tElementNode);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
import {InjectionToken} from '../di/injection_token';
|
||||
import {Type} from '../interface/type';
|
||||
import {ElementRef as ViewEngine_ElementRef} from '../linker/element_ref';
|
||||
import {createElementRef, ElementRef as ViewEngine_ElementRef} from '../linker/element_ref';
|
||||
import {QueryList} from '../linker/query_list';
|
||||
import {TemplateRef as ViewEngine_TemplateRef} from '../linker/template_ref';
|
||||
import {ViewContainerRef} from '../linker/view_container_ref';
|
||||
|
@ -30,7 +30,7 @@ import {DECLARATION_LCONTAINER, LView, PARENT, QUERIES, TVIEW, TView} from './in
|
|||
import {assertTNodeType} from './node_assert';
|
||||
import {getCurrentQueryIndex, getCurrentTNode, getLView, getTView, setCurrentQueryIndex} from './state';
|
||||
import {isCreationMode} from './util/view_utils';
|
||||
import {createContainerRef, createElementRef, createTemplateRef} from './view_engine_compatibility';
|
||||
import {createContainerRef, createTemplateRef} from './view_engine_compatibility';
|
||||
|
||||
const unusedValueToPlacateAjd = unused1 + unused2 + unused3 + unused4;
|
||||
|
||||
|
@ -300,9 +300,9 @@ function getIdxOfMatchingSelector(tNode: TNode, selector: string): number|null {
|
|||
|
||||
function createResultByTNodeType(tNode: TNode, currentView: LView): any {
|
||||
if (tNode.type & (TNodeType.AnyRNode | TNodeType.ElementContainer)) {
|
||||
return createElementRef(ViewEngine_ElementRef, tNode, currentView);
|
||||
return createElementRef(tNode, currentView);
|
||||
} else if (tNode.type & TNodeType.Container) {
|
||||
return createTemplateRef(ViewEngine_TemplateRef, ViewEngine_ElementRef, tNode, currentView);
|
||||
return createTemplateRef(ViewEngine_TemplateRef, tNode, currentView);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -323,14 +323,13 @@ function createResultForNode(lView: LView, tNode: TNode, matchingIdx: number, re
|
|||
|
||||
function createSpecialToken(lView: LView, tNode: TNode, read: any): any {
|
||||
if (read === ViewEngine_ElementRef) {
|
||||
return createElementRef(ViewEngine_ElementRef, tNode, lView);
|
||||
return createElementRef(tNode, lView);
|
||||
} else if (read === ViewEngine_TemplateRef) {
|
||||
return createTemplateRef(ViewEngine_TemplateRef, ViewEngine_ElementRef, tNode, lView);
|
||||
return createTemplateRef(ViewEngine_TemplateRef, tNode, lView);
|
||||
} else if (read === ViewContainerRef) {
|
||||
ngDevMode && assertTNodeType(tNode, TNodeType.AnyRNode | TNodeType.AnyContainer);
|
||||
return createContainerRef(
|
||||
ViewContainerRef, ViewEngine_ElementRef,
|
||||
tNode as TElementNode | TContainerNode | TElementContainerNode, lView);
|
||||
ViewContainerRef, tNode as TElementNode | TContainerNode | TElementContainerNode, lView);
|
||||
} else {
|
||||
ngDevMode &&
|
||||
throwError(
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
import {ChangeDetectorRef as ViewEngine_ChangeDetectorRef} from '../change_detection/change_detector_ref';
|
||||
import {Injector} from '../di/injector';
|
||||
import {ComponentFactory as viewEngine_ComponentFactory, ComponentRef as viewEngine_ComponentRef} from '../linker/component_factory';
|
||||
import {ElementRef as ViewEngine_ElementRef} from '../linker/element_ref';
|
||||
import {createElementRef, ElementRef as ViewEngine_ElementRef} from '../linker/element_ref';
|
||||
import {NgModuleRef as viewEngine_NgModuleRef} from '../linker/ng_module_factory';
|
||||
import {TemplateRef as ViewEngine_TemplateRef} from '../linker/template_ref';
|
||||
import {ViewContainerRef as ViewEngine_ViewContainerRef} from '../linker/view_container_ref';
|
||||
|
@ -36,35 +36,6 @@ import {ViewRef} from './view_ref';
|
|||
|
||||
|
||||
|
||||
/**
|
||||
* Creates an ElementRef from the most recent node.
|
||||
*
|
||||
* @returns The ElementRef instance to use
|
||||
*/
|
||||
export function injectElementRef(ElementRefToken: typeof ViewEngine_ElementRef):
|
||||
ViewEngine_ElementRef {
|
||||
return createElementRef(ElementRefToken, getCurrentTNode()!, getLView());
|
||||
}
|
||||
|
||||
let R3ElementRef: {new (native: RElement|RComment): ViewEngine_ElementRef};
|
||||
|
||||
/**
|
||||
* Creates an ElementRef given a node.
|
||||
*
|
||||
* @param ElementRefToken The ElementRef type
|
||||
* @param tNode The node for which you'd like an ElementRef
|
||||
* @param view The view to which the node belongs
|
||||
* @returns The ElementRef instance to use
|
||||
*/
|
||||
export function createElementRef(
|
||||
ElementRefToken: typeof ViewEngine_ElementRef, tNode: TNode,
|
||||
view: LView): ViewEngine_ElementRef {
|
||||
if (!R3ElementRef) {
|
||||
R3ElementRef = class ElementRef extends ElementRefToken {};
|
||||
}
|
||||
return new R3ElementRef(getNativeByTNode(tNode, view) as RElement);
|
||||
}
|
||||
|
||||
let R3TemplateRef: {
|
||||
new (_declarationParentView: LView, hostTNode: TContainerNode, elementRef: ViewEngine_ElementRef):
|
||||
ViewEngine_TemplateRef<any>
|
||||
|
@ -75,10 +46,9 @@ let R3TemplateRef: {
|
|||
*
|
||||
* @returns The TemplateRef instance to use
|
||||
*/
|
||||
export function injectTemplateRef<T>(
|
||||
TemplateRefToken: typeof ViewEngine_TemplateRef,
|
||||
ElementRefToken: typeof ViewEngine_ElementRef): ViewEngine_TemplateRef<T>|null {
|
||||
return createTemplateRef<T>(TemplateRefToken, ElementRefToken, getCurrentTNode()!, getLView());
|
||||
export function injectTemplateRef<T>(TemplateRefToken: typeof ViewEngine_TemplateRef):
|
||||
ViewEngine_TemplateRef<T>|null {
|
||||
return createTemplateRef<T>(TemplateRefToken, getCurrentTNode()!, getLView());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -91,8 +61,8 @@ export function injectTemplateRef<T>(
|
|||
* @returns The TemplateRef instance or null if we can't create a TemplateRef on a given node type
|
||||
*/
|
||||
export function createTemplateRef<T>(
|
||||
TemplateRefToken: typeof ViewEngine_TemplateRef, ElementRefToken: typeof ViewEngine_ElementRef,
|
||||
hostTNode: TNode, hostView: LView): ViewEngine_TemplateRef<T>|null {
|
||||
TemplateRefToken: typeof ViewEngine_TemplateRef, hostTNode: TNode,
|
||||
hostView: LView): ViewEngine_TemplateRef<T>|null {
|
||||
if (!R3TemplateRef) {
|
||||
R3TemplateRef = class TemplateRef<T> extends TemplateRefToken<T>{
|
||||
constructor(
|
||||
|
@ -126,8 +96,7 @@ export function createTemplateRef<T>(
|
|||
if (hostTNode.type & TNodeType.Container) {
|
||||
ngDevMode && assertDefined(hostTNode.tViews, 'TView must be allocated');
|
||||
return new R3TemplateRef(
|
||||
hostView, hostTNode as TContainerNode,
|
||||
createElementRef(ElementRefToken, hostTNode, hostView));
|
||||
hostView, hostTNode as TContainerNode, createElementRef(hostTNode, hostView));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
@ -145,11 +114,10 @@ let R3ViewContainerRef: {
|
|||
*
|
||||
* @returns The ViewContainerRef instance to use
|
||||
*/
|
||||
export function injectViewContainerRef(
|
||||
ViewContainerRefToken: typeof ViewEngine_ViewContainerRef,
|
||||
ElementRefToken: typeof ViewEngine_ElementRef): ViewEngine_ViewContainerRef {
|
||||
export function injectViewContainerRef(ViewContainerRefToken: typeof ViewEngine_ViewContainerRef):
|
||||
ViewEngine_ViewContainerRef {
|
||||
const previousTNode = getCurrentTNode() as TElementNode | TElementContainerNode | TContainerNode;
|
||||
return createContainerRef(ViewContainerRefToken, ElementRefToken, previousTNode, getLView());
|
||||
return createContainerRef(ViewContainerRefToken, previousTNode, getLView());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -163,7 +131,6 @@ export function injectViewContainerRef(
|
|||
*/
|
||||
export function createContainerRef(
|
||||
ViewContainerRefToken: typeof ViewEngine_ViewContainerRef,
|
||||
ElementRefToken: typeof ViewEngine_ElementRef,
|
||||
hostTNode: TElementNode|TContainerNode|TElementContainerNode,
|
||||
hostView: LView): ViewEngine_ViewContainerRef {
|
||||
if (!R3ViewContainerRef) {
|
||||
|
@ -176,7 +143,7 @@ export function createContainerRef(
|
|||
}
|
||||
|
||||
get element(): ViewEngine_ElementRef {
|
||||
return createElementRef(ElementRefToken, this._hostTNode, this._hostView);
|
||||
return createElementRef(this._hostTNode, this._hostView);
|
||||
}
|
||||
|
||||
get injector(): Injector {
|
||||
|
|
|
@ -9,16 +9,13 @@
|
|||
|
||||
import {ChangeDetectorRef} from '../change_detection/change_detector_ref';
|
||||
import {InjectFlags} from '../di/interface/injector';
|
||||
import {ElementRef as ViewEngine_ElementRef} from '../linker/element_ref';
|
||||
import {TemplateRef as ViewEngine_TemplateRef} from '../linker/template_ref';
|
||||
import {throwProviderNotFoundError} from './errors';
|
||||
|
||||
import {TNode} from './interfaces/node';
|
||||
import {LView} from './interfaces/view';
|
||||
import {createTemplateRef, injectChangeDetectorRef} from './view_engine_compatibility';
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves `TemplateRef` instance from `Injector` when a local reference is placed on the
|
||||
* `<ng-template>` element.
|
||||
|
@ -26,7 +23,7 @@ import {createTemplateRef, injectChangeDetectorRef} from './view_engine_compatib
|
|||
* @codeGenApi
|
||||
*/
|
||||
export function ɵɵtemplateRefExtractor(tNode: TNode, currentView: LView) {
|
||||
return createTemplateRef(ViewEngine_TemplateRef, ViewEngine_ElementRef, tNode, currentView);
|
||||
return createTemplateRef(ViewEngine_TemplateRef, tNode, currentView);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
import {ElementRef, TemplateRef, ViewContainerRef} from '../../../../src/linker';
|
||||
import {TemplateRef, ViewContainerRef} from '../../../../src/linker';
|
||||
import {ɵɵdefineDirective, ɵɵdirectiveInject, ɵɵtemplate} from '../../../../src/render3/index';
|
||||
import {createLView, createTNode, createTView} from '../../../../src/render3/instructions/shared';
|
||||
import {RenderFlags} from '../../../../src/render3/interfaces/definition';
|
||||
|
@ -21,7 +21,7 @@ class TemplateRefToken {
|
|||
* @nocollapse
|
||||
*/
|
||||
static __NG_ELEMENT_ID__(): TemplateRef<any>|null {
|
||||
return injectTemplateRef(TemplateRef, ElementRef);
|
||||
return injectTemplateRef(TemplateRef);
|
||||
}
|
||||
}
|
||||
class ViewContainerRefToken {
|
||||
|
@ -30,7 +30,7 @@ class ViewContainerRefToken {
|
|||
* @nocollapse
|
||||
*/
|
||||
static __NG_ELEMENT_ID__(): ViewContainerRef {
|
||||
return injectViewContainerRef(ViewContainerRef, ElementRef);
|
||||
return injectViewContainerRef(ViewContainerRef);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ import {ComponentDef, ComponentTemplate, ComponentType, DirectiveDef, DirectiveT
|
|||
import {DirectiveDefList, DirectiveDefListOrFactory, DirectiveTypesOrFactory, HostBindingsFunction, PipeDef, PipeDefList, PipeDefListOrFactory, PipeTypesOrFactory} from '../../src/render3/interfaces/definition';
|
||||
import {PlayerHandler} from '../../src/render3/interfaces/player';
|
||||
import {domRendererFactory3, ProceduralRenderer3, RComment, RElement, Renderer3, RendererFactory3, RendererStyleFlags3, RNode, RText} from '../../src/render3/interfaces/renderer';
|
||||
import {HEADER_OFFSET, LView, LViewFlags, TVIEW, TViewType} from '../../src/render3/interfaces/view';
|
||||
import {LView, LViewFlags, TVIEW, TViewType} from '../../src/render3/interfaces/view';
|
||||
import {destroyLView} from '../../src/render3/node_manipulation';
|
||||
import {getRootView} from '../../src/render3/util/view_traversal_utils';
|
||||
import {Sanitizer} from '../../src/sanitization/sanitizer';
|
||||
|
@ -452,10 +452,9 @@ export const text: RText = null as any as Text;
|
|||
* like injectElementRef() prematurely.
|
||||
*/
|
||||
export function enableIvyInjectableFactories() {
|
||||
(ElementRef as any)[NG_ELEMENT_ID] = () => R3_ELEMENT_REF_FACTORY(ElementRef);
|
||||
(TemplateRef as any)[NG_ELEMENT_ID] = () => R3_TEMPLATE_REF_FACTORY(TemplateRef, ElementRef);
|
||||
(ViewContainerRef as any)[NG_ELEMENT_ID] = () =>
|
||||
R3_VIEW_CONTAINER_REF_FACTORY(ViewContainerRef, ElementRef);
|
||||
(ElementRef as any)[NG_ELEMENT_ID] = () => R3_ELEMENT_REF_FACTORY();
|
||||
(TemplateRef as any)[NG_ELEMENT_ID] = () => R3_TEMPLATE_REF_FACTORY(TemplateRef);
|
||||
(ViewContainerRef as any)[NG_ELEMENT_ID] = () => R3_VIEW_CONTAINER_REF_FACTORY(ViewContainerRef);
|
||||
(ChangeDetectorRef as any)[NG_ELEMENT_ID] = () => R3_CHANGE_DETECTOR_REF_FACTORY();
|
||||
(Renderer2 as any)[NG_ELEMENT_ID] = () => R3_RENDERER2_FACTORY();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue