Let's say I have a component:
- Page.svelte:
<script lang="ts">
const players: Player[] = getPlayersFromSomewhere()
</script>
{#each players || [] as player}
<Player {player} />
{/each}
- and Player.svelte:
<script lang="ts">
export let player: Player;
async function doSomethingWithPlayer() {
// many lines of code here...
}
async function doSomethingElse() {
// many lines of code here...
}
async function doSomethingElseAgain() {
// many lines of code here...
}
// ... many functions here
</script>
player is used here with many buttons like:
<button on:click={doSomethingWithPlayer}>...</button>
<button on:click={doSomethingElse}>...</button>
<button on:click={doSomethingElseAgain}>...</button>
THE QUESTION IS
Is Svelte recreating the functions in Player.svelte for each player or just one time using it for each player?
Shall I create the functions in Page.svelte and pass them to Player.svelte? Or is Svelte able to "hoist" them?