(event vdom.VDomEvent, globalEventHandler func(vdom.VDomEvent))
| 300 | } |
| 301 | |
| 302 | func (r *RootElem) Event(event vdom.VDomEvent, globalEventHandler func(vdom.VDomEvent)) { |
| 303 | defer func() { |
| 304 | if event.GlobalEventType != "" { |
| 305 | util.PanicHandler(fmt.Sprintf("Global event handler - event:%s", event.GlobalEventType), recover()) |
| 306 | } else { |
| 307 | comp := r.CompMap[event.WaveId] |
| 308 | tag := "" |
| 309 | if comp != nil && comp.Elem != nil { |
| 310 | tag = comp.Elem.Tag |
| 311 | } |
| 312 | compName := "" |
| 313 | if comp != nil { |
| 314 | compName = comp.ContainingComp |
| 315 | } |
| 316 | util.PanicHandler(fmt.Sprintf("Event handler - comp: %s, tag: %s, prop: %s", compName, tag, event.EventType), recover()) |
| 317 | } |
| 318 | }() |
| 319 | |
| 320 | eventCtx := &EventContextImpl{Event: event, Root: r} |
| 321 | withGlobalEventCtx(eventCtx, func() any { |
| 322 | if event.GlobalEventType != "" { |
| 323 | if globalEventHandler == nil { |
| 324 | log.Printf("global event %s but no handler", event.GlobalEventType) |
| 325 | return nil |
| 326 | } |
| 327 | globalEventHandler(event) |
| 328 | return nil |
| 329 | } |
| 330 | |
| 331 | comp := r.CompMap[event.WaveId] |
| 332 | if comp == nil || comp.Elem == nil { |
| 333 | return nil |
| 334 | } |
| 335 | |
| 336 | fnVal := comp.Elem.Props[event.EventType] |
| 337 | callVDomFn(fnVal, event) |
| 338 | return nil |
| 339 | }) |
| 340 | } |
| 341 | |
| 342 | func (r *RootElem) runEffectUnmount(work *EffectWorkElem, hook *Hook) { |
| 343 | defer func() { |
no test coverage detected