335c0f200f
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.
31 lines
627 B
JavaScript
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; |