Convert DOM and smoketest examples to actor.js
This commit is contained in:
parent
95a4bc3c93
commit
55c9fa1d49
|
@ -0,0 +1,27 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>JS Marketplace: DOM Example</title>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<link href="../../third-party/bootstrap/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<link href="../../third-party/bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet">
|
||||||
|
<script src="../../third-party/jquery-2.0.3.min.js"></script>
|
||||||
|
<script src="../../dist/minimart.js"></script>
|
||||||
|
<script src="index.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>DOM example</h1>
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="row-fluid">
|
||||||
|
<div class="span3 well" id="counter-holder">
|
||||||
|
</div>
|
||||||
|
<div class="span9 well" id="clicker-holder">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row-fluid">
|
||||||
|
<div class="span12" id="spy-holder">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,46 @@
|
||||||
|
var G;
|
||||||
|
$(document).ready(function () {
|
||||||
|
var World = Minimart.World;
|
||||||
|
var sub = Minimart.sub;
|
||||||
|
var pub = Minimart.pub;
|
||||||
|
var __ = Minimart.__;
|
||||||
|
var _$ = Minimart._$;
|
||||||
|
|
||||||
|
G = new Minimart.Ground(function () {
|
||||||
|
console.log('starting ground boot');
|
||||||
|
// World.spawn(new Spy("GROUND", true));
|
||||||
|
Minimart.DOM.spawnDOMDriver();
|
||||||
|
Minimart.RoutingTableWidget.spawnRoutingTableWidget("#spy-holder", "spy");
|
||||||
|
|
||||||
|
World.spawn({
|
||||||
|
handleEvent: function (e) {
|
||||||
|
if (e.type === "message" && e.message[0] === "jQuery") {
|
||||||
|
World.send("bump_count");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [pub(["DOM", "#clicker-holder", "clicker",
|
||||||
|
["button", ["span", [["style", "font-style: italic"]], "Click me!"]]]),
|
||||||
|
pub("bump_count"),
|
||||||
|
sub(["jQuery", "button.clicker", "click", __])]);
|
||||||
|
|
||||||
|
World.spawn({
|
||||||
|
counter: 0,
|
||||||
|
boot: function () {
|
||||||
|
this.updateState();
|
||||||
|
},
|
||||||
|
updateState: function () {
|
||||||
|
World.updateRoutes([sub("bump_count"),
|
||||||
|
pub(["DOM", "#counter-holder", "counter",
|
||||||
|
["div",
|
||||||
|
["p", "The current count is: ", this.counter]]])]);
|
||||||
|
},
|
||||||
|
handleEvent: function (e) {
|
||||||
|
if (e.type === "message" && e.message === "bump_count") {
|
||||||
|
this.counter++;
|
||||||
|
this.updateState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
G.startStepping();
|
||||||
|
});
|
|
@ -5,7 +5,6 @@
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<link href="../../third-party/bootstrap/css/bootstrap.min.css" rel="stylesheet">
|
<link href="../../third-party/bootstrap/css/bootstrap.min.css" rel="stylesheet">
|
||||||
<link href="../../third-party/bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet">
|
<link href="../../third-party/bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet">
|
||||||
<link href="style.css" rel="stylesheet">
|
|
||||||
<script src="../../third-party/jquery-2.0.3.min.js"></script>
|
<script src="../../third-party/jquery-2.0.3.min.js"></script>
|
||||||
<script src="../../dist/minimart.js"></script>
|
<script src="../../dist/minimart.js"></script>
|
||||||
<script src="index.js"></script>
|
<script src="index.js"></script>
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
var G;
|
var G;
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
var World = Minimart.World;
|
var World = Minimart.World;
|
||||||
|
var Actor = Minimart.Actor;
|
||||||
var sub = Minimart.sub;
|
var sub = Minimart.sub;
|
||||||
var pub = Minimart.pub;
|
var pub = Minimart.pub;
|
||||||
var __ = Minimart.__;
|
var __ = Minimart.__;
|
||||||
|
@ -12,35 +13,39 @@ $(document).ready(function () {
|
||||||
Minimart.DOM.spawnDOMDriver();
|
Minimart.DOM.spawnDOMDriver();
|
||||||
Minimart.RoutingTableWidget.spawnRoutingTableWidget("#spy-holder", "spy");
|
Minimart.RoutingTableWidget.spawnRoutingTableWidget("#spy-holder", "spy");
|
||||||
|
|
||||||
World.spawn({
|
World.spawn(new Actor(function () {
|
||||||
handleEvent: function (e) {
|
Actor.subscribe(
|
||||||
if (e.type === "message" && e.message[0] === "jQuery") {
|
function () { return ["jQuery", "button.clicker", "click", __]; },
|
||||||
|
function () {
|
||||||
World.send("bump_count");
|
World.send("bump_count");
|
||||||
}
|
});
|
||||||
}
|
|
||||||
}, [pub(["DOM", "#clicker-holder", "clicker",
|
|
||||||
["button", ["span", [["style", "font-style: italic"]], "Click me!"]]]),
|
|
||||||
pub("bump_count"),
|
|
||||||
sub(["jQuery", "button.clicker", "click", __])]);
|
|
||||||
|
|
||||||
World.spawn({
|
Actor.advertise(
|
||||||
counter: 0,
|
function () { return "bump_count"; });
|
||||||
boot: function () {
|
Actor.advertise(
|
||||||
this.updateState();
|
function () {
|
||||||
},
|
return ["DOM", "#clicker-holder", "clicker",
|
||||||
updateState: function () {
|
["button", ["span", [["style", "font-style: italic"]], "Click me!"]]];
|
||||||
World.updateRoutes([sub("bump_count"),
|
});
|
||||||
pub(["DOM", "#counter-holder", "counter",
|
}));
|
||||||
["div",
|
|
||||||
["p", "The current count is: ", this.counter]]])]);
|
World.spawn(new Actor(function () {
|
||||||
},
|
this.counter = 0;
|
||||||
handleEvent: function (e) {
|
|
||||||
if (e.type === "message" && e.message === "bump_count") {
|
Actor.subscribe(
|
||||||
|
function () { return "bump_count"; },
|
||||||
|
function () {
|
||||||
this.counter++;
|
this.counter++;
|
||||||
this.updateState();
|
this.updateRoutes();
|
||||||
}
|
});
|
||||||
}
|
|
||||||
});
|
Actor.advertise(
|
||||||
|
function () {
|
||||||
|
return ["DOM", "#counter-holder", "counter",
|
||||||
|
["div",
|
||||||
|
["p", "The current count is: ", this.counter]]];
|
||||||
|
});
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
G.startStepping();
|
G.startStepping();
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
var G;
|
var G;
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
var World = Minimart.World;
|
var World = Minimart.World;
|
||||||
|
var Actor = Minimart.Actor;
|
||||||
var sub = Minimart.sub;
|
var sub = Minimart.sub;
|
||||||
var pub = Minimart.pub;
|
var pub = Minimart.pub;
|
||||||
var __ = Minimart.__;
|
var __ = Minimart.__;
|
||||||
|
@ -9,22 +10,24 @@ $(document).ready(function () {
|
||||||
G = new Minimart.Ground(function () {
|
G = new Minimart.Ground(function () {
|
||||||
console.log('starting ground boot');
|
console.log('starting ground boot');
|
||||||
World.spawn(new Minimart.Spy("GROUND", true));
|
World.spawn(new Minimart.Spy("GROUND", true));
|
||||||
World.spawn({
|
|
||||||
counter: 0,
|
World.spawn(new Actor(function () {
|
||||||
handleEvent: function (e) {},
|
this.counter = 0;
|
||||||
step: function () {
|
this.step = function () {
|
||||||
World.send(["beep", this.counter++]);
|
World.send(["beep", this.counter++]);
|
||||||
return this.counter <= 10;
|
return this.counter <= 10;
|
||||||
}
|
};
|
||||||
}, [pub(["beep", __])]);
|
|
||||||
|
|
||||||
World.spawn({
|
Actor.advertise(function () { return ["beep", __]; });
|
||||||
handleEvent: function (e) {
|
}));
|
||||||
if (e.type === "message" && e.message[0] === "beep") {
|
|
||||||
console.log("beep!", e.message[1]);
|
World.spawn(new Actor(function () {
|
||||||
}
|
Actor.subscribe(
|
||||||
}
|
function () { return ["beep", _$("counter")]; },
|
||||||
}, [sub(["beep", __])]);
|
function (counter) {
|
||||||
|
console.log("beep!", counter);
|
||||||
|
});
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
G.startStepping();
|
G.startStepping();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue