LiveReload

This commit is contained in:
Jeff Winkler
2025-11-08 13:05:23 -05:00
parent c1ddb6441e
commit 3b658ed7d0
7 changed files with 185 additions and 1 deletions

View File

@@ -0,0 +1,46 @@
package main
import (
"github.com/go-via/via"
"github.com/go-via/via/h"
)
type Counter struct{ Count int }
func main() {
v := via.New()
LiveReloadPlugin(v)
v.Config(via.Options{
DocumentTitle: "Live Reload",
DocumentHeadIncludes: []h.H{
liveReloadScript(),
},
})
v.Page("/", func(c *via.Context) {
data := Counter{Count: 0}
step := c.Signal(1)
increment := c.Action(func() {
data.Count += step.Int()
c.Sync()
})
c.View(func() h.H {
return h.Div(h.Class("container"),
h.H1(h.Text("Live Reload")),
h.P(h.Textf("Count: %d", data.Count)),
h.P(h.Span(h.Text("Step: ")), h.Span(step.Text())),
h.Label(
h.Text("Update Step: "),
h.Input(h.Type("number"), step.Bind()),
),
h.Button(h.Text("Increment"), increment.OnClick()),
)
})
})
v.Start(":3000")
}