mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-07 17:46:44 +02:00
chore: Minor refactor
This commit is contained in:
@@ -2,4 +2,4 @@
|
|||||||
'mermaid': patch
|
'mermaid': patch
|
||||||
---
|
---
|
||||||
|
|
||||||
In State Diagram refactored getDirection to retrieve the direction from rootDoc, defaulting to DEFAULT_DIAGRAM_DIRECTION and Updated setDirection to modify the existing direction if found or prepend a new entry if not.
|
fix: `getDirection` and `setDirection` in `stateDb` refactored to return and set actual direction
|
||||||
|
@@ -657,13 +657,21 @@ export class StateDB {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getDirection() {
|
/**
|
||||||
const doc = this.rootDoc.find((doc) => doc.stmt === STMT_DIRECTION);
|
* Finds the direction statement in the root document.
|
||||||
const direction = doc ? doc.value : DEFAULT_DIAGRAM_DIRECTION;
|
* @private
|
||||||
return direction;
|
* @returns {{ value: string } | undefined} - the direction statement if present
|
||||||
|
*/
|
||||||
|
getDirectionStatement() {
|
||||||
|
return this.rootDoc.find((doc) => doc.stmt === STMT_DIRECTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getDirection() {
|
||||||
|
return this.getDirectionStatement()?.value ?? DEFAULT_DIAGRAM_DIRECTION;
|
||||||
|
}
|
||||||
|
|
||||||
setDirection(dir) {
|
setDirection(dir) {
|
||||||
const doc = this.rootDoc.find((doc) => doc.stmt === STMT_DIRECTION);
|
const doc = this.getDirectionStatement();
|
||||||
if (doc) {
|
if (doc) {
|
||||||
doc.value = dir;
|
doc.value = dir;
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user