events

package
v0.0.0-...-b5b2f04 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Event and Target definition and implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseEvent

type BaseEvent struct {
	Type   Type
	Target Target
	When   time.Time
}

type Event

type Event interface {
	// Type returns event type.
	Type() Type

	// Target returns Target on which event was dispatched.
	Target() Target

	// WithTarget returns a copy of this event with a different target. This is
	// mainly used to forward events to another target.
	WithTarget(Target) Event

	// When returns time when event was created. WithXXX events methods shouldn't
	// change this property.
	When() time.Time
}

Event is a generic interface for all events

func NewEvent

func NewEvent(eventType Type) Event

NewEvent returns a new Event object of the given type. This function should be used as a base for real Event objects.

type Event2

type Event2 interface {
	BaseEvent() *BaseEvent
}

type Handler

type Handler interface {
	id.Identifiable
	HandleEvent(event Event)
}

Handler define an event handler.

func HandlerFunc

func HandlerFunc(handler func(event Event)) Handler

type Listener

type Listener struct {
	EventType Type
	Handler   Handler
}

Listener define a pair event type and handler.

type Target

type Target interface {
	AddEventListener(Type, Handler)
	RemoveEventListener(Type, Handler)
	DispatchEvent(event Event)
}

Target define an object that can receive events and may have listeners for them.

func NewNoOpTarget

func NewNoOpTarget() Target

NewNoOpTarget returns a new Target that ignore events listener and events.

func NewTarget

func NewTarget() Target

NewTarget return a new event Target with no listeners.

type Type

type Type id.ID

Type is the type of an Event

func NewType

func NewType(name string) Type

NewType returns a new Type that can be used for custom events type. All events type must be created before application starts.

func (Type) String

func (t Type) String() string

String implements the fmt.Stringer interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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