EventType should be an enumerable type
This commit is contained in:
@@ -1,19 +1,37 @@
|
||||
package event
|
||||
|
||||
type EventType string
|
||||
var events []string
|
||||
|
||||
type EventType int
|
||||
|
||||
func (e EventType) String() string {
|
||||
return string(e)
|
||||
return events[int(e)]
|
||||
}
|
||||
|
||||
const INSTANCE_VIEWPORT_RESIZE EventType = "instance viewport resize"
|
||||
const INSTANCE_DELETE EventType = "instance delete"
|
||||
const INSTANCE_NEW EventType = "instance new"
|
||||
const INSTANCE_STATS EventType = "instance stats"
|
||||
const INSTANCE_TERMINAL_OUT EventType = "instance terminal out"
|
||||
const SESSION_END EventType = "session end"
|
||||
const SESSION_READY EventType = "session ready"
|
||||
const SESSION_BUILDER_OUT EventType = "session builder out"
|
||||
func ciota(s string) EventType {
|
||||
events = append(events, s)
|
||||
return EventType(len(events) - 1)
|
||||
}
|
||||
|
||||
func FindEventType(name string) (EventType, bool) {
|
||||
for i, event := range events {
|
||||
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 AnyHandler func(eventType EventType, sessionId string, args ...interface{})
|
||||
|
||||
Reference in New Issue
Block a user