chore: update example to be the same as readme

This commit is contained in:
Joao Goncalves
2025-11-03 00:56:27 -01:00
parent 61ce1d4258
commit 57b22de0e4
2 changed files with 5 additions and 51 deletions

View File

@@ -5,25 +5,24 @@ import (
"github.com/go-via/via/h"
)
type CounterState struct{ Count int }
type Counter struct{ Count int }
func main() {
v := via.New()
v.Page("/", func(c *via.Context) {
s := CounterState{Count: 0}
data := Counter{Count: 0}
step := c.Signal(1)
increment := c.Action(func() {
s.Count += step.Int()
data.Count += step.Int()
c.Sync()
})
c.View(func() h.H {
return h.Div(
h.P(h.Textf("Count: %d", s.Count)),
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: "),
@@ -36,48 +35,3 @@ func main() {
v.Start(":3000")
}
//
// c.View(func() h.H {
// return Layout(
// h.Div(
// h.Meta(h.Data("init", "@get('/_sse')")),
// h.P(h.Data("text", "$via-ctx")),
// h.Div(
// counter(),
// h.Data("signals:step", "1"),
// h.Label(h.Text("Step")),
// h.Input(h.Data("bind", "step")),
// h.Button(
// h.Text("Trigger foo"),
// h.Data("on:click", "@get('/_action/foo')"),
// ),
// ),
// ),
// )
// })
// conterComponent := c.Component("counter1", CounterComponent)
//
// in c.View of page add CounterComponent
//
// func CounterComponent(c *via.Context){
// s := CounterState{ Count: 1 }
// step := c.Signal(1)
//
// c.View(func() h.H {
// return h.Div(
// h.P(h.Textf("Count: %d", s.Count)),
// h.Label(
// h.Text("Step"),
// h.Input(h.Type("number"), step.Bind()),
// ),
// h.Button(h.Text("Increment"), h.OnClick("inc")),
// )
// })
//
// c.Action("inc", func() {
// s.Count += step
// c.Sync()
// })
// }

View File

@@ -9,13 +9,13 @@ func main() {
v := via.New()
v.Page("/", func(c *via.Context) {
greeting := c.Signal("Hello...")
greetBob := c.Action(func() {
greeting.SetValue("Hello Bob!")
c.SyncSignals()
})
greetAlice := c.Action(func() {
greeting.SetValue("Hello Alice!")
c.SyncSignals()