1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-30 04:23:11 +03:00

Lexical: Added common events support

This commit is contained in:
Dan Brown
2024-07-23 15:35:18 +01:00
parent 2cab778f19
commit 76b0d2d5d8
5 changed files with 116 additions and 16 deletions

View File

@ -1,7 +1,7 @@
import {HttpError} from "./http";
export class EventManager {
protected listeners: Record<string, ((data: {}) => void)[]> = {};
protected listeners: Record<string, ((data: any) => void)[]> = {};
protected stack: {name: string, data: {}}[] = [];
/**
@ -19,7 +19,7 @@ export class EventManager {
/**
* Listen to a custom event and run the given callback when that event occurs.
*/
listen(eventName: string, callback: (data: {}) => void): void {
listen<T>(eventName: string, callback: (data: T) => void): void {
if (typeof this.listeners[eventName] === 'undefined') this.listeners[eventName] = [];
this.listeners[eventName].push(callback);
}