-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevents.go
More file actions
39 lines (32 loc) · 1.15 KB
/
events.go
File metadata and controls
39 lines (32 loc) · 1.15 KB
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
package hypp
import (
"github.com/macabot/hypp/window"
)
var (
globalNodeEvents = newRepo[Dispatchable]()
globalNodeEventListeners = newRepo[window.EventListenerID]()
)
// removeChild deletes all events and eventListeners before removing the child from its parent.
func removeChild(parent, child window.Element) {
getEvents(child).deleteAll()
eventListeners := getEventListeners(child)
for key, id := range eventListeners.toMap() {
child.RemoveEventListener(key, id)
}
eventListeners.deleteAll()
parent.RemoveChild(child)
}
// getEvents returns the node's "events" property.
func getEvents(node window.Element) *propertyRepo[Dispatchable] {
if node.Value.Get("events").IsUndefined() {
node.Value.Set("events", map[string]any{})
}
return newPropertyRepo(node.Value.Get("events"), globalNodeEvents)
}
// getEventListeners returns the node's "eventListeners" property.
func getEventListeners(node window.Element) *propertyRepo[window.EventListenerID] {
if node.Value.Get("eventListeners").IsUndefined() {
node.Value.Set("eventListeners", map[string]any{})
}
return newPropertyRepo(node.Value.Get("eventListeners"), globalNodeEventListeners)
}