Renamed EventFn to EventEmptyFn and EventStateFn to EventFn (both in ui and zntg packages).
This commit is contained in:
parent
8c48c949e9
commit
d673653d3f
18
events.go
18
events.go
@ -1,21 +1,21 @@
|
||||
package zntg
|
||||
|
||||
type EventFn func()
|
||||
type EventEmptyFn func()
|
||||
|
||||
type EventStateFn func(interface{})
|
||||
type EventFn func(interface{})
|
||||
|
||||
func NewEvents() *Events {
|
||||
return &Events{events: map[uint]EventStateFn{}}
|
||||
return &Events{events: map[uint]EventFn{}}
|
||||
}
|
||||
|
||||
type Events struct {
|
||||
nextID uint
|
||||
events map[uint]EventStateFn
|
||||
events map[uint]EventFn
|
||||
}
|
||||
|
||||
type EventHandler interface {
|
||||
AddHandler(EventStateFn) uint
|
||||
AddHandlerEmpty(EventFn) uint
|
||||
AddHandler(EventFn) uint
|
||||
AddHandlerEmpty(EventEmptyFn) uint
|
||||
RemoveHandler(uint)
|
||||
}
|
||||
|
||||
@ -29,9 +29,9 @@ func (e *Events) Notify(state interface{}) bool {
|
||||
return len(e.events) > 0
|
||||
}
|
||||
|
||||
func (e *Events) AddHandler(handler EventStateFn) uint {
|
||||
func (e *Events) AddHandler(handler EventFn) uint {
|
||||
if e.events == nil {
|
||||
e.events = map[uint]EventStateFn{}
|
||||
e.events = map[uint]EventFn{}
|
||||
}
|
||||
id := e.nextID
|
||||
e.nextID++
|
||||
@ -39,7 +39,7 @@ func (e *Events) AddHandler(handler EventStateFn) uint {
|
||||
return id
|
||||
}
|
||||
|
||||
func (e *Events) AddHandlerEmpty(handler EventFn) uint {
|
||||
func (e *Events) AddHandlerEmpty(handler EventEmptyFn) uint {
|
||||
return e.AddHandler(func(interface{}) { handler() })
|
||||
}
|
||||
|
||||
|
12
ui/events.go
12
ui/events.go
@ -2,9 +2,9 @@ package ui
|
||||
|
||||
import "opslag.de/schobers/zntg"
|
||||
|
||||
type EventFn func(Context)
|
||||
type EventEmptyFn func(Context)
|
||||
|
||||
type EventStateFn func(Context, interface{})
|
||||
type EventFn func(Context, interface{})
|
||||
|
||||
type EventArgs struct {
|
||||
Context Context
|
||||
@ -16,8 +16,8 @@ type Events struct {
|
||||
}
|
||||
|
||||
type EventHandler interface {
|
||||
AddHandler(EventStateFn) uint
|
||||
AddHandlerEmpty(EventFn) uint
|
||||
AddHandler(EventFn) uint
|
||||
AddHandlerEmpty(EventEmptyFn) uint
|
||||
RemoveHandler(uint)
|
||||
}
|
||||
|
||||
@ -25,13 +25,13 @@ func (e *Events) Notify(ctx Context, state interface{}) bool {
|
||||
return e.Events.Notify(EventArgs{Context: ctx, State: state})
|
||||
}
|
||||
|
||||
func (e *Events) AddHandler(handler EventStateFn) uint {
|
||||
func (e *Events) AddHandler(handler EventFn) uint {
|
||||
return e.Events.AddHandler(func(state interface{}) {
|
||||
args := state.(EventArgs)
|
||||
handler(args.Context, args.State)
|
||||
})
|
||||
}
|
||||
|
||||
func (e *Events) AddHandlerEmpty(handler EventFn) uint {
|
||||
func (e *Events) AddHandlerEmpty(handler EventEmptyFn) uint {
|
||||
return e.AddHandler(func(ctx Context, _ interface{}) { handler(ctx) })
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user