Skip to content

Commit f73ca97

Browse files
authored
docs: rename data to event in subscribers across docs (medusajs#8149)
1 parent f579f0b commit f73ca97

File tree

7 files changed

+38
-38
lines changed
  • www/apps
    • book/app
    • resources/app

7 files changed

+38
-38
lines changed

www/apps/book/app/advanced-development/events-and-subscribers/data-payload/page.mdx

+7-7
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ In this chapter, you'll learn how subscribers receive an event's data payload.
1212

1313
When events are emitted, they’re emitted with a data payload.
1414

15-
The object that the subscriber function receives as a parameter has a `data` property, which is an object holding the event payload with additional context.
15+
The object that the subscriber function receives as a parameter has an `event` property, which is an object holding the event payload in a `data` property with additional context.
1616

1717
For example:
1818

1919
export const highlights = [
20-
["7", "", "The event's data payload."],
20+
["7", "event", "The event details."],
2121
["8", "{ id: string }", "The type of expected data payloads."],
2222
]
2323

@@ -28,9 +28,9 @@ import type {
2828
} from "@medusajs/medusa"
2929

3030
export default async function productCreateHandler({
31-
data,
31+
event,
3232
}: SubscriberArgs<{ id: string }>) {
33-
const productId = data.data.id
33+
const productId = event.data.id
3434
console.log(`The product ${productId} was created`)
3535
}
3636

@@ -39,16 +39,16 @@ export const config: SubscriberConfig = {
3939
}
4040
```
4141

42-
The `data` object has the following properties:
42+
The `event` object has the following properties:
4343

4444
<TypeList types={[
4545
{
4646
name: "data",
4747
type: "`object`",
48-
description: "The data payload of the event. Its properties depend on the event."
48+
description: "The data payload of the event. Its properties are different for each event."
4949
},
5050
{
51-
name: "eventName",
51+
name: "name",
5252
type: "string",
5353
description: "The name of the triggered event."
5454
},

www/apps/book/app/basics/events-and-subscribers/page.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@ import { IProductModuleService } from "@medusajs/types"
9292
import { ModuleRegistrationName } from "@medusajs/utils"
9393

9494
export default async function productCreateHandler({
95-
data,
95+
event: { data },
9696
container,
9797
}: SubscriberArgs<{ id: string }>) {
9898
const productModuleService: IProductModuleService =
9999
container.resolve(ModuleRegistrationName.PRODUCT)
100100

101-
const productId = data.data.id
101+
const productId = data.id
102102

103103
const product = await productModuleService.retrieveProduct(
104104
productId

www/apps/book/app/basics/workflows/page.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ To execute the workflow, invoke it passing the Medusa container as a parameter.
130130
import { IUserModuleService } from "@medusajs/types"
131131

132132
export default async function handleCustomerCreate({
133-
data,
133+
event: { data },
134134
container,
135135
}: SubscriberArgs<{ id: string }>) {
136-
const userId = data.data.id
136+
const userId = data.id
137137
const userModuleService: IUserModuleService = container.resolve(
138138
ModuleRegistrationName.USER
139139
)

www/apps/resources/app/architectural-modules/notification/send-notification/page.mdx

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ In your resource, such as a subscriber, resolve the Notification Module's main s
1414

1515
export const highlights = [
1616
["12", "notificationModuleService", "Resolve the Notification Module."],
17-
["17", "create", "Create the notification to be sent."],
17+
["15", "create", "Create the notification to be sent."],
1818
[
19-
"19",
19+
"17",
2020
'"email"',
2121
"Use the module provider defined for the `email` channel to send an email.",
2222
],
2323
[
24-
"20",
24+
"18",
2525
'"product-created"',
2626
"The ID of the template defined in the third-party service, such as SendGrid.",
2727
],
2828
[
29-
"21",
29+
"19",
3030
"data",
3131
"The data to pass to the template defined in the third-party service.",
3232
],
@@ -41,7 +41,7 @@ import { ModuleRegistrationName } from "@medusajs/utils"
4141
import { INotificationModuleService } from "@medusajs/types"
4242

4343
export default async function productCreateHandler({
44-
data,
44+
event: { data },
4545
container,
4646
}: SubscriberArgs<{ id: string }>) {
4747
const notificationModuleService: INotificationModuleService =
@@ -51,7 +51,7 @@ export default async function productCreateHandler({
5151
to: "shahednasser@gmail.com",
5252
channel: "email",
5353
template: "product-created",
54-
data: data.data,
54+
data,
5555
})
5656
}
5757

www/apps/resources/app/architectural-modules/notification/sendgrid/page.mdx

+6-6
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,14 @@ To test the module out, create a simple subscriber at `src/subscribers/product-c
116116

117117
export const highlights = [
118118
["12", "notificationModuleService", "Resolve the Notification Module."],
119-
["17", "create", "Create the notification to be sent."],
119+
["15", "create", "Create the notification to be sent."],
120120
[
121-
"19",
121+
"17",
122122
'"email"',
123123
"By specifying the `email` channel, SendGrid will be used to send the notification.",
124124
],
125-
["20", '"product-created"', "The ID of the template defined in SendGrid."],
126-
["21", "data", "The data to pass to the template defined in SendGrid."],
125+
["18", '"product-created"', "The ID of the template defined in SendGrid."],
126+
["19", "data", "The data to pass to the template defined in SendGrid."],
127127
]
128128

129129
```ts title="src/subscribers/product-created.ts" highlights={highlights} collapsibleLines="1-7" expandButtonLabel="Show Imports"
@@ -135,7 +135,7 @@ import { ModuleRegistrationName } from "@medusajs/utils"
135135
import { INotificationModuleService } from "@medusajs/types"
136136

137137
export default async function productCreateHandler({
138-
data,
138+
event: { data },
139139
container,
140140
}: SubscriberArgs<{ id: string }>) {
141141
const notificationModuleService: INotificationModuleService =
@@ -145,7 +145,7 @@ export default async function productCreateHandler({
145145
to: "test@gmail.com",
146146
channel: "email",
147147
template: "product-created",
148-
data: data.data,
148+
data,
149149
})
150150
}
151151

www/apps/resources/app/recipes/commerce-automation/page.mdx

+12-13
Original file line numberDiff line numberDiff line change
@@ -795,10 +795,10 @@ The `order.placed` event is currently not emitted.
795795
} from "@medusajs/types"
796796

797797
export default async function orderCreatedHandler({
798-
data,
798+
event: { data },
799799
container,
800800
}: SubscriberArgs<{ id: string }>) {
801-
const orderId = data.data.id
801+
const orderId = data.id
802802

803803
const orderModuleService: IOrderModuleService = container
804804
.resolve(ModuleRegistrationName.ORDER)
@@ -886,15 +886,15 @@ You can also create a scheduled job that checks whether the number of new produc
886886
For example, create the file `src/subscribers/send-products-newsletter.ts` with the following content:
887887

888888
export const newsletterHighlights = [
889-
["33", "store", "Retrieve the first store in the application."],
890-
["35", "products", "Retrieve the products created since the last newsletter send date."],
891-
["41", "", "Check whether more than 10 products have been created before proceeding."],
892-
["45", "customers", "Retrieve all customers, assuming they're considered subscribed."],
893-
["47", "createNotifications", "Send a notification (newsletter) to each customer using the Notification Module."],
894-
["50", '"email"', "Send the notification through the email channel."],
895-
["51", '"newsletter_template"', "Specify the template name in the third-party service (for example, SendGrid)."],
896-
["53", "products", "Pass the created products to the template."],
897-
["58", "updateStores", "Update the store's `last_newsletter_send_date` property with the current date."]
889+
["32", "store", "Retrieve the first store in the application."],
890+
["34", "products", "Retrieve the products created since the last newsletter send date."],
891+
["40", "", "Check whether more than 10 products have been created before proceeding."],
892+
["44", "customers", "Retrieve all customers, assuming they're considered subscribed."],
893+
["46", "createNotifications", "Send a notification (newsletter) to each customer using the Notification Module."],
894+
["49", '"email"', "Send the notification through the email channel."],
895+
["50", '"newsletter_template"', "Specify the template name in the third-party service (for example, SendGrid)."],
896+
["52", "products", "Pass the created products to the template."],
897+
["57", "updateStores", "Update the store's `last_newsletter_send_date` property with the current date."]
898898
]
899899

900900
```ts title="src/subscribers/send-products-newsletter.ts" highlights={newsletterHighlights} collapsibleLines="1-14" expandButtonLabel="Show Imports"
@@ -913,7 +913,6 @@ export const newsletterHighlights = [
913913
} from "@medusajs/types"
914914

915915
export default async function productCreateHandler({
916-
data,
917916
container,
918917
}: SubscriberArgs<{ id: string }>) {
919918
const productModuleService: IProductModuleService =
@@ -926,7 +925,7 @@ export const newsletterHighlights = [
926925
container.resolve(ModuleRegistrationName.CUSTOMER)
927926

928927
const notificationModuleService:
929-
INotificationModuleService = container.resolve(
928+
INotificationModuleService = container.resolve(
930929
ModuleRegistrationName.NOTIFICATION
931930
)
932931

www/apps/resources/app/recipes/integrate-ecommerce-stack/page.mdx

+3-2
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,13 @@ export const workflowHighlights = [
264264
import createProductWorkflow from "../workflows/create-product"
265265

266266
export default async function handleProductUpdate({
267-
data, container
267+
event: { data },
268+
container
268269
}: SubscriberArgs<{id: string}>) {
269270
createProductWorkflow(container)
270271
.run({
271272
input: {
272-
productId: data.data.id
273+
productId: data.id
273274
}
274275
})
275276
.then(() => {

0 commit comments

Comments
 (0)