Skip to content

Commit edb05bf

Browse files
committed
Added more code comments
1 parent c7b7efc commit edb05bf

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

examples/invocation/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ async function start() {
2222
CommunicationProtocolEnum.HTTP
2323
);
2424

25+
// Note that invoker listeners can be set up after startServer() has been called
2526
await server.startServer();
2627

2728
console.log("Setting up invocation endpoints")
28-
await server.invoker.listen("hello-world", async (data: any) => {
29+
await server.invoker.listen("hello-world", async (data: Record<string, any>) => {
30+
// Data is automatically parsed when received
2931
console.log(`Received: ${JSON.stringify(data.body)} on POST hello-world`);
3032
return { hello: "world received from POST" };
3133
}, { method: HttpMethod.POST });

examples/pubsub/src/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,16 @@ async function start() {
2222
);
2323

2424
// Initialize the subscription. Note that this must be done BEFORE calling .startServer()
25-
await server.pubsub.subscribe("my-pubsub-component", "my-topic", async (data: any) => {
25+
await server.pubsub.subscribe("my-pubsub-component", "my-topic", async (data: Record<string, any>) => {
26+
// The library parses JSON when possible.
2627
console.log(`[Dapr-JS][Example] Received on subscription: ${JSON.stringify(data)}`)
2728
});
2829
await server.startServer();
2930

3031
// Publish a message
3132
console.log("[Dapr-JS][Example] Publishing message")
33+
34+
// Internally, the message will be serialized using JSON.stringify()
3235
await client.pubsub.publish("my-pubsub-component", "my-topic", { hello: "world" });
3336
}
3437

0 commit comments

Comments
 (0)