]> BookStack Code Mirror - bookstack/blobdiff - resources/js/services/events.ts
Comments: Split out page comment reference logic to own component
[bookstack] / resources / js / services / events.ts
index be9fba7eca515cebd616c09acfd1995f916f65ec..7dae6dc29d96da23801f4c71d480d033e8612de1 100644 (file)
@@ -24,6 +24,17 @@ export class EventManager {
         this.listeners[eventName].push(callback);
     }
 
+    /**
+     * Remove an event listener which is using the given callback for the given event name.
+     */
+    remove(eventName: string, callback: Function): void {
+        const listeners = this.listeners[eventName] || [];
+        const index = listeners.indexOf(callback);
+        if (index !== -1) {
+            listeners.splice(index, 1);
+        }
+    }
+
     /**
      * Emit an event for public use.
      * Sends the event via the native DOM event handling system.