chore: Cleanup dataFetcher

This commit is contained in:
Sidharth Vinod 2024-06-29 02:42:03 +05:30
parent b1b5ad3c9b
commit 3c6ae36611
No known key found for this signature in database
GPG Key ID: FB5CCD378D3907CD

View File

@ -35,7 +35,7 @@ import {
} from './stateCommon.js';
// List of nodes created from the parsed diagram statement items
let nodeDb = {};
let nodeDb = new Map();
let graphItemCount = 0; // used to construct ids, etc.
@ -104,7 +104,6 @@ const setupDoc = (parentParsedItem, doc, diagramStates, nodes, edges, altFlag, l
look,
};
edges.push(edgeData);
//g.setEdge(item.state1.id, item.state2.id, edgeData, graphItemCount);
graphItemCount++;
}
break;
@ -229,6 +228,7 @@ function getStylesFromDbInfo(dbInfoItem) {
}
}
}
export const dataFetcher = (
parent,
parsedItem,
@ -259,17 +259,17 @@ export const dataFetcher = (
}
// Add the node to our list (nodeDb)
if (!nodeDb[itemId]) {
nodeDb[itemId] = {
if (!nodeDb.get(itemId)) {
nodeDb.set(itemId, {
id: itemId,
shape,
description: common.sanitizeText(itemId, getConfig()),
cssClasses: `${classStr} ${CSS_DIAGRAM_STATE}`,
cssStyles: style,
};
});
}
const newNode = nodeDb[itemId];
const newNode = nodeDb.get(itemId);
// Save data for description and group so that for instance a statement without description overwrites
// one with description @todo TODO What does this mean? If important, add a test for it
@ -305,7 +305,6 @@ export const dataFetcher = (
} else {
newNode.shape = SHAPE_STATE;
}
//newNode.shape = SHAPE_STATE;
}
// group
@ -315,12 +314,7 @@ export const dataFetcher = (
newNode.isGroup = true;
newNode.dir = getDir(parsedItem);
newNode.shape = parsedItem.type === DIVIDER_TYPE ? SHAPE_DIVIDER : SHAPE_GROUP;
newNode.cssClasses =
newNode.cssClasses +
' ' +
CSS_DIAGRAM_CLUSTER +
' ' +
(altFlag ? CSS_DIAGRAM_CLUSTER_ALT : '');
newNode.cssClasses = `${newNode.cssClasses} ${CSS_DIAGRAM_CLUSTER} ${altFlag ? CSS_DIAGRAM_CLUSTER_ALT : ''}`;
}
// This is what will be added to the graph
@ -436,6 +430,6 @@ export const dataFetcher = (
};
export const reset = () => {
nodeDb = {};
nodeDb.clear();
graphItemCount = 0;
};