Repository navigation
fix(ivy): expose module injector ivy's TestBed impl #25685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,7 +7,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import {Injector} from '../di/injector'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import {Renderer2, RendererType2} from '../render/api'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import {Renderer2, RendererFactory2, RendererType2} from '../render/api'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import {DebugContext} from '../view'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import {DebugRenderer2, DebugRendererFactory2} from '../view/services'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -22,9 +22,12 @@ import {CONTEXT, DIRECTIVES, LViewData, TVIEW} from './interfaces/view'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * The created DebugRenderer know how to create a Debug Context specific to IVY. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export class Render3DebugRendererFactory2 extends DebugRendererFactory2 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| constructor(delegate: RendererFactory2, private _moduleInjector: Injector) { super(delegate); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| createRenderer(element: any, renderData: RendererType2|null): Renderer2 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const renderer = super.createRenderer(element, renderData) as DebugRenderer2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| renderer.debugContextFactory = () => new Render3DebugContext(_getViewData()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| renderer.debugContextFactory = () => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| new Render3DebugContext(this._moduleInjector, _getViewData()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return renderer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -37,9 +40,10 @@ export class Render3DebugRendererFactory2 extends DebugRendererFactory2 { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class Render3DebugContext implements DebugContext { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| readonly nodeIndex: number|null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| constructor(private viewData: LViewData) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // The LNode will be created next and appended to viewData | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.nodeIndex = viewData ? viewData.length : null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| constructor(private moduleInjector: Injector, private viewData: LViewData|null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // viewData can be null for the root element created to contain test component (such element is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // created before ivy kicks in and creates root view). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.nodeIndex = viewData ? viewData.length - 1 : null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is WRONG as reading
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would this help: angular/packages/core/src/render3/element_discovery.ts Lines 39 to 66 in 29761ea
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| get view(): any { return this.viewData; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -53,11 +57,11 @@ class Render3DebugContext implements DebugContext { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return new di.NodeInjector(nodeInjector); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return Injector.NULL; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return this.moduleInjector; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| get component(): any { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // TODO(vicb): why/when | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (this.nodeIndex === null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -74,7 +78,6 @@ class Render3DebugContext implements DebugContext { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| get providerTokens(): any[] { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const matchedDirectives: any[] = []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // TODO(vicb): why/when | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (this.nodeIndex === null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return matchedDirectives; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My current thinking is that
WRAP_RENDERER_FACTORY2should be reverted since withelement_discoverywe don't need it.What we should do is to change
angular/packages/core/src/debug/debug_node.ts
Lines 167 to 169 in 29761ea
ng_ivy_switch.tsso that in case of Ivy it returnsDebugNodeimplementation which knows how to useangular/packages/core/src/render3/element_discovery.ts
Lines 39 to 66 in 29761ea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mhevery I fully agree with the general idea of using element discovery to "enrich" native node with debug context for TestBed.
In the details, though, I don't think we can simply plug into
angular/packages/core/src/debug/debug_node.ts
Lines 167 to 169 in 29761ea
My thinking is that we will have to call
indexDebugNodefrom ivy instructions - unless we want to do deeper breaking changes to theTestBed.The challenge to call
indexDebugNodewould be to do this in the tree-shakable way (do so only in the debug mode?).Let's discuss more today.