class Athena::EventDispatcher::EventDispatcher
- Athena::EventDispatcher::EventDispatcher
- Reference
- Object
Included Modules
Direct Known Subclasses
Defined in:
event_dispatcher.crConstructors
-
.new(listeners : Array(AED::EventListenerInterface))
Initializes
self
with the provided listeners. -
.new
Initializes
self
automatically via macros.
Instance Method Summary
-
#add_listener(event : AED::Event.class, listener : AED::EventListenerType, priority : Int32 = 0) : Nil
Adds the provided listener as a listener for event, optionally with the provided priority.
-
#dispatch(event : AED::Event) : Nil
Dispatches event to all listeners registered on
self
that are listening on that event. -
#has_listeners?(event : AED::Event.class | Nil = nil) : Bool
:inherit:
-
#listener_priority(event : AED::Event.class, listener : AED::EventListenerInterface.class) : Int32 | Nil
Returns the listener priority for the provided event.
-
#listeners(event : AED::Event.class | Nil = nil) : Array(AED::EventListener)
:inherit:
-
#remove_listener(event : AED::Event.class, listener : AED::EventListenerInterface.class) : Nil
Removes the provided event from the provided listener.
-
#remove_listener(event : AED::Event.class, listener : AED::EventListenerType) : Nil
Removes the provided event from the provided listener.
Instance methods inherited from module Athena::EventDispatcher::EventDispatcherInterface
add_listener(event : AED::Event.class, listener : AED::EventListenerType, priority : Int32) : Nil
add_listener,
dispatch(event : AED::Event) : Nil
dispatch,
has_listeners?(event : AED::Event.class | Nil) : Bool
has_listeners?,
listener_priority(event : AED::Event.class, listener : AED::EventListenerInterface.class) : Int32 | Nil
listener_priority,
listeners(event : AED::Event.class | Nil) : Array(AED::EventListener)
listeners,
remove_listener(event : AED::Event.class, listener : AED::EventListenerInterface.class) : Nilremove_listener(event : AED::Event.class, listener : AED::EventListenerType) : Nil remove_listener
Constructor Detail
Initializes self
with the provided listeners.
This overload is mainly intended for DI or to manually configure the listeners that should be listened on.
Initializes self
automatically via macros. This overload is mainly intended for
use cases where the listener types don't have any dependencies, and/or all listeners should listen.
Instance Method Detail
Adds the provided listener as a listener for event, optionally with the provided priority.
Dispatches event to all listeners registered on self
that are listening on that event.
AED::EventListenerInterface
's are executed based on the listener's priority; the higher the value the sooner it gets executed.
Returns the listener priority for the provided event. Returns nil
if no listeners are listening on the provided event or
if listener isn't listening on event.
:inherit:
Removes the provided event from the provided listener.
Removes the provided event from the provided listener.