Skip to content

Instantly share code, notes, and snippets.

@hcarvalhoalves
Created October 18, 2016 21:45
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 hcarvalhoalves/822d25a003e76dadab997e1fcc3f16c2 to your computer and use it in GitHub Desktop.
Save hcarvalhoalves/822d25a003e76dadab997e1fcc3f16c2 to your computer and use it in GitHub Desktop.
// Uses https://github.com/krasimir/EventBus
var app = (function (document, bus) {
function appInit(event, appstate) {
var response = prompt("Foo?");
if (response == "foo") {
bus.dispatch("render", this, {"status": "ok"});
} else {
bus.dispatch("render", this, {"status": "errou-mane"});
}
}
function foo(event, appstate) {
console.log(event, appstate);
}
function render(event, appstate) {
document.getElementById("status").innerHTML = '<button id="foo">' + appstate["status"] + '</button>';
document.getElementById("foo").onclick = (function(ev) {
bus.dispatch("foo", this, Object.assign(appstate, {"foo": appstate["status"]}));
}).bind(this);
}
bus.addEventListener("init", appInit);
bus.addEventListener("render", render);
bus.addEventListener("foo", foo);
return bus;
});
app(document, EventBus).dispatch("init", this, {});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment