mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-02 15:16:49 +02:00
refactor(mermaid): remove registerDiagram cb func
Remove the callback function parameter from registerDiagram. Instead, we can just load the callback function from the `injectUtils` diagram definition, if it exists.
This commit is contained in:
@@ -94,7 +94,7 @@ export const getDiagramFromText = async (txt: string, parseError?: Function): Pr
|
|||||||
}
|
}
|
||||||
// Diagram not available, loading it
|
// Diagram not available, loading it
|
||||||
const { diagram } = await loader();
|
const { diagram } = await loader();
|
||||||
registerDiagram(type, diagram, undefined, diagram.injectUtils);
|
registerDiagram(type, diagram, undefined);
|
||||||
// new diagram will try getDiagram again and if fails then it is a valid throw
|
// new diagram will try getDiagram again and if fails then it is a valid throw
|
||||||
}
|
}
|
||||||
// If either of the above worked, we have the diagram
|
// If either of the above worked, we have the diagram
|
||||||
|
@@ -22,17 +22,16 @@ export interface Detectors {
|
|||||||
[key: string]: DiagramDetector;
|
[key: string]: DiagramDetector;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* @param diagram
|
||||||
|
* @param detector
|
||||||
|
*/
|
||||||
export const registerDiagram = (
|
export const registerDiagram = (
|
||||||
id: string,
|
id: string,
|
||||||
diagram: DiagramDefinition,
|
diagram: DiagramDefinition,
|
||||||
detector?: DiagramDetector,
|
detector?: DiagramDetector
|
||||||
callback?: (
|
|
||||||
_log: any,
|
|
||||||
_setLogLevel: any,
|
|
||||||
_getConfig: any,
|
|
||||||
_sanitizeText: any,
|
|
||||||
_setupGraphViewbox: any
|
|
||||||
) => void
|
|
||||||
) => {
|
) => {
|
||||||
if (diagrams[id]) {
|
if (diagrams[id]) {
|
||||||
throw new Error(`Diagram ${id} already registered.`);
|
throw new Error(`Diagram ${id} already registered.`);
|
||||||
@@ -42,8 +41,9 @@ export const registerDiagram = (
|
|||||||
addDetector(id, detector);
|
addDetector(id, detector);
|
||||||
}
|
}
|
||||||
addStylesForDiagram(id, diagram.styles);
|
addStylesForDiagram(id, diagram.styles);
|
||||||
if (typeof callback !== 'undefined') {
|
|
||||||
callback(log, setLogLevel, getConfig, sanitizeText, setupGraphViewbox);
|
if (diagram.injectUtils) {
|
||||||
|
diagram.injectUtils(log, setLogLevel, getConfig, sanitizeText, setupGraphViewbox);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user