eventx

package
v0.0.0-...-4675295 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2024 License: Apache-2.0 Imports: 2 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DisposeHandler

func DisposeHandler()

func RegisterHandler

func RegisterHandler(handlers map[string]Handler)

Types

type Dispatcher

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

func GetEvent

func GetEvent(event string) *Dispatcher

func (*Dispatcher) Dispatch

func (dispatcher *Dispatcher) Dispatch(params ...interface{}) (err error)

Dispatch / 派发消息,实现了冒泡

func (*Dispatcher) Dispose

func (dispatcher *Dispatcher) Dispose()

func (*Dispatcher) Off

func (dispatcher *Dispatcher) Off(event *Event)

func (*Dispatcher) OffAll

func (dispatcher *Dispatcher) OffAll()

func (*Dispatcher) On

func (dispatcher *Dispatcher) On(handler Handler, priority int, params ...interface{}) (event *Event)

On 添加类型为[type],处理方法为[handler]的监听器,优先级[priority]的数值越大,越早触发 返回event用于避免重复监听

func (*Dispatcher) OnKey

func (dispatcher *Dispatcher) OnKey(handlerKey string, priority int, params ...interface{}) (event *Event)

func (*Dispatcher) Once

func (dispatcher *Dispatcher) Once(handler Handler, priority int, params ...interface{}) (event *Event)

type Event

type Event struct {

	// 监听时赋予的参数
	OnParams []interface{}
	// 触发时赋予的参数
	DispatchParams []interface{}
	// 事件的类型
	Kind string
	// contains filtered or unexported fields
}

func (*Event) Host

func (event *Event) Host() interface{}

func (*Event) Off

func (event *Event) Off()

func (*Event) Reset

func (event *Event) Reset()

func (*Event) String

func (event *Event) String() string

type Handler

type Handler func(event *Event) error

type IDispatcher

type IDispatcher interface {
	Dispose()
	Wait(kind string, params ...interface{}) IEvent
	OnKey(kind string, handlerKey string, priority int, params ...interface{})
	On(kind string, handler IHandler, priority int, params ...interface{})
	Once(kind string, handler IHandler, priority int, params ...interface{})
	Off(kind string, handler IHandler)
	OffAll()
	OffKind(kind string)
	Dispatch(kind string, params ...interface{})
	// contains filtered or unexported methods
}

type IEvent

type IEvent interface {
}

type IHandler

type IHandler interface {
}

type Manager

type Manager struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewManager

func NewManager(host interface{}) (obj *Manager)

func (*Manager) Dispose

func (mgr *Manager) Dispose()

func (*Manager) GetDispatcher

func (mgr *Manager) GetDispatcher(event string) *Dispatcher

Jump to

Keyboard shortcuts

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