Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: added a chapter on how to emit an event #8414

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
4 changes: 4 additions & 0 deletions www/apps/book/sidebar.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ export const sidebar = sidebarAttachHrefCommonOptions(
path: "/advanced-development/events-and-subscribers/data-payload",
title: "Events Data Payload",
},
{
path: "/advanced-development/events-and-subscribers/emit-event",
title: "Emit an Event",
},
],
},
{
Expand Down
Loading