1
0
mirror of https://github.com/chinchang/web-maker.git synced 2025-07-17 12:01:13 +02:00

Command pallete: first draft!

This commit is contained in:
Kushagra Gour
2018-10-23 19:56:33 +05:30
parent 03e8e3e463
commit 78468f8a5d
6 changed files with 197 additions and 1 deletions

View File

@@ -0,0 +1,29 @@
import { deferred } from './deferred';
import { log } from 'util';
export const SWITCH_FILE_EVENT = 'switchFileEvent';
export const OPEN_SAVED_CREATIONS_EVENT = 'openSavedCreationsEvent';
export const SAVE_EVENT = 'saveEvent';
export const commandPaletteService = {
subscriptions: {},
subscribe(eventName, callback) {
console.log('subscribed for ', eventName);
this.subscriptions[eventName] = this.subscriptions[eventName] || [];
this.subscriptions[eventName].push(callback);
return () => {
console.log('Unsubscribing ', eventName);
this.subscriptions[eventName].splice(
this.subscriptions[eventName].indexOf(callback),
1
);
};
},
publish(eventName, ...args) {
console.log('published ', eventName, args);
const callbacks = this.subscriptions[eventName] || [];
callbacks.forEach(callback => {
callback.apply(null, args);
});
}
};