From a1a63f93e2c21fd710f4b14f6301df79b524edf1 Mon Sep 17 00:00:00 2001 From: SeanOMik Date: Sat, 30 May 2020 21:45:11 -0500 Subject: [PATCH] Fix having multiple listeners for the same event. --- src/eventhandler.nim | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/eventhandler.nim b/src/eventhandler.nim index 5f83178..659e2fc 100644 --- a/src/eventhandler.nim +++ b/src/eventhandler.nim @@ -14,8 +14,7 @@ let eventListeners = newTable[string, seq[proc(event: BaseEvent)]]() proc registerEventListener*(event: EventType, listener: proc(event: BaseEvent)) = if (eventListeners.hasKey($event)): - var listeners = eventListeners[$event] - listeners.add(cast[proc(event: BaseEvent)](listener)) + eventListeners[$event].add(cast[proc(event: BaseEvent)](listener)) echo "Added other event listener: ", $event else: @@ -25,12 +24,10 @@ proc registerEventListener*(event: EventType, listener: proc(event: BaseEvent)) echo "Added new event listener: ", $event proc dispatchEvent*[T: BaseEvent](event: T) = - #let base: BaseEvent = BaseEvent(event) - if (eventListeners.hasKey(event.name)): let listeners = eventListeners[event.name] + echo "Dispatching event: ", event.name for index, eventListener in listeners.pairs: - echo "Dispatching event: ", event.name eventListener(event) else: echo "No event listeners for event: ", event.name \ No newline at end of file