Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions examples/bind/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@ package main

import webview "github.com/webview/webview_go"

const html = `<button id="increment">Tap me</button>
const html = `<html style="background: #1B2845; color: #eee;">
<button onclick="increment();">Tap me</button>
<div>You tapped <span id="count">0</span> time(s).</div>
<script>
const [incrementElement, countElement] =
document.querySelectorAll("#increment, #count");
document.addEventListener("DOMContentLoaded", () => {
incrementElement.addEventListener("click", () => {
window.increment().then(result => {
countElement.textContent = result.count;
});
});
});
</script>`
const counter = document.getElementById("count")
async function increment() {
const result = await window.Increment()
counter.textContent = result.count;
}
</script>
</html>`

type IncrementResult struct {
Count uint `json:"count"`
Expand All @@ -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}
})
Expand Down