Switch to obviously-better approach to timeouts in routing-table widget
This commit is contained in:
parent
946e07fb5c
commit
b8fd680a24
|
@ -95,7 +95,7 @@ $(document).ready(function () {
|
||||||
// World.spawn(new Spy());
|
// World.spawn(new Spy());
|
||||||
spawnJQueryDriver();
|
spawnJQueryDriver();
|
||||||
spawnDOMDriver();
|
spawnDOMDriver();
|
||||||
spawnRoutingTableWidget("#spy-holder", "spy", 1000);
|
spawnRoutingTableWidget("#spy-holder", "spy");
|
||||||
|
|
||||||
World.spawn(new WakeDetector());
|
World.spawn(new WakeDetector());
|
||||||
var wsconn = new WebSocketConnection("broker", $("#wsurl").val(), true);
|
var wsconn = new WebSocketConnection("broker", $("#wsurl").val(), true);
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
function spawnRoutingTableWidget(selector, fragmentClass, hysteresisDelay) {
|
function spawnRoutingTableWidget(selector, fragmentClass) {
|
||||||
hysteresisDelay = hysteresisDelay || 50;
|
|
||||||
|
|
||||||
function sortedBy(xs, f) {
|
function sortedBy(xs, f) {
|
||||||
var keys = [];
|
var keys = [];
|
||||||
|
@ -88,18 +87,20 @@ function spawnRoutingTableWidget(selector, fragmentClass, hysteresisDelay) {
|
||||||
},
|
},
|
||||||
|
|
||||||
handleEvent: function (e) {
|
handleEvent: function (e) {
|
||||||
|
var self = this;
|
||||||
if (e.type === "routes") {
|
if (e.type === "routes") {
|
||||||
this.nextState = this.digestRoutes(e.routes);
|
self.nextState = self.digestRoutes(e.routes);
|
||||||
if (!this.timer) {
|
if (self.timer) {
|
||||||
var self = this;
|
clearTimeout(self.timer);
|
||||||
this.timer = setTimeout(World.wrap(function () {
|
self.timer = false;
|
||||||
if (JSON.stringify(self.nextState) !== JSON.stringify(self.state)) {
|
|
||||||
self.state = self.nextState;
|
|
||||||
self.updateState();
|
|
||||||
}
|
|
||||||
self.timer = false;
|
|
||||||
}), hysteresisDelay);
|
|
||||||
}
|
}
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue