Created
June 7, 2020 16:54
-
-
Save limitedeternity/fd22e79e0c6be08f07ce2619f6bfe781 to your computer and use it in GitHub Desktop.
Channel4 example of infinite event handling
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
function ButtonFactory() { | |
const channel = new Channel(); | |
function createConsumer() { | |
channel.take(console.log); | |
} | |
createConsumer(); | |
const button = document.createElement("button"); | |
button.onmouseover = function() { | |
channel.put("mouseover"); | |
createConsumer(); | |
} | |
button.onclick = function() { | |
channel.put("onclick"); | |
createConsumer(); | |
} | |
return button; | |
} | |
let button = ButtonFactory(); | |
button.innerText = "Button"; | |
document.body.appendChild(button); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment