Skip to content

Commit

Permalink
fixup! refactor: use structuredClone for deep copying
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed Oct 4, 2023
1 parent 7b0b1f7 commit 33af731
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
7 changes: 3 additions & 4 deletions packages/core/src/consumed-thing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,9 @@ export default class ConsumedThing extends TD.Thing implements IConsumedThing {
this.properties = {};
this.actions = {};
this.events = {};
// Deep clone the Thing Model
// without functions or methods
const clonedModel = structuredClone(thingModel);
Object.assign(this, clonedModel);

const deepClonedModel = structuredClone(thingModel);
Object.assign(this, deepClonedModel);
this.extendInteractions();
}

Expand Down
7 changes: 3 additions & 4 deletions packages/core/src/exposed-thing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,9 @@ export default class ExposedThing extends TD.Thing implements WoT.ExposedThing {
this.properties = {};
this.actions = {};
this.events = {};
// Deep clone the Thing Model
// without functions or methods
const clonedModel = structuredClone(thingModel);
Object.assign(this, clonedModel);

const deepClonedModel = structuredClone(thingModel);
Object.assign(this, deepClonedModel);

// unset "@type":"tm:ThingModel" ?
// see https://github.com/eclipse-thingweb/node-wot/issues/426
Expand Down

0 comments on commit 33af731

Please sign in to comment.