Added single update

This commit is contained in:
kunkliricsi 2020-11-11 20:56:21 +01:00
parent f13133829a
commit c92808ac7d

View File

@ -26,12 +26,12 @@ export default class MapContainer extends Component {
handleAllDevicesUpdated(service = null) {
if (service === null) {
service = new DevicesService()
service = new DevicesService();
}
service.getall().then(result => {
this.setState({ devices: result })
this.setState({ devices: result });
}).catch(ex => {
console.log(ex)
console.log(ex);
});
}
@ -73,14 +73,13 @@ export default class MapContainer extends Component {
newConnection.on(update_method_name, (id) => {
service.getdevice(id).then(result => {
var index = this.state.devices.findIndex((d => d.id == id))
this.state.devices[index] = result;
}).catch(ex => {
console.log("Device update error", ex);
});
});
var index = this.state.devices.findIndex((d => d.id == id));
const newDevices = [...this.state.devices];
newDevices[index] = result;
this.setState({ devices: newDevices });
}).catch(ex => console.log("Device update failed.", ex));
})
.catch(e => console.log('Hub Connection failed: ', e));
}).catch(e => console.log('Hub Connection failed: ', e));
}
componentWillUnmount() {