Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use structuredClone for deep copying #1105

Merged
merged 3 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
danielpeintner marked this conversation as resolved.
Show resolved Hide resolved
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);
danielpeintner marked this conversation as resolved.
Show resolved Hide resolved
Object.assign(this, clonedModel);

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