WorkflowEvent
工作流事件<
Data,DebugLabel> =object&object
表示一种工作流事件类型,可通过数据实例化。
事件是工作流的核心构建块。它们定义了流经系统的数据结构,并可用于触发处理器。
optional调试标签:DebugLabel
用于调试和日志记录目的的可选标签。
uniqueId
Section titled “uniqueId”
readonly唯一标识符:string
事件类型的唯一标识符,用于序列化和网络通信。
with()
Section titled “with()”使用(
data):WorkflowEventData<Data,DebugLabel>
使用提供的有效载荷创建事件数据。
Data
此事件实例的数据载荷
WorkflowEventData<Data, DebugLabel>
可通过工作流上下文发送的事件数据
include()
Section titled “include()”include(
event):event is WorkflowEventData<Data, DebugLabel>
类型守卫,用于检查未知事件数据是否属于此事件类型。
unknown
未知事件数据待检查
event is WorkflowEventData<Data, DebugLabel>
如果事件数据属于此事件类型则为真
onInit()
Section titled “onInit()”onInit(
callback):Cleanup
注册一个回调函数,当此事件类型被实例化时调用。
Callback
事件创建时调用的函数
Cleanup
用于移除回调的清理函数
[opaqueSymbol]
Section titled “[opaqueSymbol]”
readonly[不透明符号]:DebugLabel
Data
此事件可携带的数据类型
DebugLabel
Section titled “DebugLabel”DebugLabel 扩展 string = string
用于开发/调试的可选调试标签
// Create an event typeconst UserLoginEvent = workflowEvent<\{ userId: string; timestamp: Date \}>();
// Create event dataconst loginData = UserLoginEvent.with(\{ userId: 'user123', timestamp: new Date()\});
// Check if data belongs to this event typeif (UserLoginEvent.include(someEventData)) \{ console.log('User ID:', someEventData.data.userId);\}