Skip to content

Commit

Permalink
Fix issue where new properties were unusable. (#2435)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrstegeman committed Feb 14, 2020
1 parent ab8bb0d commit 573f5e9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
5 changes: 4 additions & 1 deletion static/js/models/gateway-model.js
Expand Up @@ -50,7 +50,10 @@ class GatewayModel extends Model {
}

setThing(thingId, description) {
if (!this.thingModels.has(thingId)) {
if (this.thingModels.has(thingId)) {
const thingModel = this.thingModels.get(thingId);
thingModel.updateFromDescription(description);
} else {
const thingModel = new ThingModel(description, this.ws);
thingModel.subscribe(
Constants.DELETE_THING,
Expand Down
19 changes: 12 additions & 7 deletions static/js/models/thing-model.js
Expand Up @@ -15,11 +15,22 @@ const Constants = require('../constants');
class ThingModel extends Model {
constructor(description, ws) {
super();
this.title = description.title;
this.properties = {};
this.events = [];
this.connected = false;

this.updateFromDescription(description);

this.initWebSocket(ws);

this.updateEvents();

return this;
}

updateFromDescription(description) {
this.title = description.title;

// Parse base URL of Thing
if (description.href) {
this.href = new URL(description.href, App.ORIGIN);
Expand Down Expand Up @@ -57,12 +68,6 @@ class ThingModel extends Model {
this.eventDescriptions[eventName] = event;
}
}

this.initWebSocket(ws);

this.updateEvents();

return this;
}

/**
Expand Down

0 comments on commit 573f5e9

Please sign in to comment.