mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-11 19:39:43 +02:00
simplify message type from and to
This commit is contained in:
@@ -11,92 +11,7 @@ import {
|
|||||||
setDiagramTitle,
|
setDiagramTitle,
|
||||||
} from '../common/commonDb.js';
|
} from '../common/commonDb.js';
|
||||||
import { ImperativeState } from '../../utils/imperativeState.js';
|
import { ImperativeState } from '../../utils/imperativeState.js';
|
||||||
|
import type { Actor, AddMessageParams, Box, Message } from './types.js';
|
||||||
interface Box {
|
|
||||||
name: string;
|
|
||||||
wrap: boolean;
|
|
||||||
fill: string;
|
|
||||||
actorKeys: string[];
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Actor {
|
|
||||||
box?: Box;
|
|
||||||
name: string;
|
|
||||||
description: string;
|
|
||||||
wrap: boolean;
|
|
||||||
prevActor?: string;
|
|
||||||
nextActor?: string;
|
|
||||||
links: Record<string, unknown>;
|
|
||||||
properties: Record<string, unknown>;
|
|
||||||
actorCnt: number | null;
|
|
||||||
rectData: unknown;
|
|
||||||
type: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Message {
|
|
||||||
from?: { actor: string };
|
|
||||||
to?: { actor: string };
|
|
||||||
message:
|
|
||||||
| string
|
|
||||||
| {
|
|
||||||
start: number;
|
|
||||||
step: number;
|
|
||||||
visible: boolean;
|
|
||||||
};
|
|
||||||
wrap: boolean;
|
|
||||||
answer?: unknown;
|
|
||||||
type?: number;
|
|
||||||
activate?: boolean;
|
|
||||||
placement?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface AddMessageParams {
|
|
||||||
from: string;
|
|
||||||
to: string;
|
|
||||||
msg: string;
|
|
||||||
signalType: number;
|
|
||||||
type:
|
|
||||||
| 'addMessage'
|
|
||||||
| 'sequenceIndex'
|
|
||||||
| 'addParticipant'
|
|
||||||
| 'createParticipant'
|
|
||||||
| 'destroyParticipant'
|
|
||||||
| 'activeStart'
|
|
||||||
| 'activeEnd'
|
|
||||||
| 'addNote'
|
|
||||||
| 'addLinks'
|
|
||||||
| 'addALink'
|
|
||||||
| 'addProperties'
|
|
||||||
| 'addDetails'
|
|
||||||
| 'boxStart'
|
|
||||||
| 'boxEnd'
|
|
||||||
| 'loopStart'
|
|
||||||
| 'loopEnd'
|
|
||||||
| 'rectStart'
|
|
||||||
| 'rectEnd'
|
|
||||||
| 'optStart'
|
|
||||||
| 'optEnd'
|
|
||||||
| 'altStart'
|
|
||||||
| 'else'
|
|
||||||
| 'altEnd'
|
|
||||||
| 'setAccTitle'
|
|
||||||
| 'parStart'
|
|
||||||
| 'parAnd'
|
|
||||||
| 'parEnd'
|
|
||||||
| 'and'
|
|
||||||
| 'criticalStart'
|
|
||||||
| 'criticalOption'
|
|
||||||
| 'option'
|
|
||||||
| 'criticalEnd'
|
|
||||||
| 'breakStart'
|
|
||||||
| 'breakEnd'
|
|
||||||
| 'parOverStart'
|
|
||||||
| 'parOverEnd'
|
|
||||||
| 'parOverAnd'
|
|
||||||
| 'parOverEnd';
|
|
||||||
|
|
||||||
activate: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
type State = {
|
type State = {
|
||||||
prevActor?: string;
|
prevActor?: string;
|
||||||
@@ -204,13 +119,13 @@ const activationCount = (part: string) => {
|
|||||||
for (i = 0; i < state.records.messages.length; i++) {
|
for (i = 0; i < state.records.messages.length; i++) {
|
||||||
if (
|
if (
|
||||||
state.records.messages[i].type === LINETYPE.ACTIVE_START &&
|
state.records.messages[i].type === LINETYPE.ACTIVE_START &&
|
||||||
state.records.messages[i].from!.actor === part
|
state.records.messages[i].from === part
|
||||||
) {
|
) {
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
state.records.messages[i].type === LINETYPE.ACTIVE_END &&
|
state.records.messages[i].type === LINETYPE.ACTIVE_END &&
|
||||||
state.records.messages[i].from!.actor === part
|
state.records.messages[i].from === part
|
||||||
) {
|
) {
|
||||||
count--;
|
count--;
|
||||||
}
|
}
|
||||||
@@ -241,12 +156,10 @@ export const addSignal = function (
|
|||||||
activate: boolean = false
|
activate: boolean = false
|
||||||
) {
|
) {
|
||||||
if (messageType === LINETYPE.ACTIVE_END) {
|
if (messageType === LINETYPE.ACTIVE_END) {
|
||||||
const cnt = activationCount(idFrom?.actor || '');
|
const cnt = activationCount(idFrom || '');
|
||||||
if (cnt < 1) {
|
if (cnt < 1) {
|
||||||
// Bail out as there is an activation signal from an inactive participant
|
// Bail out as there is an activation signal from an inactive participant
|
||||||
const error = new Error(
|
const error = new Error('Trying to inactivate an inactive participant (' + idFrom + ')');
|
||||||
'Trying to inactivate an inactive participant (' + idFrom?.actor + ')'
|
|
||||||
);
|
|
||||||
|
|
||||||
// @ts-ignore: we are passing hash param to the error object, however we should define our own custom error class to make it type safe
|
// @ts-ignore: we are passing hash param to the error object, however we should define our own custom error class to make it type safe
|
||||||
error.hash = {
|
error.hash = {
|
||||||
|
@@ -20,8 +20,8 @@ export interface Actor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface Message {
|
export interface Message {
|
||||||
from?: { actor: string };
|
from?: string;
|
||||||
to?: { actor: string };
|
to?: string;
|
||||||
message:
|
message:
|
||||||
| string
|
| string
|
||||||
| {
|
| {
|
||||||
|
Reference in New Issue
Block a user