Experimental display of current subscriptions
This commit is contained in:
parent
0273f2557e
commit
1aa0420048
|
@ -27,6 +27,10 @@
|
|||
<div class="span9 well" id="clicker-holder">
|
||||
</div>
|
||||
</div>
|
||||
<div class="row-fluid">
|
||||
<div class="span12" id="spy-holder">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,10 +1,77 @@
|
|||
function count_uniq(xs) {
|
||||
var r = [];
|
||||
if (xs.length === 0) return [];
|
||||
var last = xs[0];
|
||||
var count = 1;
|
||||
function fin() {
|
||||
r.push([count, last]);
|
||||
}
|
||||
for (var i = 1; i < xs.length; i++) {
|
||||
if (xs[i] === last) {
|
||||
count++;
|
||||
} else {
|
||||
fin();
|
||||
last = xs[i];
|
||||
count = 1;
|
||||
}
|
||||
}
|
||||
fin();
|
||||
return r;
|
||||
}
|
||||
|
||||
var G;
|
||||
$(document).ready(function () {
|
||||
G = new Ground(function () {
|
||||
console.log('starting ground boot');
|
||||
World.spawn(new Spy("GROUND", true));
|
||||
// World.spawn(new Spy("GROUND", true));
|
||||
spawnDOMDriver();
|
||||
|
||||
World.spawn({
|
||||
boot: function () { this.updateState(); },
|
||||
state: [],
|
||||
nextState: [],
|
||||
timer: false,
|
||||
digestRoutes: function (rs) {
|
||||
var s = [];
|
||||
for (var i = 0; i < rs.length; i++) {
|
||||
var p = rs[i].pattern;
|
||||
if (p[0] !== "DOM" || p[1] !== "#spy-holder" || p[2] !== "spy") {
|
||||
s.push(JSON.stringify([p,
|
||||
rs[i].isSubscription ? "sub" : "pub",
|
||||
rs[i].level]));
|
||||
}
|
||||
}
|
||||
s.sort();
|
||||
s = count_uniq(s);
|
||||
return s;
|
||||
},
|
||||
updateState: function () {
|
||||
var elts = ["ul"];
|
||||
for (var i = 0; i < this.state.length; i++) {
|
||||
var r = this.state[i];
|
||||
elts.push(["li", r[0], " × ", r[1]]);
|
||||
}
|
||||
World.updateRoutes([sub(__, 0, Infinity),
|
||||
pub(__, 0, Infinity),
|
||||
pub(["DOM", "#spy-holder", "spy", elts])]);
|
||||
},
|
||||
handleEvent: function (e) {
|
||||
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;
|
||||
}), 50);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
World.spawn({
|
||||
handleEvent: function (e) {
|
||||
if (e.type === "message" && e.message[0] === "jQuery") {
|
||||
|
|
Loading…
Reference in New Issue