Commit ea7ba1f8 by Martin Kotula

use the bind function to pass context

parent 29eb2c3d
...@@ -37,21 +37,20 @@ define([ ...@@ -37,21 +37,20 @@ define([
} }
HomeViewModel.prototype.refresh = function () { HomeViewModel.prototype.refresh = function () {
var that = this;
this.isRefreshing(true); this.isRefreshing(true);
this.queryHandler.handle().then(function(data) { this.queryHandler.handle().then(_.bind(function(data) {
var sensorsGroupedByName = _.groupBy(data, "name") var sensorsGroupedByName = _.groupBy(data, "name");
_.each(sensorsGroupedByName, function(sensorReadings, key){ _.each(sensorsGroupedByName, _.bind(function(sensorReadings, key){
var latestReading = _.orderBy(sensorReadings, "timestamp").pop(); var latestReading = _.orderBy(sensorReadings, "timestamp").pop();
if(that.sensorsDict[key]){ if(this.sensorsDict[key]){
that.updateSensor(key, latestReading); this.updateSensor(key, latestReading);
} else { } else {
that.addSensor(key, latestReading); this.addSensor(key, latestReading);
} }
}) }, this));
that.isRefreshing(false); this.isRefreshing(false);
}) }, this));
} }
return { viewModel: HomeViewModel, template: homeTemplate }; return { viewModel: HomeViewModel, template: homeTemplate };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment