class Athena::EventDispatcher::EventDispatcher

Overview

Default implementation of AED::EventDispatcherInterface.

Included Modules

Direct Known Subclasses

Defined in:

event_dispatcher.cr

Instance Method Summary

Instance methods inherited from module Athena::EventDispatcher::EventDispatcherInterface

dispatch(event : AED::Event) : AED::Event dispatch, has_listeners?(event_class : AED::Event.class) : Bool
has_listeners? : Bool
has_listeners?
, listener(callable : AED::Callable) : AED::Callable
listener(listener : T) : Nil forall T
listener(callable : AED::Callable, *, priority : Int32) : AED::Callable
listener(event_class : E.class, *, priority : Int32 = 0, name : String | Nil = nil, &block : E, AED::EventDispatcherInterface -> Nil) : AED::Callable forall E
listener
, listeners(for event_class : AED::Event.class) : Array(AED::Callable)
listeners : Hash(AED::Event.class, Array(AED::Callable))
listeners
, remove_listener(callable : AED::Callable) : Nil
remove_listener(listener : T) : Nil forall T
remove_listener

Instance Method Detail

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

Dispatches the provided event to all listeners listening on that event. Listeners are executed in priority order, highest first.


[View source]
def has_listeners?(event_class : AED::Event.class) : Bool #

Returns true if this dispatcher has any listeners on the provided event_class.


[View source]
def has_listeners? : Bool #

Returns true if there are any listeners on any event.


[View source]
def listener(callable : AED::Callable) : AED::Callable #

Registers the provided callable listener to this dispatcher.


[View source]
def listener(listener : T) : Nil forall T #

Registers the provided listener instance to this dispatcher.

T is any type that has methods annotated with AEDA::AsEventListener.


[View source]
def listener(callable : AED::Callable, *, priority : Int32) : AED::Callable #

Registers the provided callable listener to this dispatcher, overriding its priority with that of the provided priority.


[View source]
def listener(event_class : E.class, *, priority : Int32 = 0, name : String | Nil = nil, &block : E, AED::EventDispatcherInterface -> Nil) : AED::Callable forall E #

Registers the block as an AED::Callable on the provided event_class, optionally with the provided priority and/or name.


[View source]
def listeners(for event_class : AED::Event.class) : Array(AED::Callable) #

Returns an Array(AED::Callable) for all listeners on the provided event_class.


[View source]
def listeners : Hash(AED::Event.class, Array(AED::Callable)) #

Returns a hash of all registered listeners as a Hash(AED::Event.class, Array(AED::Callable)).


[View source]
def remove_listener(callable : AED::Callable) : Nil #

Deregisters the provided callable from this dispatcher.

TIP: The callable may be one retrieved via either #listeners method.


[View source]
def remove_listener(listener : T) : Nil forall T #

Deregisters listeners based on the provided listener from this dispatcher.

T is any type that has methods annotated with AEDA::AsEventListener.


[View source]