fix: try solution for race conditions; use brotli included in datastar sdk; small improvements

This commit is contained in:
Joao Goncalves
2025-11-14 17:16:09 -01:00
parent 351bed3ea1
commit 808d4dd0d1
6 changed files with 166 additions and 99 deletions

View File

@@ -2,29 +2,48 @@ package main
import (
"github.com/go-via/via"
"github.com/go-via/via-plugin-picocss/picocss"
"github.com/go-via/via/h"
)
type Counter struct{ Count int }
func main() {
v := via.New()
v.AppendToHead(h.Link(h.Rel("stylesheet"), h.Href("https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css")))
v.Config(via.Options{
DocumentTitle: "Via Counter",
// Plugin is placed here. Use picocss.WithOptions(pococss.Options) to add the plugin
// with a different color theme or to enable a classes for a wide range of colors.
Plugins: []via.Plugin{
picocss.Default,
},
})
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.H1(h.Text("Hello PicoCSS!")),
h.H2(h.Text("Hello PicoCSS!")),
h.H3(h.Text("Hello PicoCSS!")),
h.H4(h.Text("Hello PicoCSS!")),
h.H5(h.Text("Hello PicoCSS!")),
h.H6(h.Text("Hello PicoCSS!")),
h.Div(h.Class("grid"),
h.Button(h.Text("Primary")),
h.Button(h.Class("secondary"), h.Text("Secondary")),
return h.Main(h.Class("container"), h.Br(),
h.H1(h.Text("⚡ Via Counter")), h.Hr(),
h.Div(
h.H2(h.Textf("Count - %d", data.Count)),
h.H5(h.Text("Step - "), step.Text()),
h.Div(h.Role("group"),
h.Input(h.Type("number"), step.Bind()),
h.Button(h.Text("Increment"), increment.OnClick()),
),
),
)
})
})
v.Start()
}