I Wrote A Frontend Framework Without Any Frontend Code
Published in
3 min readJul 5, 2019
I like Go. I don’t like JavaScript. So I posed the question…
How could I write a reactive single page app without using the JavaScript or it’s ecosystem?
Here’s what I came up with:
package mainimport "github.com/elliotchance/pepper"type Counter struct {
Number int
}func (c *Counter) Render() (string, error) {
return `
Counter: {{ .Number }}<br/>
<button @click="AddOne">+</button>
`, nil
}func (c *Counter) AddOne() {
c.Number++
}func main() {
panic(pepper.StartServer(func() pepper.Component {
return &Counter{}
}))
}
That code encapsulates the entire stack. If you have Go installed, you can try it right now:
go get -u github.com/elliotchance/pepper/examples/ex01_counter
ex01_counter
Now open http://localhost:8080 in your browser… Or, just peek at this screenshot: