-
-
Save nb1page/6f064239977d33d54f8f9bae5a6c6001 to your computer and use it in GitHub Desktop.
NB-Dispatch Programmable Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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