From 3655a58b631078811a77ed464cf11681ee6c8008 Mon Sep 17 00:00:00 2001 From: Niklas Fasching Date: Mon, 3 Jun 2019 16:54:42 +0200 Subject: [PATCH] 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 --- etc/_wasm.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/etc/_wasm.go b/etc/_wasm.go index e94e0b9..1e719d6 100644 --- a/etc/_wasm.go +++ b/etc/_wasm.go @@ -10,12 +10,9 @@ 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 { @@ -23,7 +20,8 @@ func main() { } else { out.Set("innerHTML", html) } + return nil })) - <-make(chan struct{}) // stay alive + select {} // stay alive }