Skip to content

Commit

Permalink
refactor: use structuredClone for deep coyping
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed Oct 2, 2023
1 parent 49ad831 commit 9ce7dc3
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/binding-http/src/http-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ export default class HttpServer implements ProtocolServer {
for (const inUri in this.urlRewrite) {
const toUri = this.urlRewrite[inUri];
if (form.href.endsWith(toUri)) {
const form2: TD.Form = JSON.parse(JSON.stringify(form)); // deep copy
const form2 = structuredClone(form);
form2.href = form2.href.substring(0, form.href.lastIndexOf(toUri)) + inUri;
forms.push(form2);
debug(`HttpServer on port ${this.getPort()} assigns urlRewrite '${form2.href}' for '${form.href}'`);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/consumed-thing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ export default class ConsumedThing extends TD.Thing implements IConsumedThing {
this.events = {};
// Deep clone the Thing Model
// without functions or methods
const clonedModel = JSON.parse(JSON.stringify(thingModel));
const clonedModel = structuredClone(thingModel);
Object.assign(this, clonedModel);
this.extendInteractions();
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/exposed-thing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default class ExposedThing extends TD.Thing implements WoT.ExposedThing {
this.events = {};
// Deep clone the Thing Model
// without functions or methods
const clonedModel = JSON.parse(JSON.stringify(thingModel));
const clonedModel = structuredClone(thingModel);
Object.assign(this, clonedModel);

// unset "@type":"tm:ThingModel" ?
Expand Down

0 comments on commit 9ce7dc3

Please sign in to comment.