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

Previous awaited value #82

Closed
notchatbot opened this issue Jun 11, 2024 · 9 comments
Closed

Previous awaited value #82

notchatbot opened this issue Jun 11, 2024 · 9 comments
Labels
enhancement New feature or request

Comments

@notchatbot
Copy link

Describe the feature in detail (code, mocks, or screenshots encouraged)

I have the following situation

let previousValueAwaited = $state()

const someAsyncFunction = async () => { 
const response = await fetch something
previousValueAwaited = await response.json()
}
const valuePromise = $derived(async someAsyncFunction )

There may be a cool application for Previous that should always be equal to the last awaited value.

What type of pull request would this be?

Enhancement

Provide relevant links or additional information.

No response

@notchatbot notchatbot added the enhancement New feature or request label Jun 11, 2024
@abdel-17
Copy link
Collaborator

The problem with async and runes is that dependencies cannot be determined in an async context. Can you describe the feature in more detail? Perhaps with a REPL example?

@TGlide
Copy link
Member

TGlide commented Jun 12, 2024

Can't you just do something like this?

@notchatbot
Copy link
Author

It worked, but I wanted to achieved that "magical" dx that runes have without a workaround.

Here is the repl

Important: There is a small bug when clicking quickly the button that previous and current values are beign shown at the same time.

@TGlide
Copy link
Member

TGlide commented Jun 14, 2024

I think this is a Svelte bug to be honest. Will check.

@TGlide
Copy link
Member

TGlide commented Jun 14, 2024

Anyways, is something like this what you wanted? REPL

@TGlide
Copy link
Member

TGlide commented Jun 14, 2024

Indeed, it's a Svelte bug, will be fixed by sveltejs/svelte#11989

@notchatbot
Copy link
Author

Yeap Await blocks are kind of buggy. Yes! It does work. I guess that the most important part of this behaviour is "in case you are a promise then show the previous value" (Which can be achieve with the $effect that you added, no need for Previous but still might be useful though).

@huntabyte
Copy link
Member

Is this good to close now that the Svelte issue has been resolved? @TGlide @notchatbot

@notchatbot
Copy link
Author

Closed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants