From de6f0a2945f4fdfb3fdee75c0e20c863a356ff90 Mon Sep 17 00:00:00 2001 From: Lucas Holmquist Date: Wed, 15 Jul 2020 09:50:46 -0400 Subject: [PATCH] docs(README): Update readme to mention that CloudEvents are read-only now (#248) * also update readme with a mention about the cloneWith method Signed-off-by: Lucas Holmquist --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index c610a3c..e9afbba 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,22 @@ emitter.send(new CloudEvent({ specversion: Version.V03, source, type })) }).catch(console.error); ``` +## 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: + +```js +const { + CloudEvent, +} = require("cloudevents-sdk"); + +// Create a new CloudEvent +const ce = new CloudEvent({...}); + +// Add a new extension to an existing CloudEvent +const ce2 = ce.cloneWith({extension: "Value"}); +``` + ### Example Applications There are a few trivial example applications in