Skip to content

Commit

Permalink
Update github pages demo for go 1.12+
Browse files Browse the repository at this point in the history
- go 1.12 optimizes memory allocation for wasm - see
  golang/go#27462. This was causing the demo to OOM
  on memory restricted devices (e.g. phones).
- js namespace changed so we need to adapt to that
  • Loading branch information
niklasfasching committed Jun 3, 2019
1 parent da99094 commit 3655a58
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions etc/_wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,18 @@ import (

func main() {
js.Global().Call("initialized")

document := js.Global().Get("document")
in := document.Call("getElementById", "input")
out := document.Call("getElementById", "output")

js.Global().Set("run", js.NewCallback(func([]js.Value) {
doc := js.Global().Get("document")
in, out := doc.Call("getElementById", "input"), doc.Call("getElementById", "output")
js.Global().Set("run", js.FuncOf(func(js.Value, []js.Value) interface{} {
in := strings.NewReader(in.Get("value").String())
html, err := org.New().Parse(in, "").Write(org.NewHTMLWriter())
if err != nil {
out.Set("innerHTML", fmt.Sprintf("<pre>%s</pre>", err))
} else {
out.Set("innerHTML", html)
}
return nil
}))

<-make(chan struct{}) // stay alive
select {} // stay alive
}

0 comments on commit 3655a58

Please sign in to comment.