2013-10-17 15:38:47 +00:00
|
|
|
function Spy() {
|
|
|
|
}
|
|
|
|
|
|
|
|
Spy.prototype.boot = function () {
|
|
|
|
World.updateRoutes([sub(__, 0, 1000), pub(__, 0, 1000)]);
|
|
|
|
};
|
|
|
|
|
|
|
|
Spy.prototype.handleEvent = function (e) {
|
|
|
|
console.log("SPY", e);
|
|
|
|
};
|
|
|
|
|
2013-10-22 18:14:51 +00:00
|
|
|
function JQueryEventRouter(selector, eventName) {
|
|
|
|
var self = this;
|
|
|
|
this.selector = selector;
|
|
|
|
this.eventName = eventName;
|
|
|
|
this.handler =
|
|
|
|
World.wrap(function (e) { World.send(["jQuery", self.selector, self.eventName, e]); });
|
|
|
|
$(this.selector).on(this.eventName, this.handler);
|
2013-10-17 15:38:47 +00:00
|
|
|
}
|
|
|
|
|
2013-10-22 18:14:51 +00:00
|
|
|
JQueryEventRouter.prototype.handleEvent = function (e) {
|
|
|
|
if (e.type === "routes" && e.routes.length === 0) {
|
|
|
|
$(this.selector).off(this.eventName, this.handler);
|
|
|
|
World.exit();
|
2013-10-17 15:38:47 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-10-30 13:13:03 +00:00
|
|
|
function spawnJQueryDriver() {
|
|
|
|
var d = new DemandMatcher(["jQuery", __, __, __]);
|
|
|
|
d.onDemandIncrease = function (r) {
|
2013-10-22 18:14:51 +00:00
|
|
|
var selector = r.pattern[1];
|
|
|
|
var eventName = r.pattern[2];
|
|
|
|
World.spawn(new JQueryEventRouter(selector, eventName),
|
|
|
|
[pub(["jQuery", selector, eventName, __]),
|
|
|
|
pub(["jQuery", selector, eventName, __], 0, 1)]);
|
2013-10-30 13:13:03 +00:00
|
|
|
};
|
|
|
|
World.spawn(d);
|
2013-10-22 18:14:51 +00:00
|
|
|
}
|
|
|
|
|
2013-10-17 14:50:51 +00:00
|
|
|
var g = new Ground(function () {
|
2013-10-18 08:58:08 +00:00
|
|
|
console.log('starting ground boot');
|
2013-10-17 15:38:47 +00:00
|
|
|
World.spawn(new Spy());
|
2013-10-30 13:13:03 +00:00
|
|
|
spawnJQueryDriver();
|
2013-10-17 14:50:51 +00:00
|
|
|
World.spawn({
|
2013-10-22 18:14:51 +00:00
|
|
|
// step: function () { console.log('dummy step'); },
|
2013-10-17 14:50:51 +00:00
|
|
|
boot: function () {
|
2013-10-17 15:38:47 +00:00
|
|
|
console.log('dummy boot');
|
2013-10-22 18:14:51 +00:00
|
|
|
World.updateRoutes([sub(["jQuery", "#testButton", "click", __]),
|
|
|
|
sub(["jQuery", "#testButton2", "click", __]),
|
|
|
|
sub(__, 1)]);
|
2013-10-17 14:50:51 +00:00
|
|
|
World.send({msg: 'hello outer world'}, 1);
|
|
|
|
World.send({msg: 'hello inner world'}, 0);
|
2013-10-26 17:36:58 +00:00
|
|
|
// World.spawn(new World(function () {
|
|
|
|
// World.spawn({
|
|
|
|
// boot: function () {
|
|
|
|
// console.log('w1p1');
|
|
|
|
// World.updateRoutes([sub('w1p1')]);
|
|
|
|
// },
|
|
|
|
// handleEvent: function (e) { console.log('w1p1', e); }
|
|
|
|
// })
|
|
|
|
// }))
|
|
|
|
// World.spawn(new World(function () {
|
|
|
|
// World.spawn({
|
|
|
|
// boot: function () {
|
|
|
|
// console.log('w2p2');
|
|
|
|
// World.updateRoutes([sub('w2p2')]);
|
|
|
|
// },
|
|
|
|
// handleEvent: function (e) { console.log('w2p2', e); }
|
|
|
|
// })
|
|
|
|
// }));
|
2013-10-17 14:50:51 +00:00
|
|
|
},
|
|
|
|
handleEvent: function (e) {
|
2013-10-30 15:50:05 +00:00
|
|
|
if (e.type === "message" && e.message[0] === "jQuery") {
|
2013-10-22 18:14:51 +00:00
|
|
|
if (e.message[1] === "#testButton") {
|
|
|
|
console.log("got a click");
|
|
|
|
World.updateRoutes([sub(["jQuery", "#testButton2", "click", __])]);
|
|
|
|
} else {
|
|
|
|
console.log("got a click 2");
|
|
|
|
// World.exit();
|
|
|
|
}
|
2013-10-18 08:58:08 +00:00
|
|
|
}
|
2013-10-17 14:50:51 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
g.startStepping();
|