diff --git a/.changeset/khaki-cars-suffer.md b/.changeset/khaki-cars-suffer.md new file mode 100644 index 0000000000..84ded1f01e --- /dev/null +++ b/.changeset/khaki-cars-suffer.md @@ -0,0 +1,5 @@ +--- +"create-mud": minor +--- + +Replaced usage of `window` global in vanilla JS template with an event listener on the button. diff --git a/templates/vanilla/packages/client/index.html b/templates/vanilla/packages/client/index.html index 4345268f38..c1f2329aa8 100644 --- a/templates/vanilla/packages/client/index.html +++ b/templates/vanilla/packages/client/index.html @@ -8,6 +8,6 @@
Counter: 0
- + diff --git a/templates/vanilla/packages/client/src/index.ts b/templates/vanilla/packages/client/src/index.ts index 0c7dda5720..52bf00a491 100644 --- a/templates/vanilla/packages/client/src/index.ts +++ b/templates/vanilla/packages/client/src/index.ts @@ -14,11 +14,8 @@ components.Counter.update$.subscribe((update) => { document.getElementById("counter")!.innerHTML = String(nextValue?.value ?? "unset"); }); -// Just for demonstration purposes: we create a global function that can be -// called to invoke the Increment system contract via the world. (See IncrementSystem.sol.) -(window as any).increment = async () => { - console.log("new counter value:", await increment()); -}; +// Attach the increment function to the html element with ID `incrementButton` (if it exists) +document.querySelector("#incrementButton")?.addEventListener("click", increment); // https://vitejs.dev/guide/env-and-mode.html if (import.meta.env.DEV) {