From d673653d3f2964a91bd204641f87a6c3de7c3092 Mon Sep 17 00:00:00 2001 From: Sander Schobers Date: Sat, 16 May 2020 12:07:13 +0200 Subject: [PATCH] Renamed EventFn to EventEmptyFn and EventStateFn to EventFn (both in ui and zntg packages). --- events.go | 18 +++++++++--------- ui/events.go | 12 ++++++------ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/events.go b/events.go index e264187..b2e4a46 100644 --- a/events.go +++ b/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() }) } diff --git a/ui/events.go b/ui/events.go index 404f36c..7e361bb 100644 --- a/ui/events.go +++ b/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) }) }