refactor: circular deps part 1

This commit is contained in:
Nathan Walker
2025-07-06 10:05:35 -07:00
parent 0fe60552a3
commit 84f5f1920d
14 changed files with 85 additions and 127 deletions

View File

@ -1,5 +1,5 @@
//Types
import { DOMNode } from './dom-node';
import { DOMNode } from './dom-types';
export interface InspectorCommands {
// DevTools -> Application communication. Methods that devtools calls when needed.

View File

@ -2,7 +2,7 @@
import { ViewBase } from '../ui/core/view-base';
//Requires
import { getNodeById } from './dom-node';
import { getNodeById } from './dom-types';
import { mainThreadify } from '../utils';
// Use lazy requires for core modules

View File

@ -3,7 +3,8 @@ import { InspectorEvents, InspectorCommands } from './devtools-elements-interfac
// Requires
import { getDocument, getComputedStylesForNode, removeNode, setAttributeAsText } from './devtools-elements.common';
import { registerInspectorEvents, DOMNode } from './dom-node';
import { registerInspectorEvents } from './dom-types';
import { DOMNode } from './dom-types';
export * from './devtools-elements-interfaces';

View File

@ -1,27 +0,0 @@
import { ViewBase } from '../ui/core/view-base';
import { CSSComputedStyleProperty } from './css-agent';
export declare function getNodeById(id: number): DOMNode;
declare class WeakRef<T> {
constructor(obj: T);
get(): T;
clear(): void;
}
export declare class DOMNode {
nodeId: any;
nodeType: any;
nodeName: any;
localName: any;
nodeValue: string;
attributes: string[];
viewRef: WeakRef<ViewBase>;
constructor(view: ViewBase);
loadAttributes(): void;
readonly children: DOMNode[];
onChildAdded(childView: ViewBase): void;
onChildRemoved(view: ViewBase): void;
attributeModified(name: string, value: any): void;
attributeRemoved(name: string): void;
getComputedProperties(): CSSComputedStyleProperty[];
dispose(): void;
toJSON(): string;
}

View File

@ -1,28 +1,29 @@
import { CSSComputedStyleProperty } from './css-agent';
import { InspectorEvents } from './devtools-elements-interfaces';
// Needed for typings only
import { CSSComputedStyleProperty } from './css-agent';
import { ViewBase } from '../ui/core/view-base';
const registeredDomNodes = {};
const ELEMENT_NODE_TYPE = 1;
const ROOT_NODE_TYPE = 9;
const propertyBlacklist = ['effectivePaddingLeft', 'effectivePaddingBottom', 'effectivePaddingRight', 'effectivePaddingTop', 'effectiveBorderTopWidth', 'effectiveBorderRightWidth', 'effectiveBorderBottomWidth', 'effectiveBorderLeftWidth', 'effectiveMinWidth', 'effectiveMinHeight', 'effectiveWidth', 'effectiveHeight', 'effectiveMarginLeft', 'effectiveMarginTop', 'effectiveMarginRight', 'effectiveMarginBottom', 'nodeName', 'nodeType', 'decodeWidth', 'decodeHeight', 'ng-reflect-items', 'domNode', 'touchListenerIsSet', 'bindingContext', 'nativeView'];
function lazy<T>(action: () => T): () => T {
let _value: T;
return () => _value || (_value = action());
}
const percentLengthToStringLazy = lazy<(length) => string>(() => require('../ui/styling/style-properties').PercentLength.convertToString);
const getSetPropertiesLazy = lazy<(view: ViewBase) => [string, any][]>(() => require('../ui/core/properties').getSetProperties);
const getComputedCssValuesLazy = lazy<(view: ViewBase) => [string, any][]>(() => require('../ui/core/properties').getComputedCssValues);
const registeredDomNodes = {};
export function getNodeById(id: number): DOMNode {
return registeredDomNodes[id];
}
let inspectorFrontendInstance: any;
export function registerInspectorEvents(inspector: InspectorEvents) {
inspectorFrontendInstance = inspector;
}
let inspectorFrontendInstance: any;
function notifyInspector(callback: (inspector: InspectorEvents) => void) {
if (inspectorFrontendInstance) {
callback(inspectorFrontendInstance);
@ -63,10 +64,6 @@ function unregisterNode(domNode: DOMNode) {
delete registeredDomNodes[domNode.nodeId];
}
export function getNodeById(id: number): DOMNode {
return registeredDomNodes[id];
}
export class DOMNode {
nodeId;
nodeType;