Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experiment going full go #207

Closed
maxence-charriere opened this issue Oct 4, 2018 · 0 comments
Closed

Experiment going full go #207

maxence-charriere opened this issue Oct 4, 2018 · 0 comments

Comments

@maxence-charriere
Copy link
Owner

maxence-charriere commented Oct 4, 2018

Hello,
When developing this package, I often ask myself if there would be a way to make it easier to use.
I'm pretty satisfied with the current way to describe an interface but sometimes, I wonder if it would be even more simple to use only Go rather than mixing it with HTML.

Go with html

The way it is done today is by creating a component by mixing go code and html code.
Here is the Hello example:

type Hello struct {
	Name string
}

func (h *Hello) Render() string {
	return `
<div class="Hello">
    <h1>
        Hello
        {{if .Name}}
            {{.Name}}
        {{else}}
            world
        {{end}}!
    </h1>
    <input value="{{.Name}}" placeholder="Write a name..." onchange="Name" autofocus>
</div>
    `
}

While it works pretty well, there is areas where I'm not totally satisfied:

  • Html is described into a go string.
    • No html auto format.
    • No html syntax check.
    • No auto-completion on html tag or properties.
  • Need to learn go template syntaxe.
  • Binding functions or fields to html callback can be a little bit confusing at the first read.
  • Parsing html have a cost in performance (not noticeable yet but the goal is to be fast!).

Only go

When I started building this repo, I tried to use only Go struct. The result was verbose and confusing to a point where I found writing html far more clean.

Though, last night I tried to gave it another try and see if it was possible to make something clean in Go. Here is what would look like the Hello component written only in go:

type Hello struct {
	Name string
}

func (h *Hello) Render() app.Node {
	return app.Div(
		app.Class("Hello"),
		app.H1(
			"Hello",
			app.If(h.Name == "",
				h.Name,
			).Else(
				"world",
			),
			"!",
		),
		app.Input(
			app.Value(h.Name),
			app.Placeholder("Write a name..."),
			app.OnChange(&h.Name),
			app.Autofocus(),
		),
	)
}

Here is what we would benefit:

  • Compiler check on valid values.
  • Go fmt.
  • IDE auto completion.
  • No go template, all you need is documented in the repo go doc.
  • Better perf (cpu and memory).
  • More expressive func/field Binding.

Let me know what you think

This is just an idea. The priority is to finish the Windows driver.

Please let me know what you think. Either by the poll below or by commenting.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant