Skip to content

Instantly share code, notes, and snippets.

@carlosvillu
Last active August 29, 2015 14:26
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 carlosvillu/fb260f62ff8a2c2d934f to your computer and use it in GitHub Desktop.
Save carlosvillu/fb260f62ff8a2c2d934f to your computer and use it in GitHub Desktop.
class BusEvents {
on(event, fn){}
emit(event, ...data){}
}
class JQueryBusEvents extends BusEvents{
constructor($=window.jQuery){
super();
this.$doc = $(document);
}
on(event, fn) {
this.$doc.on(event, fn)
}
emit(event, ...data){
this.$doc.trigger.apply(this.$doc, [event].concat(data));
}
}
window.bus = new JQueryBusEvents();
////// En la modal
window.bus.on('close-modal', function(){/*Aqui cierro la modal*/});
//// En otra parte de tu código
$('#button-id').on('click', function(){
window.bus.emit('close-modal');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment