refactor: Add type annotations and optimize redundant set loop

This commit is contained in:
kairi003
2024-11-10 02:05:34 +09:00
parent 309ff6be38
commit ec1c6325d4

View File

@@ -36,7 +36,8 @@ let classCounter = 0;
let namespaces = new Map<string, NamespaceNode>(); let namespaces = new Map<string, NamespaceNode>();
let namespaceCounter = 0; let namespaceCounter = 0;
let functions: any[] = []; // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
let functions: Function[] = [];
const sanitizeText = (txt: string) => common.sanitizeText(txt, getConfig()); const sanitizeText = (txt: string) => common.sanitizeText(txt, getConfig());
@@ -125,12 +126,12 @@ export const lookUpDomId = function (_id: string): string {
export const clear = function () { export const clear = function () {
relations = []; relations = [];
classes = new Map(); classes = new Map<string, ClassNode>();
notes = new Map<string, ClassNote>(); notes = new Map<string, ClassNote>();
interfaces = []; interfaces = [];
functions = []; functions = [];
functions.push(setupToolTips); functions.push(setupToolTips);
namespaces = new Map(); namespaces = new Map<string, NamespaceNode>();
namespaceCounter = 0; namespaceCounter = 0;
direction = 'TB'; direction = 'TB';
commonClear(); commonClear();
@@ -602,31 +603,25 @@ export const getData = () => {
const edges: Edge[] = []; const edges: Edge[] = [];
const config = getConfig(); const config = getConfig();
for (const namespaceKey of namespaces.keys()) { for (const namespace of namespaces.values()) {
const namespace = namespaces.get(namespaceKey); const node: Node = {
if (namespace) { id: namespace.id,
const node: Node = { label: namespace.id,
id: namespace.id, isGroup: true,
label: namespace.id, padding: config.class!.padding ?? 16,
isGroup: true, // parent node must be one of [rect, roundedWithTitle, noteGroup, divider]
padding: config.class!.padding ?? 16, shape: 'rect',
// parent node must be one of [rect, roundedWithTitle, noteGroup, divider] cssStyles: ['fill: none', 'stroke: black'],
shape: 'rect', look: config.look,
cssStyles: ['fill: none', 'stroke: black'], };
look: config.look, nodes.push(node);
};
nodes.push(node);
}
} }
for (const classKey of classes.keys()) { for (const classNode of classes.values()) {
const classNode = classes.get(classKey); const node = classNode as unknown as Node;
if (classNode) { node.parentId = classNode.parent;
const node = classNode as unknown as Node; node.look = config.look;
node.parentId = classNode.parent; nodes.push(node);
node.look = config.look;
nodes.push(node);
}
} }
for (const note of notes.values()) { for (const note of notes.values()) {