Skip to content

class Athena::EventDispatcher::EventDispatcher
inherits Reference #

Included modules

Athena::EventDispatcher::EventDispatcherInterface

Class methods#

.new(listeners : Array(AED::EventListenerInterface)) #

Initializes self with the provided listeners.

This overload is mainly intended for DI or to manually configure the listeners that should be listened on.

View source

.new #

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.

View source

Methods#

#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.

View source

#dispatch(event : AED::Event) : Nil #

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.

View source

#has_listeners?(event : AED::Event.class? = nil) : Bool #

Returns true if there are any listeners listening on the provided event. If no event is provided, returns true if there are ANY listeners registered on self.

View source

#listener_priority(event : AED::Event.class, listener : AED::EventListenerInterface.class) : Int32? #

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.

View source

#listeners(event : AED::Event.class? = nil) : Array(AED::EventListener) #

Returns the listeners listening on the provided event. If no event is provided, returns all listeners.

View source

#remove_listener(event : AED::Event.class, listener : AED::EventListenerInterface.class) : Nil #

Removes the provided event from the provided listener.

View source

#remove_listener(event : AED::Event.class, listener : AED::EventListenerType) : Nil #

Removes the provided event from the provided listener.

View source