Skip to content

Commit de6f0a2

Browse files
authored
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 <lholmqui@redhat.com>
1 parent 13bcdb4 commit de6f0a2

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,22 @@ emitter.send(new CloudEvent({ specversion: Version.V03, source, type }))
9494
}).catch(console.error);
9595
```
9696

97+
## CloudEvent Objects
98+
99+
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:
100+
101+
```js
102+
const {
103+
CloudEvent,
104+
} = require("cloudevents-sdk");
105+
106+
// Create a new CloudEvent
107+
const ce = new CloudEvent({...});
108+
109+
// Add a new extension to an existing CloudEvent
110+
const ce2 = ce.cloneWith({extension: "Value"});
111+
```
112+
97113
### Example Applications
98114

99115
There are a few trivial example applications in

0 commit comments

Comments
 (0)