Skip to content

Instantly share code, notes, and snippets.

@damz

damz/main.go Secret

Created April 30, 2018 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save damz/5609c4a65535627cf7f71adc2c797d5e to your computer and use it in GitHub Desktop.
Save damz/5609c4a65535627cf7f71adc2c797d5e to your computer and use it in GitHub Desktop.
package main
import (
"strconv"
"time"
"github.com/gopherjs/vecty"
"github.com/gopherjs/vecty/elem"
"github.com/gopherjs/vecty/event"
)
func main() {
body := &Body{}
vecty.RenderBody(body)
}
type Body struct {
vecty.Core
}
func (b *Body) Mount() {
go func() {
for {
vecty.Rerender(b)
time.Sleep(time.Second)
}
}()
}
func (b *Body) Render() vecty.ComponentOrHTML {
return elem.Body(
&Component{},
)
}
type Component struct {
vecty.Core
Count int
}
func (c *Component) Render() vecty.ComponentOrHTML {
return elem.Div(
elem.Button(
vecty.Markup(event.Click(func(ev *vecty.Event) {
c.Count += 1
vecty.Rerender(c)
})),
vecty.Text("Increment"),
),
vecty.Text(strconv.Itoa(c.Count)),
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment