event

package
v0.0.0-...-9034458 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2016 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bubble

func Bubble(e IEvent, ls EventListeners) (err error)

func Capture

func Capture(e IEvent, ls EventListeners) (err error)

Types

type EventListeners

type EventListeners interface {
	NumListener() int
	ListenerNum(int) IListen
}

EventListeners provides the helper code a way to traverse listeners.

type IEvent

type IEvent interface {
	Id() ident.Id
	Data() interface{}

	Bubbles() bool
	Cancelable() bool
	DefaultBlocked() bool

	Target() ITarget // ultimate endpoint for the event
	Path() PathList

	Phase() Phase
	CurrentTarget() ITarget // which changes as the event captures and bubbles

	// cancel the default action
	// returns true if now cancelled
	PreventDefault() bool
	// stop processing the event flow after this set is done
	StopPropagation()
	// stop processing all other event handlers immediately
	StopImmediatePropagation()
}

IEvent implemented as interface to help show callers are not intended to modify, but since we cant inherit, and i dont want to implement 100 functions for every event a generic data() seems required.

type IListen

type IListen interface {
	// FIX: does dispatch really need an error handling?
	HandleEvent(IEvent) error
}

IListen in order to handle event callbacks. Uses an interface for facilitating add/remove event listeners; comparing function pointers is error-prone in go (due to closures)

type ITarget

type ITarget interface {
	Id() ident.Id
	Parent() (ITarget, bool)     // used by path.addPath
	TargetDispatch(IEvent) error // used by proc.sendToTarget, Send(path PathList)
}

ITarget dispatch events to some hierarchical node, for instance, in a DOM. FIX: i wonder whether instead of having ITarget ( target could be an id ) the focus could be around Path: rather than building ( and copying ) the path ahead of time, instead: have a path interface which the caller implements. dispatch could be to a path node. evaluate what dispatch needs, not what we want to give it.

type Message

type Message struct {
	Id          ident.Id
	Data        interface{}
	CaptureOnly bool
	CantCancel  bool
}

func (*Message) Send

func (msg *Message) Send(path PathList) (bool, error)

Send returns true if the default action is desired.

func (*Message) String

func (msg *Message) String() string

type PathList

type PathList struct {
	*list.List
}

func NewPathTo

func NewPathTo(n ITarget) PathList

func (PathList) Cast

func (PathList) Cast(el *list.Element) ITarget

func (PathList) String

func (path PathList) String() string

type Phase

type Phase int
const (
	CapturingPhase Phase = iota
	TargetPhase
	BubblingPhase
)

func (Phase) String

func (phase Phase) String() string

type Proc

type Proc struct {
	// contains filtered or unexported fields
}

Proc implements IEvent

func (*Proc) Bubbles

func (evt *Proc) Bubbles() bool

func (*Proc) Cancelable

func (evt *Proc) Cancelable() bool

func (*Proc) CurrentTarget

func (evt *Proc) CurrentTarget() ITarget

func (*Proc) Data

func (evt *Proc) Data() interface{}

func (*Proc) DefaultBlocked

func (evt *Proc) DefaultBlocked() bool

func (*Proc) Id

func (evt *Proc) Id() ident.Id

func (*Proc) Path

func (evt *Proc) Path() PathList

func (*Proc) Phase

func (evt *Proc) Phase() Phase

func (*Proc) PreventDefault

func (evt *Proc) PreventDefault() bool

func (*Proc) StopImmediatePropagation

func (evt *Proc) StopImmediatePropagation()

func (*Proc) StopPropagation

func (evt *Proc) StopPropagation()

func (*Proc) Target

func (evt *Proc) Target() ITarget

Jump to

Keyboard shortcuts

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