package events

var handlers map[string][]func()

func init() {
	handlers = make(map[string][]func())
}

func AddListener(event string, f func()) {
	l, isPresent := handlers[event]
	if !isPresent {
		handlers[event] = []func(){
			f,
		}
	} else {
		handlers[event] = append(l, f)
	}
}

func FireEvent(event string) {
	l, isPresent := handlers[event]
	if !isPresent {
		return
	}
	for _, v := range l {
		v()
	}
}
