brotherton-erpnext/erpnext/public/js/hub/event_emitter.js
Faris Ansari 335c0f200f feat: custom cache invalidation for hub calls
In some cases, we know when to invalidate the cache.
This feature allows to do just that.
erpnext.hub namespace is now an EventEmitter instance.
2018-08-17 16:04:14 +05:30

31 lines
627 B
JavaScript

/**
* Simple EventEmitter which uses jQuery's event system
*/
class EventEmitter {
init() {
this.jq = jQuery(this);
}
trigger(evt, data) {
!this.jq && this.init();
this.jq.trigger(evt, data);
}
once(evt, handler) {
!this.jq && this.init();
this.jq.one(evt, (e, data) => handler(data));
}
on(evt, handler) {
!this.jq && this.init();
this.jq.bind(evt, (e, data) => handler(data));
}
off(evt, handler) {
!this.jq && this.init();
this.jq.unbind(evt, (e, data) => handler(data));
}
}
export default EventEmitter;