change NewEventHook to return pointer

This commit is contained in:
raziman 2021-02-19 12:08:56 +08:00
parent 4fa99d1043
commit e8f0b306f0
2 changed files with 7 additions and 3 deletions

View File

@ -1,9 +1,10 @@
package main package main
import ( import (
"github.com/issadarkthing/gomu/anko"
"github.com/issadarkthing/gomu/hook"
"github.com/rivo/tview" "github.com/rivo/tview"
"github.com/ztrue/tracerr" "github.com/ztrue/tracerr"
"github.com/issadarkthing/gomu/anko"
) )
var VERSION = "N/A" var VERSION = "N/A"
@ -25,6 +26,7 @@ type Gomu struct {
panels []Panel panels []Panel
args Args args Args
anko anko.Anko anko anko.Anko
hook *hook.EventHook
} }
// Creates new instance of gomu with default values // Creates new instance of gomu with default values
@ -33,6 +35,7 @@ func newGomu() *Gomu {
gomu := &Gomu{ gomu := &Gomu{
command: newCommand(), command: newCommand(),
anko: anko.NewAnko(), anko: anko.NewAnko(),
hook: hook.NewEventHook(),
} }
return gomu return gomu

View File

@ -4,8 +4,8 @@ type EventHook struct {
events map[string][]func() events map[string][]func()
} }
func NewEventHook() EventHook { func NewEventHook() *EventHook {
return EventHook{make(map[string][]func())} return &EventHook{make(map[string][]func())}
} }
func (e *EventHook) AddHook(eventName string, handler func()) { func (e *EventHook) AddHook(eventName string, handler func()) {
@ -13,6 +13,7 @@ func (e *EventHook) AddHook(eventName string, handler func()) {
hooks, ok := e.events[eventName] hooks, ok := e.events[eventName]
if !ok { if !ok {
e.events[eventName] = []func(){handler} e.events[eventName] = []func(){handler}
return
} }
e.events[eventName] = append(hooks, handler) e.events[eventName] = append(hooks, handler)