From 6de656e831387e4be69aae1a847c70bd8eaa1540 Mon Sep 17 00:00:00 2001 From: Turiiya <34311583+ttytm@users.noreply.github.com> Date: Sun, 10 Sep 2023 01:59:08 +0200 Subject: [PATCH 1/2] Modernize bind example --- examples/bind/main.go | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/examples/bind/main.go b/examples/bind/main.go index 3374f84..b70e66b 100644 --- a/examples/bind/main.go +++ b/examples/bind/main.go @@ -2,19 +2,17 @@ package main import webview "github.com/webview/webview_go" -const html = ` +const html = ` +
You tapped 0 time(s).
` + const counter = document.getElementById("count") + async function increment() { + const result = await window.Increment() + counter.textContent = result.count; + } + +` type IncrementResult struct { Count uint `json:"count"` @@ -28,7 +26,7 @@ func main() { w.SetSize(480, 320, webview.HintNone) // A binding that increments a value and immediately returns the new value. - w.Bind("increment", func() IncrementResult { + w.Bind("Increment", func() IncrementResult { count++ return IncrementResult{Count: count} }) From f9596dfad3acbcc8b523ae5a9965abed128d326a Mon Sep 17 00:00:00 2001 From: Turiiya <34311583+ttytm@users.noreply.github.com> Date: Fri, 22 Sep 2023 19:16:58 +0200 Subject: [PATCH 2/2] Apply suggestions --- examples/bind/main.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/examples/bind/main.go b/examples/bind/main.go index b70e66b..28e5eb3 100644 --- a/examples/bind/main.go +++ b/examples/bind/main.go @@ -2,17 +2,16 @@ package main import webview "github.com/webview/webview_go" -const html = ` - +const html = `
You tapped 0 time(s).
-` + const incrementBtn = document.getElementById("increment"); + const counter = document.getElementById("count"); + incrementBtn.addEventListener("click", async () => { + const result = await window.increment(); + counter.textContent = result.count; + }); +` type IncrementResult struct { Count uint `json:"count"` @@ -26,7 +25,7 @@ func main() { w.SetSize(480, 320, webview.HintNone) // A binding that increments a value and immediately returns the new value. - w.Bind("Increment", func() IncrementResult { + w.Bind("increment", func() IncrementResult { count++ return IncrementResult{Count: count} })