sse

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 25, 2024 License: 0BSD Imports: 2 Imported by: 2

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

func Connect[T any](hx htmx.HX[T], url string) T

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

func Swap[T any](hx htmx.HX[T], messageName string) T

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

func Trigger[T any](hx htmx.HX[T], event string) T

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL