Switch to obviously-better approach to timeouts in routing-table widget

This commit is contained in:
Tony Garnock-Jones 2014-03-10 15:22:31 -04:00
parent 946e07fb5c
commit b8fd680a24
2 changed files with 14 additions and 13 deletions

View File

@ -95,7 +95,7 @@ $(document).ready(function () {
// World.spawn(new Spy());
spawnJQueryDriver();
spawnDOMDriver();
spawnRoutingTableWidget("#spy-holder", "spy", 1000);
spawnRoutingTableWidget("#spy-holder", "spy");
World.spawn(new WakeDetector());
var wsconn = new WebSocketConnection("broker", $("#wsurl").val(), true);

View File

@ -1,5 +1,4 @@
function spawnRoutingTableWidget(selector, fragmentClass, hysteresisDelay) {
hysteresisDelay = hysteresisDelay || 50;
function spawnRoutingTableWidget(selector, fragmentClass) {
function sortedBy(xs, f) {
var keys = [];
@ -88,18 +87,20 @@ function spawnRoutingTableWidget(selector, fragmentClass, hysteresisDelay) {
},
handleEvent: function (e) {
var self = this;
if (e.type === "routes") {
this.nextState = this.digestRoutes(e.routes);
if (!this.timer) {
var self = this;
this.timer = setTimeout(World.wrap(function () {
if (JSON.stringify(self.nextState) !== JSON.stringify(self.state)) {
self.state = self.nextState;
self.updateState();
}
self.timer = false;
}), hysteresisDelay);
self.nextState = self.digestRoutes(e.routes);
if (self.timer) {
clearTimeout(self.timer);
self.timer = false;
}
self.timer = setTimeout(World.wrap(function () {
if (JSON.stringify(self.nextState) !== JSON.stringify(self.state)) {
self.state = self.nextState;
self.updateState();
}
self.timer = false;
}), 50);
}
}
});