Skip to content

Instantly share code, notes, and snippets.

@stevenhao
Created June 21, 2016 17:57
Show Gist options
  • Save stevenhao/83a834a7a22357b3437c73705a9bf2be to your computer and use it in GitHub Desktop.
Save stevenhao/83a834a7a22357b3437c73705a9bf2be to your computer and use it in GitHub Desktop.
print = console.log.bind(console);
err = console.error.bind(console);
function Dispatcher(name) {
function evtname(evt) {
return name + '.' + evt;
}
this.fire = function() {
evt = arguments[0];
args = Array.prototype.slice.call(arguments, 1);
print.apply(console, ['firing', evtname(evt)+'('].concat(args).concat(')'));
$(document).trigger(evtname(evt), args);
}
this.listen = function(evt, callback) {
$(document).on(evtname(evt), function() {
callback.apply(this, Array.prototype.slice.call(arguments, 1));
});
}
}
M = new Dispatcher('M');
V = new Dispatcher('V');
$(function() {
Controller.start();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment