mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
refactor(devtools): remove ng.getComponent calls in places it is no longer needed
This commit is contained in:
parent
f39fe31355
commit
0ba899bfd5
3 changed files with 8 additions and 9 deletions
|
|
@ -160,7 +160,7 @@ const findElementIDFromNativeElementInForest = (
|
|||
return null;
|
||||
};
|
||||
|
||||
export const findNodeFromSerializedPosition = (serializedPosition: string) => {
|
||||
export const findNodeFromSerializedPosition = (serializedPosition: string): ComponentTreeNode | null => {
|
||||
const position: number[] = serializedPosition.split(',').map((index) => parseInt(index, 10));
|
||||
return queryDirectiveForest(position, buildDirectiveForest());
|
||||
};
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ const _setConsoleReference = (referenceNode: ConsoleReferenceNode) => {
|
|||
};
|
||||
|
||||
const prepareCurrentReferencesForInsertion = (referenceNode: ConsoleReferenceNode) => {
|
||||
const foundIndex = nodesForConsoleReference.findIndex(nodeToLookFor =>
|
||||
const foundIndex = nodesForConsoleReference.findIndex((nodeToLookFor) =>
|
||||
arrayEquals(nodeToLookFor.position, referenceNode.position)
|
||||
);
|
||||
if (foundIndex !== -1) {
|
||||
|
|
@ -44,13 +44,13 @@ const assignConsoleReferencesFrom = (referenceNodes: ConsoleReferenceNode[]) =>
|
|||
);
|
||||
};
|
||||
|
||||
const setDirectiveKey = (node: ComponentTreeNode | null, key) => {
|
||||
const setDirectiveKey = (node: ComponentTreeNode | null, key: string) => {
|
||||
Object.defineProperty(window, key, {
|
||||
get: () => {
|
||||
if (node && node.nativeElement instanceof HTMLElement) {
|
||||
return ng.getComponent(node.nativeElement) || node;
|
||||
if (node?.component) {
|
||||
return node.component.instance;
|
||||
}
|
||||
if (node) {
|
||||
if (node?.nativeElement) {
|
||||
return node.nativeElement;
|
||||
}
|
||||
return node;
|
||||
|
|
|
|||
|
|
@ -23,9 +23,8 @@ const chromeWindowExtensions = {
|
|||
console.error(`Cannot find element associated with node ${serializedId}`);
|
||||
return;
|
||||
}
|
||||
const root = node.nativeElement instanceof HTMLElement && ng.getComponent(node.nativeElement);
|
||||
if (root) {
|
||||
return root.constructor;
|
||||
if (node.component) {
|
||||
return node.component.instance.constructor;
|
||||
} else {
|
||||
console.error('This component has no instance and therefore no constructor');
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue