Last active
July 1, 2018 14:55
-
-
Save jaynagpaul/922104bb4738ad56e617880645377298 to your computer and use it in GitHub Desktop.
Example of a possible future WASM + Go framework.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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