Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit 8f21616

Browse files
committed
Make registering event handlers easier
1 parent 4f536d2 commit 8f21616

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/main/scala/org/codeoverflow/chatoverflow/requirement/impl/EventInputImpl.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,21 @@ abstract class EventInputImpl[T <: Event, C <: Connector](implicit ctc: ClassTag
2020

2121
protected val handlers: ListBuffer[EventHandler[_ <: T]] = ListBuffer[EventHandler[_ <: T]]()
2222

23+
/**
24+
* Register a new event handler that listens for a specific event
25+
*
26+
* @param eventHandler consumer for which `accept()` is called if the event is fired
27+
* @param eventClass class of the events for which this listener should listen
28+
*/
2329
override def registerEventHandler[S <: T](eventHandler: Consumer[S], eventClass: Class[S]): Unit = {
2430
handlers += EventHandler[S](eventHandler, eventClass)
2531
}
2632

33+
/**
34+
* Use this methods to fire an event.
35+
* All eventHandlers listening for that event will be triggered.
36+
* @param event the event that should be fired
37+
*/
2738
protected def call[S <: T](event: S)(implicit cts: ClassTag[S]): Unit = {
2839
handlers.filter(handler => handler.clazz == cts.runtimeClass)
2940
.foreach(handler => handler.consumer.asInstanceOf[Consumer[S]].accept(event))

0 commit comments

Comments
 (0)