Skip to content

Instantly share code, notes, and snippets.

@jaynagpaul
Last active July 1, 2018 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaynagpaul/922104bb4738ad56e617880645377298 to your computer and use it in GitHub Desktop.
Save jaynagpaul/922104bb4738ad56e617880645377298 to your computer and use it in GitHub Desktop.
Example of a possible future WASM + Go framework.
package devcomponents
// go:generate oak generate devcomponents -o components
import (
"github.com/hogstack/oak"
"fmt"
)
var template = `<h1> Welcome to my App {app.name}! You are {app.age} years old. </h1>`
type App struct {
oak.Component // Needed?
name string
age int
}
func (app App) Render() string {
return oak.Template(template)
// Which generates something like this to the output package
return fmt.Sprintf(`<h1> Welcome to my App %s! You are %s years old. </h1>`, app.name, app.age)
// or precompiles the lit-html approach for better performance + lighter code size in exchange for less readable generated code.
return oak.HTMLTemplate{
Template: []string{`<h1> Welcome to my App `, ` You are `, ` years old. </h1>`},
Values: []string{app.name, strconv.Itoa(app.age)},
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment