syndicate-2017/examples/smoketest/index.js

36 lines
792 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;
2016-05-12 01:03:50 +00:00
document.addEventListener('DOMContentLoaded', function () {
var Dataspace = Syndicate.Dataspace;
var sub = Syndicate.sub;
var __ = Syndicate.__;
var _$ = Syndicate._$;
2016-04-06 16:22:30 +00:00
2016-05-12 01:03:50 +00:00
G = new Syndicate.Ground(function () {
console.log('starting ground boot');
2016-04-06 16:22:30 +00:00
2016-05-12 01:03:50 +00:00
Dataspace.spawn({
counter: 0,
boot: function () {},
handleEvent: function (e) {},
step: function () {
Dataspace.send(beep(this.counter++));
return this.counter <= 10;
}
});
2016-04-06 16:22:30 +00:00
2016-05-12 01:03:50 +00:00
Dataspace.spawn({
boot: function () { return sub(beep.pattern); },
handleEvent: function (e) {
if (e.type === 'message') {
console.log("beep!", e.message[0]);
2016-04-06 16:22:30 +00:00
}
2016-05-12 01:03:50 +00:00
}
2016-04-06 16:22:30 +00:00
});
2016-05-12 01:03:50 +00:00
});
G.startStepping();
2016-04-06 16:22:30 +00:00
});