Documentation ¶
Index ¶
- type Dispatcher
- func (dispatcher *Dispatcher[T]) AddEventListener(listener Listener[T]) int
- func (dispatcher *Dispatcher[T]) DispatchEvent(event Event[T]) bool
- func (dispatcher *Dispatcher[T]) HasEventListener(id int) bool
- func (dispatcher *Dispatcher[T]) Ordered() bool
- func (dispatcher *Dispatcher[T]) RemoveEventListener(id int) bool
- func (dispatcher *Dispatcher[T]) SetOrdered(ordered bool)
- type Event
- type Listener
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Dispatcher ¶ added in v0.1.0
type Dispatcher[T comparable] struct { // contains filtered or unexported fields }
Dispatcher manages event listeners
func (*Dispatcher[T]) AddEventListener ¶ added in v0.1.0
func (dispatcher *Dispatcher[T]) AddEventListener(listener Listener[T]) int
AddEventListener registers a Listener
func (*Dispatcher[T]) DispatchEvent ¶ added in v0.1.0
func (dispatcher *Dispatcher[T]) DispatchEvent(event Event[T]) bool
DispatchEvent dispatchs event
func (*Dispatcher[T]) HasEventListener ¶ added in v0.1.0
func (dispatcher *Dispatcher[T]) HasEventListener(id int) bool
HasEventListener reports whether the Dispatcher has specified listener
func (*Dispatcher[T]) Ordered ¶ added in v0.2.2
func (dispatcher *Dispatcher[T]) Ordered() bool
Ordered reports whether the listeners fired by added order
func (*Dispatcher[T]) RemoveEventListener ¶ added in v0.1.0
func (dispatcher *Dispatcher[T]) RemoveEventListener(id int) bool
RemoveEventListener removes specified listener
func (*Dispatcher[T]) SetOrdered ¶ added in v0.2.2
func (dispatcher *Dispatcher[T]) SetOrdered(ordered bool)
SetOrdered sets whether the listeners fired by added order
type Event ¶
type Event[T comparable] interface { Type() T // Type gets type of event }
Event is the interface that wraps the basic Type method.
type Listener ¶ added in v0.1.0
type Listener[T comparable] interface { EventType() T // EventType gets type of listening event Handle(Event[T]) // Handle handles fired event }
A Listener handles fired event
func Listen ¶ added in v0.1.0
func Listen[T comparable, E Event[T]](eventType T, handler func(E)) Listener[T]
Listen creates a Listener by eventType and handler function
Click to show internal directories.
Click to hide internal directories.