mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-11-16 18:54:12 +01:00
Code refactor
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { StateDb } from '../stateDb.js';
|
import { StateDB } from '../stateDb.js';
|
||||||
import stateDiagram from './stateDiagram.jison';
|
import stateDiagram from './stateDiagram.jison';
|
||||||
import { setConfig } from '../../../config.js';
|
import { setConfig } from '../../../config.js';
|
||||||
|
|
||||||
@@ -9,7 +9,7 @@ setConfig({
|
|||||||
describe('state parser can parse...', () => {
|
describe('state parser can parse...', () => {
|
||||||
let stateDb;
|
let stateDb;
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
stateDb = new StateDb();
|
stateDb = new StateDB();
|
||||||
stateDiagram.parser.yy = stateDb;
|
stateDiagram.parser.yy = stateDb;
|
||||||
stateDiagram.parser.yy.clear();
|
stateDiagram.parser.yy.clear();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { StateDb } from '../stateDb.js';
|
import { StateDB } from '../stateDb.js';
|
||||||
import stateDiagram from './stateDiagram.jison';
|
import stateDiagram from './stateDiagram.jison';
|
||||||
import { setConfig } from '../../../config.js';
|
import { setConfig } from '../../../config.js';
|
||||||
|
|
||||||
@@ -9,7 +9,7 @@ setConfig({
|
|||||||
describe('ClassDefs and classes when parsing a State diagram', () => {
|
describe('ClassDefs and classes when parsing a State diagram', () => {
|
||||||
let stateDb;
|
let stateDb;
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
stateDb = new StateDb();
|
stateDb = new StateDB();
|
||||||
stateDiagram.parser.yy = stateDb;
|
stateDiagram.parser.yy = stateDb;
|
||||||
stateDiagram.parser.yy.clear();
|
stateDiagram.parser.yy.clear();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { line, curveBasis } from 'd3';
|
import { line, curveBasis } from 'd3';
|
||||||
import idCache from './id-cache.js';
|
import idCache from './id-cache.js';
|
||||||
import { StateDb } from './stateDb.js';
|
import { StateDB } from './stateDb.js';
|
||||||
import utils from '../../utils.js';
|
import utils from '../../utils.js';
|
||||||
import common from '../common/common.js';
|
import common from '../common/common.js';
|
||||||
import { getConfig } from '../../diagram-api/diagramAPI.js';
|
import { getConfig } from '../../diagram-api/diagramAPI.js';
|
||||||
@@ -412,7 +412,7 @@ export const drawState = function (elem, stateDef) {
|
|||||||
|
|
||||||
let edgeCount = 0;
|
let edgeCount = 0;
|
||||||
export const drawEdge = function (elem, path, relation) {
|
export const drawEdge = function (elem, path, relation) {
|
||||||
const stateDb = new StateDb();
|
const stateDb = new StateDB();
|
||||||
const getRelationType = function (type) {
|
const getRelationType = function (type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case stateDb.relationType.AGGREGATION:
|
case stateDb.relationType.AGGREGATION:
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import {
|
|||||||
STMT_STYLEDEF,
|
STMT_STYLEDEF,
|
||||||
} from './stateCommon.js';
|
} from './stateCommon.js';
|
||||||
|
|
||||||
export class StateDb {
|
export class StateDB {
|
||||||
#START_NODE = '[*]';
|
#START_NODE = '[*]';
|
||||||
#START_TYPE = 'start';
|
#START_TYPE = 'start';
|
||||||
#END_NODE = this.#START_NODE;
|
#END_NODE = this.#START_NODE;
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { StateDb } from './stateDb.js';
|
import { StateDB } from './stateDb.js';
|
||||||
|
|
||||||
describe('State Diagram stateDb', () => {
|
describe('State Diagram stateDb', () => {
|
||||||
let stateDb;
|
let stateDb;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
stateDb = new StateDb();
|
stateDb = new StateDB();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('addStyleClass', () => {
|
describe('addStyleClass', () => {
|
||||||
@@ -23,7 +23,7 @@ describe('State Diagram stateDb', () => {
|
|||||||
describe('addDescription to a state', () => {
|
describe('addDescription to a state', () => {
|
||||||
let stateDb;
|
let stateDb;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
stateDb = new StateDb();
|
stateDb = new StateDB();
|
||||||
stateDb.addState('state1');
|
stateDb.addState('state1');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ describe('State Diagram stateDb', () => {
|
|||||||
describe('state db class', () => {
|
describe('state db class', () => {
|
||||||
let stateDb;
|
let stateDb;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
stateDb = new StateDb();
|
stateDb = new StateDB();
|
||||||
});
|
});
|
||||||
// This is to ensure that functions used in flow JISON are exposed as function from FlowDb
|
// This is to ensure that functions used in flow JISON are exposed as function from FlowDb
|
||||||
it('should have functions used in flow JISON as own property', () => {
|
it('should have functions used in flow JISON as own property', () => {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { parser } from './parser/stateDiagram.jison';
|
import { parser } from './parser/stateDiagram.jison';
|
||||||
import { StateDb } from './stateDb.js';
|
import { StateDB } from './stateDb.js';
|
||||||
import stateDiagram from './parser/stateDiagram.jison';
|
import stateDiagram from './parser/stateDiagram.jison';
|
||||||
|
|
||||||
describe('state diagram V2, ', function () {
|
describe('state diagram V2, ', function () {
|
||||||
@@ -7,7 +7,7 @@ describe('state diagram V2, ', function () {
|
|||||||
describe('when parsing an info graph it', function () {
|
describe('when parsing an info graph it', function () {
|
||||||
let stateDb;
|
let stateDb;
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
stateDb = new StateDb();
|
stateDb = new StateDB();
|
||||||
parser.yy = stateDb;
|
parser.yy = stateDb;
|
||||||
stateDiagram.parser.yy = stateDb;
|
stateDiagram.parser.yy = stateDb;
|
||||||
stateDiagram.parser.yy.clear();
|
stateDiagram.parser.yy.clear();
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
import type { DiagramDefinition } from '../../diagram-api/types.js';
|
import type { DiagramDefinition } from '../../diagram-api/types.js';
|
||||||
// @ts-ignore: JISON doesn't support types
|
// @ts-ignore: JISON doesn't support types
|
||||||
import parser from './parser/stateDiagram.jison';
|
import parser from './parser/stateDiagram.jison';
|
||||||
import { StateDb } from './stateDb.js';
|
import { StateDB } from './stateDb.js';
|
||||||
import styles from './styles.js';
|
import styles from './styles.js';
|
||||||
import renderer from './stateRenderer-v3-unified.js';
|
import renderer from './stateRenderer-v3-unified.js';
|
||||||
|
|
||||||
export const diagram: DiagramDefinition = {
|
export const diagram: DiagramDefinition = {
|
||||||
parser,
|
parser,
|
||||||
get db() {
|
get db() {
|
||||||
return new StateDb();
|
return new StateDB();
|
||||||
},
|
},
|
||||||
renderer,
|
renderer,
|
||||||
styles,
|
styles,
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import { parser } from './parser/stateDiagram.jison';
|
import { parser } from './parser/stateDiagram.jison';
|
||||||
import { StateDb } from './stateDb.js';
|
import { StateDB } from './stateDb.js';
|
||||||
|
|
||||||
describe('state diagram, ', function () {
|
describe('state diagram, ', function () {
|
||||||
describe('when parsing an info graph it', function () {
|
describe('when parsing an info graph it', function () {
|
||||||
let stateDb;
|
let stateDb;
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
stateDb = new StateDb();
|
stateDb = new StateDB();
|
||||||
parser.yy = stateDb;
|
parser.yy = stateDb;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
import type { DiagramDefinition } from '../../diagram-api/types.js';
|
import type { DiagramDefinition } from '../../diagram-api/types.js';
|
||||||
// @ts-ignore: JISON doesn't support types
|
// @ts-ignore: JISON doesn't support types
|
||||||
import parser from './parser/stateDiagram.jison';
|
import parser from './parser/stateDiagram.jison';
|
||||||
import { StateDb } from './stateDb.js';
|
import { StateDB } from './stateDb.js';
|
||||||
import styles from './styles.js';
|
import styles from './styles.js';
|
||||||
import renderer from './stateRenderer.js';
|
import renderer from './stateRenderer.js';
|
||||||
|
|
||||||
export const diagram: DiagramDefinition = {
|
export const diagram: DiagramDefinition = {
|
||||||
parser,
|
parser,
|
||||||
get db() {
|
get db() {
|
||||||
return new StateDb();
|
return new StateDB();
|
||||||
},
|
},
|
||||||
renderer,
|
renderer,
|
||||||
styles,
|
styles,
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ import { compile, serialize } from 'stylis';
|
|||||||
import { Diagram } from './Diagram.js';
|
import { Diagram } from './Diagram.js';
|
||||||
import { decodeEntities, encodeEntities } from './utils.js';
|
import { decodeEntities, encodeEntities } from './utils.js';
|
||||||
import { toBase64 } from './utils/base64.js';
|
import { toBase64 } from './utils/base64.js';
|
||||||
import { StateDb } from './diagrams/state/stateDb.js';
|
import { StateDB } from './diagrams/state/stateDb.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see https://vitest.dev/guide/mocking.html Mock part of a module
|
* @see https://vitest.dev/guide/mocking.html Mock part of a module
|
||||||
@@ -857,8 +857,8 @@ graph TD;A--x|text including URL space|B;`)
|
|||||||
Crash --> [*]`
|
Crash --> [*]`
|
||||||
);
|
);
|
||||||
expect(classDiagram1.db).not.toBe(classDiagram2.db);
|
expect(classDiagram1.db).not.toBe(classDiagram2.db);
|
||||||
assert(classDiagram1.db instanceof StateDb);
|
assert(classDiagram1.db instanceof StateDB);
|
||||||
assert(classDiagram2.db instanceof StateDb);
|
assert(classDiagram2.db instanceof StateDB);
|
||||||
expect(classDiagram1.db.getDirection()).not.toEqual(classDiagram2.db.getDirection());
|
expect(classDiagram1.db.getDirection()).not.toEqual(classDiagram2.db.getDirection());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user