htmlx-org / HTMLx

One Template to rule them all
588 stars 9 forks source link

Consistent block params syntax #19

Open NullVoxPopuli opened 1 year ago

NullVoxPopuli commented 1 year ago

I noticed in the README there is:

<h1>Cats of YouTube</h1>
<ul>
  {#each cats as cat}
    <li><a target="_blank" href={cat.video}>{cat.name}</a></li>
  {/each}
</ul>

and

{#each items as item, i}
  <p>{i}: {item.name}</p>
{/each}

and

{#each items as item (item.id)}
  <p>{item.name}</p>
{/each}

It would be good to unify the concept of "block params", so that there is only one syntax to mean "these are params passed to the block"

I propose:

{#each items as (item, i, params, here, example)}
  <p>{item.name}</p>
{/each}

and then for specifying the key, since that's a concern of each and not the block params, it should be closer to what each is iterating over.

{#each items key='id' as (item, i, params, here, , example)}
  <p>{item.name}</p>
{/each}

(this is in part inspired by the glimmer syntax, where the syntax is immensely narrow, but clear)