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 07b88a5
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions etc/_wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,19 @@ 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)
out.Set("innerHTML", fmt.Sprintf("<pre>%s</pre>", html))
return nil
}
out.Set("innerHTML", fmt.Sprintf("%s", err))
return nil
}))

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

0 comments on commit 07b88a5

Please sign in to comment.