htmgo/examples/sse-with-state/partials/click.go

22 lines
625 B
Go
Raw Normal View History

2024-10-08 17:48:28 +00:00
package partials
import (
"github.com/maddalax/htmgo/framework/h"
"sse-with-state/event"
2024-10-09 14:57:51 +00:00
"sse-with-state/internal"
2024-10-08 17:48:28 +00:00
)
func OnClick(ctx *h.RequestContext, handler event.Handler) *h.AttributeMapOrdered {
return event.AddHandler(ctx, "click", handler)
}
2024-10-09 14:57:51 +00:00
func OnServerSideEvent(ctx *h.RequestContext, eventName string, handler event.Handler) h.Ren {
id := internal.RandSeq(30)
2024-10-08 17:48:28 +00:00
event.AddServerSideHandler(ctx, id, eventName, handler)
2024-10-09 14:57:51 +00:00
return h.Attribute("data-handler-id", id)
2024-10-08 17:48:28 +00:00
}
func OnMouseOver(ctx *h.RequestContext, handler event.Handler) *h.AttributeMapOrdered {
return event.AddHandler(ctx, "mouseover", handler)
}