-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Closed
Labels
Description
Currently there is no specific syntax to reuse computations that depend on each
loop variables. For example, here's some code that loops over some numbers and uses the squares of the numbers in two different ways:
{#each [1,2,3,4] as n}
{#each [n*n] as sqr_n}
{sqr_n} {sqr_n/2}<br>
{/each}
{/each}
The inner each
is a hack to define a reusable computation. It would lovely to have syntax something like this:
{#each [1,2,3,4] as n}
{#let sqr_n = n * n}
{sqr_n} {sqr_n/2}<br>
{/each}
Besides being easier to read, that syntax has the advantage of not introducing another nesting level. Is there a clean alternative to the second version in current svelte? If not, would this be a reasonable feature to add?
milahu, oreilles, cdock1029, joshuakb2, funatsufumiya and 19 more