diagramClasses no longer needs to be cached; mermaidAPI no longer calls it repeatedly

This commit is contained in:
Ashley Engelund (weedySeaDragon @ github) 2022-11-15 09:18:10 -08:00
parent 6090a1f65a
commit 13f3008f82
1 changed files with 4 additions and 13 deletions

View File

@ -58,11 +58,7 @@ const G_EDGE_LABELTYPE = 'text';
const G_EDGE_THICKNESS = 'normal'; const G_EDGE_THICKNESS = 'normal';
// -------------------------------------- // --------------------------------------
// When information is parsed and processed (extracted) by stateDb.extract()
// These are globals so the information can be accessed as needed (e.g. in setUpNode, etc.)
let diagramStates = []; let diagramStates = [];
let diagramClasses = [];
// List of nodes created from the parsed diagram statement items // List of nodes created from the parsed diagram statement items
let nodeDb = {}; let nodeDb = {};
@ -81,18 +77,14 @@ export const setConf = function (cnf) {
}; };
/** /**
* Returns the all the styles from classDef statements in the graph definition. * Returns the all the classdef styles (a.k.a. classes) from classDef statements in the graph definition.
* *
* @param {string} text - the diagram text to be parsed * @param {string} text - the diagram text to be parsed
* @param {Diagram} diagramObj * @param diagramObj
* @returns {object} ClassDef styles * @returns {object} ClassDef styles (a Map with keys = strings, values = )
*/ */
export const getClasses = function (text, diagramObj) { export const getClasses = function (text, diagramObj) {
log.trace('Extracting classes'); log.trace('Extracting classes');
if (diagramClasses.length > 0) {
return diagramClasses; // we have already extracted the classes
}
diagramObj.db.clear(); diagramObj.db.clear();
try { try {
// Parse the graph definition // Parse the graph definition
@ -407,8 +399,7 @@ export const draw = function (text, id, _version, diag) {
diag.db.extract(diag.db.getRootDocV2()); diag.db.extract(diag.db.getRootDocV2());
log.info(diag.db.getRootDocV2()); log.info(diag.db.getRootDocV2());
diagramStates = diag.db.getStates(); const diagramStates = diag.db.getStates();
diagramClasses = diag.db.getClasses();
// Create the input mermaid.graph // Create the input mermaid.graph
const g = new graphlib.Graph({ const g = new graphlib.Graph({