Documentation
¶
Overview ¶
Package dispatcher contains functionality for uni-directional event dispatching
Index ¶
- type EventDispatcher
- func New[ID comparable, E any](listenerMatcher Matcher[ID, E]) EventDispatcher[ID, E]
- func NewFrom[ID comparable, E any](globalListeners []listener.Listener[ID, E], listenerMap listener.Map[ID, E]) EventDispatcher[ID, E]
- func NewFromFunc[ID comparable, E any](closure func(ID, E), additional ...func(ID, E)) EventDispatcher[ID, E]
- func NewFromListener[ID comparable, E any](targetListener listener.Listener[ID, E], ...) EventDispatcher[ID, E]
- func NewFromMap[ID comparable, E any](listenerMap map[ID]listener.Listener[ID, E]) EventDispatcher[ID, E]
- type Matcher
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EventDispatcher ¶
type EventDispatcher[ID comparable, E any] interface { Dispatch(ID, ...E) }
An EventDispatcher invokes listeners corresponding to the provided event ID and event objects.
func New ¶
func New[ID comparable, E any](listenerMatcher Matcher[ID, E]) EventDispatcher[ID, E]
New creates an EventDispatcher using the provided matcher.
If nil is provided, an EventDispatcher having no listeners is created
func NewFrom ¶
func NewFrom[ID comparable, E any]( globalListeners []listener.Listener[ID, E], listenerMap listener.Map[ID, E], ) EventDispatcher[ID, E]
NewFrom creates an EventDispatcher using the provided global and event-specific listeners.
Global listeners are always executed no matter what event ID is passed. Listeners triggered by a specific event ID can be specified as a map in the second parameter
Nil can be passed for either parameter to specify that no listeners are present
func NewFromFunc ¶
func NewFromFunc[ID comparable, E any](closure func(ID, E), additional ...func(ID, E)) EventDispatcher[ID, E]
NewFromFunc creates an EventDispatcher using one or more of the provided closures.
Each closure is converted into a global listener -- all will be invoked for each event that's dispatched
func NewFromListener ¶
func NewFromListener[ID comparable, E any](targetListener listener.Listener[ID, E], additional ...listener.Listener[ID, E]) EventDispatcher[ID, E]
NewFromListener creates an EventDispatcher using one or more provided listeners
Each listener is converted into a global listener -- all will be invoked for each event that's dispatched. Note: Nil listeners are not permitted and the function will panic if one is encountered.
func NewFromMap ¶
func NewFromMap[ID comparable, E any](listenerMap map[ID]listener.Listener[ID, E]) EventDispatcher[ID, E]
NewFromMap creates an EventDispatcher where the specified listeners are only triggered for the corresponding event ID they're mapped to.
Each listener is converted into a global listener -- all will be invoked for each event that's dispatched. Note: Nil maps or listeners are not permitted and the function will panic if one is encountered.