Skip to content

Commit

Permalink
refactor: Add type annotations and optimize redundant set loop
Browse files Browse the repository at this point in the history
  • Loading branch information
kairi003 committed Nov 9, 2024
1 parent 828da5a commit dbc04be
Showing 1 changed file with 22 additions and 27 deletions.
49 changes: 22 additions & 27 deletions packages/mermaid/src/diagrams/class/classDb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ let classCounter = 0;
let namespaces = new Map<string, NamespaceNode>();
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());

Expand Down Expand Up @@ -125,12 +126,12 @@ export const lookUpDomId = function (_id: string): string {

export const clear = function () {
relations = [];
classes = new Map();
notes = [];
classes = new Map<string, ClassNode>();
notes = new Map<string, ClassNote>();
interfaces = [];
functions = [];
functions.push(setupToolTips);
namespaces = new Map();
namespaces = new Map<string, NamespaceNode>();
namespaceCounter = 0;
direction = 'TB';
commonClear();
Expand Down Expand Up @@ -602,31 +603,25 @@ export const getData = () => {
const edges: Edge[] = [];
const config = getConfig();

for (const namespaceKey of namespaces.keys()) {
const namespace = namespaces.get(namespaceKey);
if (namespace) {
const node: Node = {
id: namespace.id,
label: namespace.id,
isGroup: true,
padding: config.class!.padding ?? 16,
// parent node must be one of [rect, roundedWithTitle, noteGroup, divider]
shape: 'rect',
cssStyles: ['fill: none', 'stroke: black'],
look: config.look,
};
nodes.push(node);
}
for (const namespace of namespaces.values()) {
const node: Node = {
id: namespace.id,
label: namespace.id,
isGroup: true,
padding: config.class!.padding ?? 16,
// parent node must be one of [rect, roundedWithTitle, noteGroup, divider]
shape: 'rect',
cssStyles: ['fill: none', 'stroke: black'],
look: config.look,
};
nodes.push(node);
}

for (const classKey of classes.keys()) {
const classNode = classes.get(classKey);
if (classNode) {
const node = classNode as unknown as Node;
node.parentId = classNode.parent;
node.look = config.look;
nodes.push(node);
}
for (const classNode of classes.values()) {
const node = classNode as unknown as Node;
node.parentId = classNode.parent;
node.look = config.look;
nodes.push(node);
}

for (const note of notes.values()) {
Expand Down

0 comments on commit dbc04be

Please sign in to comment.