Update github pages demo for go 1.12+
- go 1.12 optimizes memory allocation for wasm - see https://github.com/golang/go/issues/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
This commit is contained in:
parent
da99094e20
commit
3655a58b63
1 changed files with 5 additions and 7 deletions
12
etc/_wasm.go
12
etc/_wasm.go
|
@ -10,12 +10,9 @@ import (
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
js.Global().Call("initialized")
|
js.Global().Call("initialized")
|
||||||
|
doc := js.Global().Get("document")
|
||||||
document := js.Global().Get("document")
|
in, out := doc.Call("getElementById", "input"), doc.Call("getElementById", "output")
|
||||||
in := document.Call("getElementById", "input")
|
js.Global().Set("run", js.FuncOf(func(js.Value, []js.Value) interface{} {
|
||||||
out := document.Call("getElementById", "output")
|
|
||||||
|
|
||||||
js.Global().Set("run", js.NewCallback(func([]js.Value) {
|
|
||||||
in := strings.NewReader(in.Get("value").String())
|
in := strings.NewReader(in.Get("value").String())
|
||||||
html, err := org.New().Parse(in, "").Write(org.NewHTMLWriter())
|
html, err := org.New().Parse(in, "").Write(org.NewHTMLWriter())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -23,7 +20,8 @@ func main() {
|
||||||
} else {
|
} else {
|
||||||
out.Set("innerHTML", html)
|
out.Set("innerHTML", html)
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}))
|
}))
|
||||||
|
|
||||||
<-make(chan struct{}) // stay alive
|
select {} // stay alive
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue