-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: added a chapter on how to emit an event (#8414)
- Loading branch information
1 parent
bb4f002
commit e7965db
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
www/apps/book/app/advanced-development/events-and-subscribers/emit-event/page.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
export const metadata = { | ||
title: `${pageNumber} Emit an Event`, | ||
} | ||
|
||
# {metadata.title} | ||
|
||
In this chapter, you'll learn how to emit an event in a workflow. | ||
|
||
## Emit Event Step | ||
|
||
Medusa provides an `emitEventStep` helper step in the `@medusajs/core-flows` package that emits an event. | ||
|
||
When you emit an event, you specify the event's name and data payload to pass with the event. | ||
|
||
For example: | ||
|
||
export const highlights = [ | ||
["13", "emitEventStep", "Emit an event."], | ||
["14", `"custom.created"`, "The name of the event to emit."], | ||
["15", "data", "The data payload to pass with the event."] | ||
] | ||
|
||
```ts highlights={highlights} | ||
import { | ||
createWorkflow | ||
} from "@medusajs/workflows-sdk" | ||
import { | ||
emitEventStep | ||
} from "@medusajs/core-flows" | ||
|
||
const helloWorldWorkflow = createWorkflow( | ||
"hello-world", | ||
() => { | ||
// ... | ||
|
||
emitEventStep({ | ||
eventName: "custom.created", | ||
data: { | ||
id: "123" | ||
} | ||
}) | ||
} | ||
) | ||
``` | ||
|
||
In this example, you emit the event `custom.created` and pass in the data payload an ID property. | ||
|
||
If you execute the workflow, the emit is emitted and any subscribers listening to the event are executed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters