diff --git a/js/examples/dom/index.js b/js/examples/dom/index.js index c66babe..0af4a3e 100644 --- a/js/examples/dom/index.js +++ b/js/examples/dom/index.js @@ -51,9 +51,9 @@ $(document).ready(function () { }); }); - G.dataspace.onStateChange = function (mux, patch) { + G.dataspace.setOnStateChange(function (mux, patch) { $("#spy-holder").text(Syndicate.prettyTrie(mux.routingTable)); - }; + }); G.startStepping(); }); diff --git a/js/examples/iot/index.js b/js/examples/iot/index.js index d1ddf1c..da01c5e 100644 --- a/js/examples/iot/index.js +++ b/js/examples/iot/index.js @@ -192,7 +192,7 @@ $(document).ready(function () { spawnChaosMonkey(); } - G.dataspace.onStateChange = function (mux, patch) { + G.dataspace.setOnStateChange(function (mux, patch) { $("#ds-state").text(Syndicate.prettyTrie(mux.routingTable)); - }; + }); }); diff --git a/js/examples/jquery/index.js b/js/examples/jquery/index.js index d65ab5a..41d24ea 100644 --- a/js/examples/jquery/index.js +++ b/js/examples/jquery/index.js @@ -27,8 +27,8 @@ $(document).ready(function () { } }); }); - G.dataspace.onStateChange = function (mux, patch) { + G.dataspace.setOnStateChange(function (mux, patch) { $("#spy-holder").text(Syndicate.prettyTrie(mux.routingTable)); - }; + }); G.startStepping(); }); diff --git a/js/examples/textfield-dsl/index.js b/js/examples/textfield-dsl/index.js index 4effb36..3f7ad36 100644 --- a/js/examples/textfield-dsl/index.js +++ b/js/examples/textfield-dsl/index.js @@ -163,7 +163,7 @@ $(document).ready(function () { spawnSearch(); } - G.dataspace.onStateChange = function (mux, patch) { + G.dataspace.setOnStateChange(function (mux, patch) { $("#spy-holder").text(Syndicate.prettyTrie(mux.routingTable)); - }; + }); }); diff --git a/js/examples/textfield/index.js b/js/examples/textfield/index.js index 261b08c..a29361b 100644 --- a/js/examples/textfield/index.js +++ b/js/examples/textfield/index.js @@ -203,9 +203,9 @@ $(document).ready(function () { spawnSearch(); }); - G.dataspace.onStateChange = function (mux, patch) { + G.dataspace.setOnStateChange(function (mux, patch) { $("#spy-holder").text(Syndicate.prettyTrie(mux.routingTable)); - }; + }); G.startStepping(); }); diff --git a/js/src/dataspace.js b/js/src/dataspace.js index bbe620e..3cf5e9e 100644 --- a/js/src/dataspace.js +++ b/js/src/dataspace.js @@ -287,6 +287,11 @@ Dataspace.prototype.deliverEvent = function (pid, event) { if (childBusy) this.markRunnable(pid); }; +Dataspace.prototype.setOnStateChange = function (handler) { + this.onStateChange = handler; + this.onStateChange(this.mux, Patch.emptyPatch); +}; + /////////////////////////////////////////////////////////////////////////// module.exports.stateChange = stateChange;