chore: Editor refactor (#3286)
* cleanup * add context * EventEmitter allows removal of toolbar props from extensions * Move to 'packages' of extensions Remove EmojiTrigger extension * types * iteration * fix render flashing * fix: Missing nodes in collection descriptions
This commit is contained in:
29
shared/utils/events.ts
Normal file
29
shared/utils/events.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* A tiny EventEmitter implementation for the browser.
|
||||
*/
|
||||
export default class EventEmitter {
|
||||
private listeners: { [name: string]: ((data: any) => unknown)[] } = {};
|
||||
|
||||
public addListener(name: string, callback: (data: any) => unknown) {
|
||||
if (!this.listeners[name]) {
|
||||
this.listeners[name] = [];
|
||||
}
|
||||
|
||||
this.listeners[name].push(callback);
|
||||
}
|
||||
|
||||
public removeListener(name: string, callback: (data: any) => unknown) {
|
||||
this.listeners[name] = this.listeners[name]?.filter(
|
||||
(cb) => cb !== callback
|
||||
);
|
||||
}
|
||||
|
||||
public on = this.addListener;
|
||||
public off = this.removeListener;
|
||||
|
||||
public emit(name: string, data?: any) {
|
||||
this.listeners[name]?.forEach((callback) => {
|
||||
callback(data);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user