class Athena::EventDispatcher::EventDispatcher

Included Modules

Direct Known Subclasses

Defined in:

event_dispatcher.cr

Constructors

Instance Method Summary

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) : Nil
remove_listener(event : AED::Event.class, listener : AED::EventListenerType) : Nil
remove_listener

Constructor Detail

def self.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]
def self.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]

Instance Method Detail

def 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]
def 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]
def has_listeners?(event : AED::Event.class | Nil = nil) : Bool #

:inherit:


[View source]
def listener_priority(event : AED::Event.class, listener : AED::EventListenerInterface.class) : Int32 | Nil #

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]
def listeners(event : AED::Event.class | Nil = nil) : Array(AED::EventListener) #

:inherit:


[View source]
def remove_listener(event : AED::Event.class, listener : AED::EventListenerInterface.class) : Nil #

Removes the provided event from the provided listener.


[View source]
def remove_listener(event : AED::Event.class, listener : AED::EventListenerType) : Nil #

Removes the provided event from the provided listener.


[View source]