Skip to content

Instantly share code, notes, and snippets.

@limitedeternity
Created June 7, 2020 16:54
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 limitedeternity/fd22e79e0c6be08f07ce2619f6bfe781 to your computer and use it in GitHub Desktop.
Save limitedeternity/fd22e79e0c6be08f07ce2619f6bfe781 to your computer and use it in GitHub Desktop.
Channel4 example of infinite event handling
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