From f6133591a86eb169a7b1b2b8d342733a887af610 Mon Sep 17 00:00:00 2001 From: Ori Pomerantz Date: Mon, 4 Dec 2023 14:16:43 -0600 Subject: [PATCH] feat(create-mud): remove window global usage in vanilla template (#1774) Co-authored-by: alvarius Co-authored-by: Kevin Ingersoll --- .changeset/khaki-cars-suffer.md | 5 +++++ templates/vanilla/packages/client/index.html | 2 +- templates/vanilla/packages/client/src/index.ts | 7 ++----- 3 files changed, 8 insertions(+), 6 deletions(-) create mode 100644 .changeset/khaki-cars-suffer.md 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) {