Support Network onStateChange callback.

This commit is contained in:
Tony Garnock-Jones 2016-02-06 07:40:46 -05:00
parent d00d205314
commit f06d951dcb
3 changed files with 6 additions and 0 deletions

View File

@ -11,5 +11,6 @@
<h1>jQuery example</h1> <h1>jQuery example</h1>
<button id="clicker">Click me</button> <button id="clicker">Click me</button>
<div id="result">0</div> <div id="result">0</div>
<pre id="spy-holder"></pre>
</body> </body>
</html> </html>

View File

@ -24,5 +24,8 @@ $(document).ready(function () {
} }
}); });
}); });
G.network.onStateChange = function (mux, patch) {
$("#spy-holder").text(Syndicate.prettyTrie(mux.routingTable));
};
G.startStepping(); G.startStepping();
}); });

View File

@ -36,6 +36,7 @@ function Network(bootFn) {
this.processTable = Immutable.Map(); // pid -> Behavior this.processTable = Immutable.Map(); // pid -> Behavior
this.runnablePids = Immutable.Set(); // of pid this.runnablePids = Immutable.Set(); // of pid
this.mux = new Mux.Mux(); this.mux = new Mux.Mux();
this.onStateChange = function (mux, deltaAggregate) {};
this.asChild('meta', function () { return bootFn() }, true); this.asChild('meta', function () { return bootFn() }, true);
} }
@ -273,6 +274,7 @@ Network.prototype.deliverPatches = function (oldMux, updateStreamResult) {
self.deliverEvent(pid, stateChange(patch)); self.deliverEvent(pid, stateChange(patch));
}); });
events.metaEvents.forEach(Network.stateChange); events.metaEvents.forEach(Network.stateChange);
this.onStateChange(this.mux, updateStreamResult.deltaAggregate);
}; };
Network.prototype.deliverEvent = function (pid, event) { Network.prototype.deliverEvent = function (pid, event) {