Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Await expressions #1857

Closed
Closed
Milestone
@Rich-Harris

Description

@Rich-Harris

Just want to capture a thought I had the other day: it might be neat to have inlineawait expressions in templates. We already have{#await ...} blocks but they're overkill in some situations — you have to declare a name for the resolved value, which you might only be using once, and you might not need to worry about error states depending on what you're doing.

Imagine something like this (v3 syntax):

<script>asyncfunctionfibonacci(n){returnawaitfibonacciWorker.calculate(n);}</script><inputtype=numberbind:value={n}><p>The {n}th Fibonacci number is {await fibonacci(n)}</p>

It would integrate withSuspense, so it'd be convenient for doing this sort of thing (whereloadImage resolves to its input, but only after ensuring that the image is loaded):

<script>importloadImagefrom'./utils.js';</script>{#each thumbnails as thumbnail}<imgalt={thumbnail.description}src="{await loadImage(thumbnail.src)}">{/each}

Of course, you'd need some way to have placeholder content, for situations where you're not using Suspense. Maybe this?

<p>The {n}th Fibonacci number is {await fibonacci(n) or '...'}</p>

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp