Use PartialFunction.applyOrElse when dispatching

This commit is contained in:
Fingercomp 2025-08-13 22:44:46 +03:00
parent 22d854ed34
commit c789722d4c
No known key found for this signature in database
GPG Key ID: BBC71CEE45D86E37

View File

@ -2,10 +2,10 @@ package ocelot.desktop.ui.widget
import ocelot.desktop.ui.event.Event import ocelot.desktop.ui.event.Event
import scala.collection.mutable.ListBuffer import scala.collection.mutable.ArrayBuffer
class EventHandlers extends PartialFunction[Event, Unit] { class EventHandlers extends PartialFunction[Event, Unit] {
private val handlers = new ListBuffer[EventHandler] private val handlers = ArrayBuffer.empty[EventHandler]
def +=(handler: EventHandler): Unit = handlers += handler def +=(handler: EventHandler): Unit = handlers += handler
@ -19,9 +19,7 @@ class EventHandlers extends PartialFunction[Event, Unit] {
return return
} }
if (handler.isDefinedAt(event)) { handler.applyOrElse(event, (_: Event) => ())
handler(event)
}
} }
} }