1
0
mirror of https://github.com/chinchang/web-maker.git synced 2025-07-09 08:02:24 +02:00
Files
php-web-maker/src/commandPaletteService.js
Kushagra Gour e39e284705 add ui events
2019-03-15 15:11:33 +05:30

23 lines
607 B
JavaScript

import { trackEvent } from './analytics';
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) {
trackEvent('ui', 'commandPaletteCommandSelected', eventName);
const callbacks = this.subscriptions[eventName] || [];
callbacks.forEach(callback => {
callback(...args);
});
}
};