DEV Community


Starting to feel like a proper UI framework

progrium profile image Jeff Lindsay Updated on ・2 min read

First of all, yesterday off stream I added slot support to vtemplate. I'll show that in the demo. This morning I started pushing this more into the direction of an actual web UI framework. The main thing I wanted to accomplish was letting you define HTML templates in a file next to your Go component. This also involved setting up asset compilation since they'd need to be accessible from within the WebAssembly binary.

I used vfsgen which lets you define an http.FileSystem variable that it uses to then generate a replacement file that gives you a variable that returns the same data, but from compressed data in-memory. This involved some experimentation to get right, but I like the system I ended up with.

I also wanted to simplify how Go components reference their template data, so I made a helper that looks at the filename of where it was called from and then looks for a template with the same filename but with .html extension.

The render helper still hardcodes the directives and evaluator, but at least looks up components and custom elements from a registry. You just register your components in init().

Lastly I updated the dev server since now it needs to watch for HTML files. I updated the HTML that bootstraps the page to just reload the WebAssembly instance instead of the whole page. This gives it more of that hot reload feel, even though it's still reloading the entire app.

What next? I guess the dev server could use some more work, but then I might be ready to try building a real app with this.

Discussion (0)

Editor guide