Skip to content

事件建模图 (v<MERMAID_RELEASE_VERSION>+)

🌐 Event Modeling Diagram (v<MERMAID_RELEASE_VERSION>+)

介绍

🌐 Introduction

事件建模 (EM) 是一种使用信息在系统内随时间变化的示例来描述系统的方法。事件建模特别省略瞬态细节,而是关注信息流是什么以及用户在任何特定时间点看到的内容。

你可以在 事件建模网页 上阅读更多内容。

🌐 You can read more at Event Modeling web page.

事件建模图由几个主要实体组成:

🌐 Event Modeling diagram is composed of a few main entities:

  • 触发器 - 屏幕和处理器
  • 命令
  • 查看 / 阅读模型
  • 事件

实体被组织在泳道中,形成时间轴,通常基于以下模式:

🌐 Entities are organized in swimlanes forming a timeline usually based on the following patterns:

  • 状态视图
  • 状态变化
  • 翻译
  • 自动化

你可以在备忘单中找到更多详细信息。

🌐 You can find more details in the cheat sheet.

支持绘制事件建模图的字段专用语言(DSL)的目的是快速创建。实体之间的关系默认会被推断,因此在设计过程中干扰很小。实体的进一步细节可以逐步添加。

🌐 The purpose of the Domain Specific Language (DSL) supporting the drawing of the Event Modeling diagram is the rapid creation. Relations among the entities are inferred by default, so the distraction while you design is limited. Further detail to the entities can be added gradually.

DSL 的语法也维护在一个单独的项目中,目的是提供不同类型的输出、VS Code(以及可能的其他)IDE 等。

🌐 The grammar for the DSL is also maintained in a separate project with the intention to provide also different types of output, VS Code (and potentially other) IDEs, etc.

基本语法

🌐 Basic Syntax

DSL支持两种语法——紧凑型和宽松型。在示例中都会提到这两种语法,而且两者可以互换使用。

🌐 The DSL supports two types of syntaxes - compact and relaxed one. Both will be mentioned in the examples and both can be used interchangeably.

时间线

🌐 Timeline

时间轴是图表的关键部分,它由时间框架定义组成。快速输入时间框架是紧凑符号的关键。对于紧凑符号,你输入 tf 令牌。对于宽松符号,你输入 timeframe 令牌。

🌐 The timeline is the key part of the diagram and it is composed of Time Frame definitions. Speedy Time Frame typing is the key of the compact notation. For compact notation you type the tf token. For the relaxed notation you type timeframe token.

md
eventmodeling

tf 01 scn CartScreen
tf 02 cmd AddItem
tf 03 evt ItemAdded

渲染为

🌐 rendering to

每个时间框架都通过一个唯一的数字来标识,以便区分彼此,同时在需要时可以引用它。根据图表的复杂性,两个数字可能就足够了,当然也可以更多。想象一下你在 ZX Spectrum 上编写 BASIC 程序时总是以两个数字开始,但数字的顺序无关紧要,只需在整个时间线上保持唯一性即可。

🌐 Each Time Frame is referenced by a unique number in order to distinguish one from another and also to be able to reference it when needed. Depending on the complexity of the diagram it should be enough to have just two digit number or more. Imagine you are typing a BASIC program on your ZX Spectrum always starting with a two digit number, but the order of the numbers does not matter, just the uniqueness in the whole timeline.

时间框架还包含一个实体标识符,例如在01时间框架中,它是CartScreen。同一个实体标识符可以在时间线上被多次使用,例如当你想在不同时间点表达同一事件的调用时。

🌐 The Time Frame also contains an Entity Identifier, e.g. in case of 01 Time Frame it is CartScreen. One Entity Identifier can be used multiple times in the timeline for example when you want to express invocations of the same event in different points in time.

放松的符号表示如下:

🌐 Relaxed notation would look like this:

md
eventmodeling

timeframe 01 screen CartScreen
timeframe 02 command AddItem
timeframe 03 event ItemAdded

内联数据

🌐 Inline data

可以为单个时间框提供数据示例。内联数据用大括号括起来,放在与时间框同一行上。

🌐 It is possible to provide data examples for individual Time Frames. An Inline Data is wrapped in curly brackets on the same line as the Time Frame.

简化版:

🌐 Compact version:

放松版:

🌐 Relaxed version:

数据块

🌐 Data block

如果你需要提供更复杂的数据描述,你可以单独定义 数据块。数据块可以通过在双中括号 [[identifier]] 内提供标识符来从时间框架中引用,这类似于 Markdown 中的 wiki 链接约定。

🌐 If you need to provide more complex data description, you can define the Data Block separately. Data Block is referenced from a Time Frame by providing the identifier inside of double-square brackets [[identifier]], similar to wiki links convention in Markdown.

如果同一实体重复出现,你需要唯一标识数据块,因此数据块标识符会加上一个数字后缀。

🌐 In case the same entity is repeated you need to uniquely identify the data blocks, therefore the Data Block identifier is suffixed with a number.

简化版:

🌐 Compact version:

放松版:

🌐 Relaxed version:

重置流程

🌐 Resetting the flow

默认情况下,图表会基于推断来建立关系。但是,建模更复杂的业务流程有时需要打破这种推断。为此,你可以使用一种称为重置时间框的不同类型时间框。它由 rf / resetframe 令牌表示。

🌐 By default the diagram builds the relations based on the inference. But modeling a more complex business flow requires to break such inference from time to time. For that you can use a different type of Time Frame called Reset Frame. It is represented by a rf / resetframe token.

简化版:

🌐 Compact version:

放松版:

🌐 Relaxed version:

多重关系

🌐 Multiple relations

有些情况下,你需要为一个实体指定多个关系。例如,当一个读取模型是由多个事件构建的时。你可以为此使用->>标记。

🌐 There are situations where you need to specify multiple relations for an entity. For example when a Read Model is built of multiple Events. You can use ->> token for that.

事件建模模式

🌐 Event Modeling patterns

本章简要总结了每个事件建模模式。

🌐 This chapter briefly summarizes each Event Modeling pattern.

状态变化

🌐 State Change

状态视图

🌐 State View

翻译

🌐 Translation

语法的详情

🌐 Details of the Syntax

实体类型

🌐 Entity types

实体类型由时间框架语法中的第三列决定。

🌐 Entity type is determined by the third column in the Time Frame grammar.

简化版:

🌐 Compact version:

md
tf 01 pcr InventoryProcessor

放松版:

🌐 Relaxed version:

md
timeframe 01 processor InventoryProcessor

除非在实体标识符中指定了命名空间,否则实体会被分配到默认的泳道。

🌐 Entities are assigned to default swimlanes unless a Namespace is specified in the Entity Identifier.

可用的类型如下:

🌐 There are the following types available:

  • scn / screen: Screen - 属于 UI/自动化工作流
  • pcr / processor: Processor - 属于 UI/自动化工作流
  • cmd / command: Command - 属于命令/读取模型泳道
  • rmo / readmodel: Read Model - 属于命令/读取模型泳道
  • evt / event: Event - 属于事件泳道

泳道和命名空间

🌐 Swimlanes and Namespaces

根据实体类型推断出三种基本的泳道

🌐 There are three basic Swimlanes inferred from the Entity Type.

  • 用户界面/自动化
  • 命令/读取模型
  • 事件

随着你的图表不断增长,并且你探索特定软件系统的深度,你也希望对你的实体进行分类。为了做到这一点,你可以将 Namespace 标识符作为实体标识符的一部分使用。

🌐 As your diagram grows and you explore the depths of a particular software system, you want to categorize your Entities as well. In order to do that, you can use Namespace identifier as part of the Entity Identifier.

md
Inventory.InventoryChanged

命名空间 是实体标识符中 . 之前的第一部分。命名空间和实体类型的每种组合都会形成新的泳道。它们在文本定义中指定的顺序决定了图中泳道的顺序。

数据块数据类型

🌐 Data block data types

数据 总是用大括号括起来。它可以在前面加上用反引号封装的数据类型。这个模式适用于 内联数据 以及 数据块

🌐 A Data is always wrapped in curly brackets. It can be prepended by a data type in backticks. The pattern applies for Inline Data as well as for Data Block.

md
tf 01 rmo UserAdded `json`{ "name": "foo" }

或用于数据块

🌐 or for Data Block

md
data UserAdded01 `json`{
"name": "foo"
}

警告

目前在图表渲染器中对于特定数据类型没有特殊处理。

支持的类型包括:

🌐 Supported types are:

  • json
  • jsobj
  • figma
  • salt
  • uri
  • md
  • html
  • text
Opens in mermaid.ai