event

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2025 License: MIT Imports: 3 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Capture

func Capture(o *EventListener)

func NoError

func NoError[T func(U), U any](f T) func(U) error

NoError takes a function accepting a single argument and has no return value, and transforms it into a function that can be used where an error return value is expected.

func Once

func Once(o *EventListener)

func SetEventTargetSelf

func SetEventTargetSelf(t EventTarget)

Types

type CustomEventInit

type CustomEventInit struct {
	EventInit
	Details interface{}
}

type ErrorEventInit

type ErrorEventInit struct {
	EventInit
	Err error
}

type Event

type Event struct {
	entity.Entity
	Init
	// contains filtered or unexported fields
}

func New

func New(eventType string, eventInit Init) *Event

func NewCustomEvent

func NewCustomEvent(eventType string, init CustomEventInit) *Event

func NewErrorEvent

func NewErrorEvent(err error) *Event

func (*Event) Bubbles

func (e *Event) Bubbles() bool

func (*Event) Cancelable

func (e *Event) Cancelable() bool

func (*Event) CurrentTarget

func (e *Event) CurrentTarget() EventTarget

func (*Event) EventPhase

func (e *Event) EventPhase() EventPhase

func (*Event) PreventDefault

func (e *Event) PreventDefault()

func (*Event) StopPropagation

func (e *Event) StopPropagation()

func (*Event) Target

func (e *Event) Target() EventTarget

func (*Event) Type

func (e *Event) Type() string

type EventHandler

type EventHandler interface {
	// HandleEvent is called when the the event occurrs.
	//
	// An non-nil error return value will dispatch an error event on the global
	// object in a normally configured environment.
	HandleEvent(event *Event) error
	// Equals must return true, if the underlying event handler of the other
	// handler is the same as this handler.
	Equals(other EventHandler) bool
}

EventHandler is the interface for an event handler. In JavaScript; an event handler can be a function; or an object with a `handleEvent` function. In Go code, you can provide your own implementation, or use NewEventHandlerFunc to create a valid handler from a function.

Multiple EventHandler instances can represent the same underlying event handler. E.g., when JavaScript code calls RemoveEventListener, a new Go struct is created wrapping the same underlying handler.

The Equals function must return true when the other event handler is the same as the current value, so event handlers can properly be removed, and avoiding duplicates are added by AddEventListener.

func NewEventHandlerFunc

func NewEventHandlerFunc(handler HandlerFunc) EventHandler

NewEventHandlerFunc creates an EventHandler implementation from a compatible function.

Note: Calling this twice for the same Go-function will be treated as different event handlers. Be sure to use the same instance returned from this function when removing.

func NewEventHandlerFuncWithoutError

func NewEventHandlerFuncWithoutError(handler HandlerFuncWithoutError) EventHandler

type EventInit

type EventInit struct {
	Bubbles    bool
	Cancelable bool
}

type EventListener

type EventListener struct {
	Handler EventHandler
	Capture bool
	Once    bool
}

type EventPhase

type EventPhase int
const (
	EventPhaseNone     EventPhase = 0
	EventPhaseCapture  EventPhase = 1
	EventPhaseAtTarget EventPhase = 2
	EventPhaseBubbline EventPhase = 3
)

type EventTarget

type EventTarget interface {
	AddEventListener(eventType string, listener EventHandler, options ...func(*EventListener))
	RemoveEventListener(eventType string, listener EventHandler, options ...func(*EventListener))
	DispatchEvent(event *Event) bool
	// Adds a listener that will receive _all_ dispatched event. This listener
	// will not be removed from the window when navigating. This makes it useful
	// for a test to setup event listeners _before_ navigating, as by the time the
	// Navigate function returns, the DOMContentLoaded event _has_ fired, and
	// subscribed listeners have been called.
	SetCatchAllHandler(listener EventHandler)
	SetParentTarget(EventTarget)
	RemoveAll()
	// contains filtered or unexported methods
}

func NewEventTarget

func NewEventTarget() EventTarget

type HandlerFunc

type HandlerFunc = func(*Event) error

type HandlerFuncWithoutError

type HandlerFuncWithoutError = func(*Event)

type Init

type Init interface {
	// contains filtered or unexported methods
}

Jump to

Keyboard shortcuts

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