Documentation ¶
Overview ¶
package sse connects to an EventSource directly from HTML. It manages the connections to your web server, listens for server events, and then swaps their contents into your htmx webpage in real-time.
Index ¶
Examples ¶
Constants ¶
View Source
const Extension htmx.Extension = "sse"
Extension connects to an EventSource directly from HTML. It manages the connections to your web server, listens for server events, and then swaps their contents into your htmx webpage in real-time.
Install ¶
<script src="https://unpkg.com/htmx.org@1.9.12/dist/ext/sse.js"></script>
Extension: server-sent-events
View Source
const Message = "message"
Message is the the default name of an empty SSE event.
Variables ¶
This section is empty.
Functions ¶
func Connect ¶
Connect
Example ¶
package main import ( "fmt" "github.com/will-wow/typed-htmx-go/htmx" "github.com/will-wow/typed-htmx-go/htmx/ext/sse" ) var hx = htmx.NewStringAttrs() func main() { attr := sse.Connect(hx, "/chatroom") fmt.Println(attr) }
Output: sse-connect='/chatroom'
func Swap ¶
Swap
Example ¶
package main import ( "fmt" "github.com/will-wow/typed-htmx-go/htmx" "github.com/will-wow/typed-htmx-go/htmx/ext/sse" ) var hx = htmx.NewStringAttrs() func main() { attr := sse.Swap(hx, "event") fmt.Println(attr) }
Output: sse-swap='event'
func Trigger ¶
Trigger allows SSE messages to trigger HTTP callbacks using the [htmx.HX.Trigger()] attribute.
Example ¶
package main import ( "fmt" "github.com/will-wow/typed-htmx-go/htmx" "github.com/will-wow/typed-htmx-go/htmx/ext/sse" ) var hx = htmx.NewStringAttrs() func main() { attr := sse.Trigger(hx, "event") fmt.Println(attr) }
Output: hx-trigger='sse:event'
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.