1
0
mirror of https://github.com/chinchang/web-maker.git synced 2025-07-16 11:36:20 +02:00
Files
php-web-maker/src/commandPaletteService.js
Kushagra Gour 17850a15a4 eslint fixes
2018-11-15 19:41:03 +05:30

20 lines
500 B
JavaScript

export const commandPaletteService = {
subscriptions: {},
subscribe(eventName, callback) {
this.subscriptions[eventName] = this.subscriptions[eventName] || [];
this.subscriptions[eventName].push(callback);
return () => {
this.subscriptions[eventName].splice(
this.subscriptions[eventName].indexOf(callback),
1
);
};
},
publish(eventName, ...args) {
const callbacks = this.subscriptions[eventName] || [];
callbacks.forEach(callback => {
callback(...args);
});
}
};