Skip to content

Instantly share code, notes, and snippets.

@nb1page
Forked from nimezhu/index.html
Last active May 21, 2020 18:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nb1page/6f064239977d33d54f8f9bae5a6c6001 to your computer and use it in GitHub Desktop.
Save nb1page/6f064239977d33d54f8f9bae5a6c6001 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://unpkg.com/@nucleome/nb-dispatch"></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 = "Goodbye from " + d.id
})
})()
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment