Skip to content

Commit 38952e9

Browse files
committed
squash: simplify the validate method if we are copying the complete object
Signed-off-by: Lucas Holmquist <[email protected]>
1 parent 1a3588e commit 38952e9

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

src/event/cloudevent.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,12 @@ export class CloudEvent implements CloudEventV1, CloudEventV03 {
107107
// value is the value on the right side of the equal sign
108108
set: function (obj, prop: string, value) {
109109
// Make a copy of the incoming Object, need to have all it's properties and such
110-
const updateObj = Object.create(obj);
110+
const updateObj: CloudEvent = Object.create(obj);
111111
// Update it with the new value
112112
updateObj[prop] = value;
113113

114114
// Validate the object
115-
obj.validate(updateObj);
116-
115+
updateObj.validate();
117116
// If we succeed, then Update the real object
118117
// Set the new value normally
119118
obj[prop] = value;
@@ -172,16 +171,12 @@ export class CloudEvent implements CloudEventV1, CloudEventV03 {
172171
* @throws if the CloudEvent does not conform to the schema
173172
* @return {boolean} true if this event is valid
174173
*/
175-
public validate(cloudEvent?: CloudEvent): boolean {
176-
if (!cloudEvent) {
177-
cloudEvent = this;
178-
}
179-
174+
public validate(): boolean {
180175
try {
181-
if (cloudEvent.specversion === Version.V1) {
182-
return validateV1(cloudEvent);
183-
} else if (cloudEvent.specversion === Version.V03) {
184-
return validateV03(cloudEvent);
176+
if (this.specversion === Version.V1) {
177+
return validateV1(this);
178+
} else if (this.specversion === Version.V03) {
179+
return validateV03(this);
185180
}
186181
throw new ValidationError("invalid payload");
187182
} catch (e) {

0 commit comments

Comments
 (0)