fix(ivy): implement rootNodes getter on ViewRef (#27095)
PR Close #27095
This commit is contained in:

committed by
Andrew Kushnir

parent
1c9e526a83
commit
ce5242462b
@ -12,10 +12,12 @@ import {ViewContainerRef as viewEngine_ViewContainerRef} from '../linker/view_co
|
||||
import {EmbeddedViewRef as viewEngine_EmbeddedViewRef, InternalViewRef as viewEngine_InternalViewRef} from '../linker/view_ref';
|
||||
|
||||
import {checkNoChanges, checkNoChangesInRootView, detectChanges, detectChangesInRootView, markViewDirty, storeCleanupFn, viewAttached} from './instructions';
|
||||
import {TViewNode} from './interfaces/node';
|
||||
import {FLAGS, LViewData, LViewFlags, PARENT} from './interfaces/view';
|
||||
import {TNode, TNodeType, TViewNode} from './interfaces/node';
|
||||
import {FLAGS, HOST, HOST_NODE, LViewData, LViewFlags, PARENT} from './interfaces/view';
|
||||
import {destroyLView} from './node_manipulation';
|
||||
import {getRendererFactory} from './state';
|
||||
import {getNativeByTNode} from './util';
|
||||
|
||||
|
||||
|
||||
// Needed due to tsickle downleveling where multiple `implements` with classes creates
|
||||
@ -38,8 +40,13 @@ export class ViewRef<T> implements viewEngine_EmbeddedViewRef<T>, viewEngine_Int
|
||||
*/
|
||||
_tViewNode: TViewNode|null = null;
|
||||
|
||||
// TODO(issue/24571): remove '!'.
|
||||
rootNodes !: any[];
|
||||
get rootNodes(): any[] {
|
||||
if (this._view[HOST] == null) {
|
||||
const tView = this._view[HOST_NODE] as TViewNode;
|
||||
return collectNativeNodes(this._view, tView, []);
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
constructor(_view: LViewData, private _context: T|null, private _componentIndex: number) {
|
||||
this._view = _view;
|
||||
@ -269,3 +276,17 @@ export class RootViewRef<T> extends ViewRef<T> {
|
||||
|
||||
checkNoChanges(): void { checkNoChangesInRootView(this._view); }
|
||||
}
|
||||
|
||||
function collectNativeNodes(lView: LViewData, parentTNode: TNode, result: any[]): any[] {
|
||||
let tNodeChild = parentTNode.child;
|
||||
|
||||
while (tNodeChild) {
|
||||
result.push(getNativeByTNode(tNodeChild, lView));
|
||||
if (tNodeChild.type === TNodeType.ElementContainer) {
|
||||
collectNativeNodes(lView, tNodeChild, result);
|
||||
}
|
||||
tNodeChild = tNodeChild.next;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
Reference in New Issue
Block a user