event

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package event contains core browser event behavior

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 {
	Details interface{}
}

type Entity added in v0.5.0

type Entity interface {
	ObjectId() entity.ObjectId
}

type ErrorEventInit

type ErrorEventInit struct {
	Err error
}

type Event

type Event struct {
	entity.Entity
	Type       string
	Bubbles    bool
	Cancelable bool
	Data       any
	// contains filtered or unexported fields
}

Event corresponds to a DOM Event dispatched by a DOM EventTarget. Different types of events carry different data. The event-specific data exist in the Data property, which must be a valid "EventInit" type. The data contains the event-specific values of the 2nd constructor argument.

// JS:
const event = new CustomEvent("my-custom", { bubbles: true, details: "Something else" })

The corresponding Go event would be:

event := Event {
  Type: "My-custom",
  Bubbles: true,
  Data: CustomEventInit{ Details: "Something else" },
}

The "EventInit" postfix reflect naming in IDL specifications.

The Go Event representation stores the value for Bubbles on the event itself. The other properties on the event options are data communicated between the event dispatcher and the event listener, which Gost doesn't care about, and as such is stored as an interface{} type.

In JavaScript, events are represented by concrete subclasses of the base Event class. The concrete class used will be determined by the Data property.

func New deprecated

func New(eventType string, eventInit any) *Event

New creates a new Event object passing a specific event type and event data.

Deprecated: Calling New was originally necessary to handle object initialization, but this is no longer necessary, and it's suggested to just create an Event objects directly

func NewCustomEvent

func NewCustomEvent(eventType string, init CustomEventInit) *Event

func NewErrorEvent

func NewErrorEvent(err error) *Event

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

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 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)

Jump to

Keyboard shortcuts

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