From 55c9fa1d499bbdff6b8b26ac1cd5e178d1f7859b Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Fri, 25 Jul 2014 16:20:53 -0700 Subject: [PATCH] Convert DOM and smoketest examples to actor.js --- examples/dom-raw/index.html | 27 ++++++++++++++++++ examples/dom-raw/index.js | 46 ++++++++++++++++++++++++++++++ examples/dom/index.html | 1 - examples/dom/index.js | 57 ++++++++++++++++++++----------------- examples/dom/style.css | 0 examples/smoketest/index.js | 29 ++++++++++--------- 6 files changed, 120 insertions(+), 40 deletions(-) create mode 100644 examples/dom-raw/index.html create mode 100644 examples/dom-raw/index.js delete mode 100644 examples/dom/style.css diff --git a/examples/dom-raw/index.html b/examples/dom-raw/index.html new file mode 100644 index 0000000..6fd18c4 --- /dev/null +++ b/examples/dom-raw/index.html @@ -0,0 +1,27 @@ + + + + JS Marketplace: DOM Example + + + + + + + + +

DOM example

+
+
+
+
+
+
+
+
+
+
+
+
+ + diff --git a/examples/dom-raw/index.js b/examples/dom-raw/index.js new file mode 100644 index 0000000..a797a34 --- /dev/null +++ b/examples/dom-raw/index.js @@ -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(); +}); diff --git a/examples/dom/index.html b/examples/dom/index.html index 5556bdf..6fd18c4 100644 --- a/examples/dom/index.html +++ b/examples/dom/index.html @@ -5,7 +5,6 @@ - diff --git a/examples/dom/index.js b/examples/dom/index.js index a797a34..a622f9e 100644 --- a/examples/dom/index.js +++ b/examples/dom/index.js @@ -1,6 +1,7 @@ var G; $(document).ready(function () { var World = Minimart.World; + var Actor = Minimart.Actor; var sub = Minimart.sub; var pub = Minimart.pub; var __ = Minimart.__; @@ -12,35 +13,39 @@ $(document).ready(function () { Minimart.DOM.spawnDOMDriver(); Minimart.RoutingTableWidget.spawnRoutingTableWidget("#spy-holder", "spy"); - World.spawn({ - handleEvent: function (e) { - if (e.type === "message" && e.message[0] === "jQuery") { + World.spawn(new Actor(function () { + Actor.subscribe( + function () { return ["jQuery", "button.clicker", "click", __]; }, + function () { 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") { + Actor.advertise( + function () { return "bump_count"; }); + Actor.advertise( + function () { + return ["DOM", "#clicker-holder", "clicker", + ["button", ["span", [["style", "font-style: italic"]], "Click me!"]]]; + }); + })); + + World.spawn(new Actor(function () { + this.counter = 0; + + Actor.subscribe( + function () { return "bump_count"; }, + function () { this.counter++; - this.updateState(); - } - } - }); + this.updateRoutes(); + }); + + Actor.advertise( + function () { + return ["DOM", "#counter-holder", "counter", + ["div", + ["p", "The current count is: ", this.counter]]]; + }); + })); }); G.startStepping(); }); diff --git a/examples/dom/style.css b/examples/dom/style.css deleted file mode 100644 index e69de29..0000000 diff --git a/examples/smoketest/index.js b/examples/smoketest/index.js index b0ee8aa..34c31e5 100644 --- a/examples/smoketest/index.js +++ b/examples/smoketest/index.js @@ -1,6 +1,7 @@ var G; $(document).ready(function () { var World = Minimart.World; + var Actor = Minimart.Actor; var sub = Minimart.sub; var pub = Minimart.pub; var __ = Minimart.__; @@ -9,22 +10,24 @@ $(document).ready(function () { G = new Minimart.Ground(function () { console.log('starting ground boot'); World.spawn(new Minimart.Spy("GROUND", true)); - World.spawn({ - counter: 0, - handleEvent: function (e) {}, - step: function () { + + World.spawn(new Actor(function () { + this.counter = 0; + this.step = function () { World.send(["beep", this.counter++]); return this.counter <= 10; - } - }, [pub(["beep", __])]); + }; - World.spawn({ - handleEvent: function (e) { - if (e.type === "message" && e.message[0] === "beep") { - console.log("beep!", e.message[1]); - } - } - }, [sub(["beep", __])]); + Actor.advertise(function () { return ["beep", __]; }); + })); + + World.spawn(new Actor(function () { + Actor.subscribe( + function () { return ["beep", _$("counter")]; }, + function (counter) { + console.log("beep!", counter); + }); + })); }); G.startStepping(); });