abstract struct Athena::EventDispatcher::Callable
- Athena::EventDispatcher::Callable
- Struct
- Value
- Object
Overview
Encapsulates everything required to represent an event listener. Including what event is being listened on, the callback itself, and its priority.
Each subclass represents a specific "type" of listener. See each subclass for more information.
TIP: These types can be manually instantiated and added via the related AED::EventDispatcherInterface#listener(callable)
overload.
This can be useful as a point of integration to other libraries, such as lazily instantiating listener instances.
Name
Each callable also has an optional name that can be useful for debugging to allow identifying a specific callable since there would be no way to tell apart two listeners on the same event, with the same priority.
class MyEvent < AED::Event; end
dispatcher = AED::EventDispatcher.new
dispatcher.listener(MyEvent) { }
dispatcher.listener(MyEvent, name: "block-listener") { }
class MyListener
@[AEDA::AsEventListener]
def on_my_event(event : MyEvent) : Nil
end
end
dispatcher.listener MyListener.new
dispatcher.listeners(MyEvent).map &.name # => ["unknown callable", "block-listener", "MyListener#on_my_event"]
AED::Callable::EventListenerInstance
instances registered via AED::EventDispatcherInterface#listener(listener)
will automatically have a name including the
method and listener class names in the format of ClassName#method_name
.
Included Modules
- Comparable(Athena::EventDispatcher::Callable)
Direct Known Subclasses
- Athena::EventDispatcher::Callable::Event(E)
- Athena::EventDispatcher::Callable::EventDispatcher(E)
- Athena::EventDispatcher::Callable::EventListenerInstance(I, E)
Defined in:
callable.crConstructors
Instance Method Summary
-
#event_class : AED::Event.class
Returns what
AED::Event
class this callable represents. -
#name : String
Returns the name of this callable.
-
#priority : Int32
Returns the [listener priority][Athena::EventDispatcher::EventDispatcherInterface--listener-priority] of this callable.
Constructor Detail
Instance Method Detail
Returns what AED::Event
class this callable represents.
Returns the name of this callable.
Useful for debugging to identify a specific callable added from a block, or which method an AED::Callable::EventListenerInstance
is associated with.
Returns the [listener priority][Athena::EventDispatcher::EventDispatcherInterface--listener-priority] of this callable.