Renamed EventFn to EventEmptyFn and EventStateFn to EventFn (both in ui and zntg packages).

This commit is contained in:
Sander Schobers 2020-05-16 12:07:13 +02:00
parent 8c48c949e9
commit d673653d3f
2 changed files with 15 additions and 15 deletions

View File

@ -1,21 +1,21 @@
package zntg package zntg
type EventFn func() type EventEmptyFn func()
type EventStateFn func(interface{}) type EventFn func(interface{})
func NewEvents() *Events { func NewEvents() *Events {
return &Events{events: map[uint]EventStateFn{}} return &Events{events: map[uint]EventFn{}}
} }
type Events struct { type Events struct {
nextID uint nextID uint
events map[uint]EventStateFn events map[uint]EventFn
} }
type EventHandler interface { type EventHandler interface {
AddHandler(EventStateFn) uint AddHandler(EventFn) uint
AddHandlerEmpty(EventFn) uint AddHandlerEmpty(EventEmptyFn) uint
RemoveHandler(uint) RemoveHandler(uint)
} }
@ -29,9 +29,9 @@ func (e *Events) Notify(state interface{}) bool {
return len(e.events) > 0 return len(e.events) > 0
} }
func (e *Events) AddHandler(handler EventStateFn) uint { func (e *Events) AddHandler(handler EventFn) uint {
if e.events == nil { if e.events == nil {
e.events = map[uint]EventStateFn{} e.events = map[uint]EventFn{}
} }
id := e.nextID id := e.nextID
e.nextID++ e.nextID++
@ -39,7 +39,7 @@ func (e *Events) AddHandler(handler EventStateFn) uint {
return id return id
} }
func (e *Events) AddHandlerEmpty(handler EventFn) uint { func (e *Events) AddHandlerEmpty(handler EventEmptyFn) uint {
return e.AddHandler(func(interface{}) { handler() }) return e.AddHandler(func(interface{}) { handler() })
} }

View File

@ -2,9 +2,9 @@ package ui
import "opslag.de/schobers/zntg" 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 { type EventArgs struct {
Context Context Context Context
@ -16,8 +16,8 @@ type Events struct {
} }
type EventHandler interface { type EventHandler interface {
AddHandler(EventStateFn) uint AddHandler(EventFn) uint
AddHandlerEmpty(EventFn) uint AddHandlerEmpty(EventEmptyFn) uint
RemoveHandler(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}) 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{}) { return e.Events.AddHandler(func(state interface{}) {
args := state.(EventArgs) args := state.(EventArgs)
handler(args.Context, args.State) 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) }) return e.AddHandler(func(ctx Context, _ interface{}) { handler(ctx) })
} }