-
Notifications
You must be signed in to change notification settings - Fork 11
/
event.go
63 lines (49 loc) · 1.49 KB
/
event.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package echo
import (
"github.com/admpub/events"
)
func On(name string, handlers ...events.Listener) events.Emitterer {
return events.Default.On(name, handlers...)
}
func OnCallback(name string, cb func(events.Event) error, id ...string) events.Emitterer {
return events.Default.On(name, events.Callback(cb, id...))
}
func OnStream(name string, ch chan events.Event, id ...string) events.Emitterer {
var h events.Listener
if len(id) > 0 {
h = events.StreamWithID(ch, id[0])
} else {
h = events.Stream(ch)
}
return events.Default.On(name, h)
}
func Off(name string) events.Emitterer {
return events.Default.Off(name)
}
func AddListener(listener events.Listener, names ...string) events.Emitterer {
events.Default.AddEventListener(listener, names...)
return events.Default
}
func RemoveListener(listener events.Listener) events.Emitterer {
events.Default.RemoveEventListener(listener)
return events.Default
}
func Fire(e interface{}) error {
return events.Default.Fire(e)
}
func FireByName(name string, options ...events.EventOption) error {
return events.Default.FireByName(name, options...)
}
func FireByNameWithMap(name string, data events.Map) error {
return events.Default.FireByNameWithMap(name, data)
}
func HasEvent(name string) bool {
return events.Default.HasEvent(name)
}
func EventNames() []string {
return events.Default.EventNames()
}
func NewEvent(data interface{}, options ...events.EventOption) events.Event {
return events.New(data, options...)
}
type Event = events.Event