class Athena::EventDispatcher::GenericEvent(S, V)
Overview
An extension of AED::Event
that provides a generic event type that can be used in place of dedicated event types.
Allows using various instantiations of this one event type to handle multiple events.
INFO: This type is provided for convenience for use within simple use cases. Dedicated event types are still considered a best practice.
Usage
A generic event consists of a #subject
of type S
, which is some object/value representing an event that has occurred.
#arguments
of type V
may also be provided to augment the event with additional context, which is modeled as a Hash(String, V)
.
dispatcher.dispatch(
AED::GenericEvent(MyClass, Int32 | String).new(
my_class_instance,
{"counter" => 0, "data" => "bar"}
)
)
Refer to [AED::Event][Athena::EventDispatcher::Event--generics] for examples of how listeners on events with generics behave.
TODO Make this include Mappable
when/if https://github.com/crystal-lang/crystal/issues/10886 is implemented.
Defined in:
generic_event.crConstructors
Instance Method Summary
-
#[](key : String) : V
Returns the argument with the provided key, raising if it does not exist.
-
#[]=(key : String, value : V) : Nil
Sets the argument with the provided key to the provided value.
-
#[]?(key : String) : V | Nil
Returns the argument with the provided key, or
nil
if it does not exist. -
#arguments : Hash(String, V)
Returns the extra information stored with this event.
-
#arguments=(arguments : Hash(String, V))
Sets the extra information that should be stored with this event.
-
#has_key?(key : String) : Bool
Returns
true
if there is an argument with the provided key, otherwisefalse
. -
#subject : S
Returns the subject of this event.
Class methods inherited from class Athena::EventDispatcher::Event
callable(*, priority : Int32 = 0, name : String | Nil = nil, &block : self, AED::EventDispatcherInterface -> Nil) : AED::Callable
callable
Instance methods inherited from module Athena::EventDispatcher::StoppableEvent
propagate? : Bool
propagate?,
stop_propagation : Nil
stop_propagation
Constructor Detail
Instance Method Detail
Returns the argument with the provided key, raising if it does not exist.
Sets the argument with the provided key to the provided value.
Returns the argument with the provided key, or nil
if it does not exist.
Sets the extra information that should be stored with this event.
Returns true
if there is an argument with the provided key, otherwise false
.