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:
29
src/commandPaletteService.js
Normal file
29
src/commandPaletteService.js
Normal 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);
|
||||
});
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user