From 57b22de0e4e9e3661ca829724170e2d1f25bc01c Mon Sep 17 00:00:00 2001 From: Joao Goncalves Date: Mon, 3 Nov 2025 00:56:27 -0100 Subject: [PATCH] chore: update example to be the same as readme --- internal/examples/counter/main.go | 54 +++---------------------------- internal/examples/greeter/main.go | 2 +- 2 files changed, 5 insertions(+), 51 deletions(-) diff --git a/internal/examples/counter/main.go b/internal/examples/counter/main.go index a964b4b..b088371 100644 --- a/internal/examples/counter/main.go +++ b/internal/examples/counter/main.go @@ -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() -// }) -// } diff --git a/internal/examples/greeter/main.go b/internal/examples/greeter/main.go index 46d31d8..41d0456 100644 --- a/internal/examples/greeter/main.go +++ b/internal/examples/greeter/main.go @@ -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()