Files
pgadmin4/web/pgadmin/static/js/helpers/EventBus.js
Aditya Toshniwal b5b9ee46a1 1) Port query tool to React. Fixes #6131
2) Added status bar to the Query Tool. Fixes #3253
3) Ensure that row numbers should be visible in view when scrolling horizontally. Fixes #3989
4) Allow removing a single query history. Refs #4113
5) Partially fixed Macros usability issues. Ref #6969
6) Fixed an issue where the Query tool opens on minimum size if the user opens multiple query tool Window quickly. Fixes #6725
7) Relocate GIS Viewer Button to the Left Side of the Results Table. Fixes #6830
8) Fixed an issue where the connection bar is not visible. Fixes #7188
9) Fixed an issue where an Empty message popup after running a query. Fixes #7260
10) Ensure that Autocomplete should work after changing the connection. Fixes #7262
11) Fixed an issue where the copy and paste row does not work if the first column contains no data. Fixes #7294
2022-04-07 17:36:56 +05:30

47 lines
1.2 KiB
JavaScript

import _ from 'lodash';
export default class EventBus {
constructor() {
this._eventListeners = [];
}
registerListener(event, callback, once=false) {
this._eventListeners = this._eventListeners || [];
this._eventListeners.push({
event: event,
callback: callback,
fired: once ? 'pending' : 'ignore',
});
}
deregisterListener(event, callback) {
if(callback) {
this._eventListeners = this._eventListeners.filter((e)=>{
if(e.event === event) {
return e.callback.toString()!=callback.toString();
}
return e.event!=event && e.callback.toString()!=callback.toString();
});
} else {
this._eventListeners = this._eventListeners.filter((e)=>e.event!=event);
}
}
fireEvent(event, ...args) {
let self = this;
Promise.resolve(0).then(()=>{
let allListeners = _.filter(this._eventListeners, (e)=>e.event==event);
if(allListeners) {
for(const listener of allListeners) {
Promise.resolve(0).then(()=>{
listener.callback(...args);
if(listener.fired == 'pending') {
self.deregisterListener(event, listener.callback);
}
});
}
}
});
}
}