Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Await Destructuring #1851

Closed
Crisfole opened this issue Nov 14, 2018 · 5 comments · Fixed by #4548
Closed

Await Destructuring #1851

Crisfole opened this issue Nov 14, 2018 · 5 comments · Fixed by #4548

Comments

@Crisfole
Copy link
Contributor

Currently #await blocks do not support destructuring in the then and else clauses.

It would be helpful, especially when dealing with API results with extra wrappers around stuff, to allow destructuring there:

{#await promise}
  Loading...
{:then {prop1, prop2: { items } }}
  Prop1: {prop1}
  {#each items as i}{i}{/each}
{:catch e}
Boo {e}
{/await}
@omaishar
Copy link

+1

@dovca
Copy link

dovca commented Mar 9, 2020

Also consider destructuring multiple resolved values when using Promise.all:

{#await Promise.all([promiseOne, promiseTwo])}
    Loading...
{:then [firstValue, secondValue]}
    ...
{/await}

@Crisfole
Copy link
Contributor Author

Crisfole commented Mar 9, 2020

@dovca that comes free! Promise.all returns a promise of an array, so destructuring that would work correctly

@Conduitry
Copy link
Member

In 3.20.0, you can now destructure in await blocks! 🎉

@BulatDashiev
Copy link

With destructuring brokes the scope of destructed variables
Example: https://svelte.dev/repl/bd3005bb703f4c85bf72a08603141836?version=3.21.0
Tap on update button

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants