1
0
mirror of https://github.com/chinchang/web-maker.git synced 2025-05-05 10:05:18 +02:00
php-web-maker/src/commandPaletteService.js
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);
});
}
};