Skip to content

feature request: {#await let promise} #4665

@knobo

Description

@knobo

When iterating over a list, I would like to be able to perform actions on that list without creating a separate component with its own local variables.

<script>
  let promise = 0
  let next = (value) =>  
    new Promise(resolve => setTimeout(() => resolve(value + 1), 1000))
</script>

{#each {length: 5} as i}
  {#await promise}
    Waiting
  {:then result}
    <button on:click={() => promise = next(result)}>Next</button>
    result: {result}
  {:catch error}
    error: {error}
  {/await}
{/each}

repl example

with {#await let promise} The action is local to each iteration.

and with a default value {#await let promise = "foo"}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions