From f2aafa787b6965e7aa57e27e3306c42adb4d26e7 Mon Sep 17 00:00:00 2001 From: Lucas Holmquist Date: Tue, 14 Jul 2020 14:07:57 -0400 Subject: [PATCH 1/3] chore(README): update readme with a mention about CloudEvents being read-only and the cloneWith method Signed-off-by: Lucas Holmquist --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.md b/README.md index c610a3ce..e3a7e751 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,23 @@ emitter.send(new CloudEvent({ specversion: Version.V03, source, type })) }).catch(console.error); ``` +#### Cloud Events + +All created `CloudEvent` objects are read-only. If you need to update a property or add a new extension to an existing cloud event object, you can use the `cloneWith` method. This will return a new `CloudEvent` with any update or new properties. For example: + +```js +const { + CloudEvent, +} = require("cloudevents-sdk"); + +// Create a new CloudEvent +const ce = new CloudEvent({.....}); + +// Add a new extension to an existing CloudEvent +ce = ce.cloneWith({extension: "Value"}); + +``` + ### Example Applications There are a few trivial example applications in From c84fbae13a8716676e445e03c6eba51de0fd1c19 Mon Sep 17 00:00:00 2001 From: Lucas Holmquist Date: Tue, 14 Jul 2020 21:49:44 -0400 Subject: [PATCH 2/3] squash: nits Signed-off-by: Lucas Holmquist --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e3a7e751..581b2f63 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ emitter.send(new CloudEvent({ specversion: Version.V03, source, type })) }).catch(console.error); ``` -#### Cloud Events +#### CloudEvents All created `CloudEvent` objects are read-only. If you need to update a property or add a new extension to an existing cloud event object, you can use the `cloneWith` method. This will return a new `CloudEvent` with any update or new properties. For example: @@ -104,10 +104,10 @@ const { } = require("cloudevents-sdk"); // Create a new CloudEvent -const ce = new CloudEvent({.....}); +const ce = new CloudEvent({...}); // Add a new extension to an existing CloudEvent -ce = ce.cloneWith({extension: "Value"}); +const ce2 = ce.cloneWith({extension: "Value"}); ``` From 82279f8941bcb6ac35ec916300512c6b06efb126 Mon Sep 17 00:00:00 2001 From: Lucas Holmquist Date: Wed, 15 Jul 2020 09:26:14 -0400 Subject: [PATCH 3/3] squash: address nits Signed-off-by: Lucas Holmquist --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 581b2f63..e9afbba7 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ emitter.send(new CloudEvent({ specversion: Version.V03, source, type })) }).catch(console.error); ``` -#### CloudEvents +## CloudEvent Objects All created `CloudEvent` objects are read-only. If you need to update a property or add a new extension to an existing cloud event object, you can use the `cloneWith` method. This will return a new `CloudEvent` with any update or new properties. For example: @@ -108,7 +108,6 @@ const ce = new CloudEvent({...}); // Add a new extension to an existing CloudEvent const ce2 = ce.cloneWith({extension: "Value"}); - ``` ### Example Applications