EventType should be an enumerable type

This commit is contained in:
Jonathan Leibiusky @xetorthio
2017-07-24 13:46:48 -03:00
parent 9293a4f8d0
commit fd7441943d

View File

@@ -1,19 +1,37 @@
package event package event
type EventType string var events []string
type EventType int
func (e EventType) String() string { func (e EventType) String() string {
return string(e) return events[int(e)]
} }
const INSTANCE_VIEWPORT_RESIZE EventType = "instance viewport resize" func ciota(s string) EventType {
const INSTANCE_DELETE EventType = "instance delete" events = append(events, s)
const INSTANCE_NEW EventType = "instance new" return EventType(len(events) - 1)
const INSTANCE_STATS EventType = "instance stats" }
const INSTANCE_TERMINAL_OUT EventType = "instance terminal out"
const SESSION_END EventType = "session end" func FindEventType(name string) (EventType, bool) {
const SESSION_READY EventType = "session ready" for i, event := range events {
const SESSION_BUILDER_OUT EventType = "session builder out" if event == name {
return EventType(i), true
}
}
return EventType(-1), false
}
var (
INSTANCE_VIEWPORT_RESIZE = ciota("instance viewport resize")
INSTANCE_DELETE = ciota("instance delete")
INSTANCE_NEW = ciota("instance new")
INSTANCE_STATS = ciota("instance stats")
INSTANCE_TERMINAL_OUT = ciota("instance terminal out")
SESSION_END = ciota("session end")
SESSION_READY = ciota("session ready")
SESSION_BUILDER_OUT = ciota("session builder out")
)
type Handler func(sessionId string, args ...interface{}) type Handler func(sessionId string, args ...interface{})
type AnyHandler func(eventType EventType, sessionId string, args ...interface{}) type AnyHandler func(eventType EventType, sessionId string, args ...interface{})