event

package
v0.2.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 5, 2022 License: MIT Imports: 2 Imported by: 1

Documentation

Index

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL