mirror of
https://github.com/issadarkthing/gomu.git
synced 2025-05-04 22:17:48 +08:00
change NewEventHook to return pointer
This commit is contained in:
parent
4fa99d1043
commit
e8f0b306f0
5
gomu.go
5
gomu.go
@ -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
|
||||||
|
@ -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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user