Skip to content

Instantly share code, notes, and snippets.

@nimezhu
Last active October 3, 2019 11:16
Show Gist options
  • Save nimezhu/e7b2275849b0f1cab9d778e2f817b80e to your computer and use it in GitHub Desktop.
Save nimezhu/e7b2275849b0f1cab9d778e2f817b80e to your computer and use it in GitHub Desktop.
NB Dispatch Programmable Test
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>NB-Dispatch-Programmable</title>
<script src="https://vis.nucleome.org/static/lib/nb-dispatch.min.js"></script>
</head>
<body>
<div id = "name"></div>
<button id ="hello">Hello</button>
<button id="goodbye">Goodbye</button>
<div id="message">
MESSAGE
</div>
<script>
(function()
{
var chan = nb.dispatch("hello","goodbye")
chan.connect()
var id = Math.floor(Math.random()*1000)
document.getElementById("name").innerHTML = "My Id is "+id
document.getElementById("hello").onclick = function() {
chan.call("hello",this,{"id":id})
}
document.getElementById("goodbye").onclick = function() {
chan.call("goodbye",this,{"id":id})
}
chan.on("hello",function(d){
document.getElementById("message").innerHTML = "hello from" + d.id
})
chan.on("goodbye", function(d){
document.getElementById("message").innerHTML = "Goodby from" + d.id
})
})()
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment