I Wrote A Frontend Framework Without Any Frontend Code

Elliot Chance
Level Up Coding
Published in
3 min readJul 5, 2019

--

Photo by Goran Ivos on Unsplash

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:

--

--

I’m a data nerd and TDD enthusiast originally from Sydney. Currently working for Uber in New York. My thoughts here are my own. 🤓 elliotchance@gmail.com