Svelte: More idiomatic "emit to parent" (#172)

* Svelte: More idiomatic "emit to parent".

* Run ~~uglier~~ prettier.

* Restore functions.

* Restore `on:event` after merge.
This commit is contained in:
brunnerh
2023-07-21 21:30:11 +02:00
committed by GitHub
parent c9dc8dfb19
commit b6936ef789
2 changed files with 6 additions and 5 deletions

View File

@@ -1,8 +1,9 @@
<script>
export let onYes;
export let onNo;
import { createEventDispatcher } from "svelte";
const dispatch = createEventDispatcher();
</script>
<button on:click={onYes}> YES </button>
<button on:click={() => dispatch("yes")}> YES </button>
<button on:click={onNo}> NO </button>
<button on:click={() => dispatch("no")}> NO </button>

View File

@@ -13,5 +13,5 @@
</script>
<p>Are you happy?</p>
<AnswerButton onYes={onAnswerYes} onNo={onAnswerNo} />
<AnswerButton on:yes={onAnswerYes} on:no={onAnswerNo} />
<p style="font-size: 50px;">{isHappy ? "😀" : "😥"}</p>