syndicate-2017/examples/smoketest/index.js

36 lines
758 B
JavaScript
Raw Normal View History

2016-04-06 16:22:30 +00:00
"use strict";
2016-05-10 04:44:02 +00:00
var beep = Syndicate.Struct.makeConstructor('beep', ['counter']);
2016-05-08 15:34:45 +00:00
2016-04-06 16:22:30 +00:00
var G;
$(document).ready(function () {
var Dataspace = Syndicate.Dataspace;
2016-04-06 16:22:30 +00:00
var sub = Syndicate.sub;
var __ = Syndicate.__;
var _$ = Syndicate._$;
G = new Syndicate.Ground(function () {
console.log('starting ground boot');
Dataspace.spawn({
2016-04-06 16:22:30 +00:00
counter: 0,
boot: function () {},
handleEvent: function (e) {},
step: function () {
2016-05-08 15:34:45 +00:00
Dataspace.send(beep(this.counter++));
2016-04-06 16:22:30 +00:00
return this.counter <= 10;
}
});
Dataspace.spawn({
2016-05-08 15:34:45 +00:00
boot: function () { return sub(beep.pattern); },
2016-04-06 16:22:30 +00:00
handleEvent: function (e) {
if (e.type === 'message') {
2016-05-10 04:44:02 +00:00
console.log("beep!", e.message[0]);
2016-04-06 16:22:30 +00:00
}
}
});
});
G.startStepping();
});