mirror of
https://github.com/chinchang/web-maker.git
synced 2025-05-05 10:05:18 +02:00
23 lines
607 B
JavaScript
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);
|
|
});
|
|
}
|
|
};
|