Svelte 5 friends, how would you get rid of $effect here:
https://svelte.dev/playground/c9e38a0b0bd54c5097e346384d59d8e3?version=5.19.2
Mainly, the real question is how to deal with async code ?
https://svelte.dev/playground/c9e38a0b0bd54c5097e346384d59d8e3?version=5.19.2
Mainly, the real question is how to deal with async code ?
Comments
https://svelte.dev/playground/c9e38a0b0bd54c5097e346384d59d8e3?version=5.19.2#H4sIAAAAAAAAE21Rsa7UMBD8FWsFkiNCco_XhUv0aCgooKDEFD5nk_jJt7bsTeCI8u8oCRceEoUla3Zm1jOegfQVoYIO2QxCUyuw69Aw5NBZhwmqbzPwLWwc6xDyu-JDCEWa0PGKXXTC_-HGEyNxggrOyUQbWDhNfc2pUaTYXoOPLGbR4sWPZFAsoov-KhQ8dSb6X5otxpLT2wFdwJjKEP3VJkwK3q8G63HIYtJuRFGLV4k1o1QQdLRJQXYnREyj47-Meck2NSk2nhIfL2g_bk3UByDllIm6EfO2b2N7h4XzvVR7bZZ6BbmYsp2xYVLBwBxSVZYRExs_EkeLqTD-Wk6PxUNpdLCsXalAvDm0igsekGSsm1g8J0_yGNxHpm6OMOaYbpclF4-nU_YylidLYVy5El_G-DeuxIJ17JGLrcjdbLdRdC73n1t_jM673cVSW-2lz39WLCLxzWGt4IdteageTqfXCkS5y0LEZv709cvnInG01NvuJvcYuaDRuVy8y5ZzudIUQQ6MPxkqjiMu35ffpNuPl6YCAAA=
Still don't have a good solution. :(
Of course, I'll use a debounced later ;)
TELL ME MORE, TELL ME MORE 😁
await 👆()
console.log('🚀')
But please, don't
It's more for async mechanism, not fetch only (so not abort controller)
Just listen for the abort event
https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/abort_event
That's why it's been added to the $effect api
https://github.com/sveltejs/svelte/pull/14753
But will we be able to "await" (and double await for the .json() also)
I think I don't have the right mental model. :(
subscribed
I plan to migrate all of `@layerstack/svelte-stores` to Svelte 5 state/runes (as `@layerstack/svelte-state`).
https://github.com/techniq/layerstack/blob/main/packages/svelte-stores/src/lib/fetchStore.ts
Also smartly handles mime types, integrates with Svelte context to set common headers (ex. auth), global error handling, and a few other features.
I show an example with fetch, but it's generaly async that I don't really know how to handle well.
https://github.com/techniq/layerstack/tree/main/packages/svelte-stores/src/lib
Sometime I have some condition before doing the fetch, and then I format the result differently.
https://www.layerstack.dev/docs/svelte-stores/fetchStore
in "force: true", you say 👉 ignore cache. But cache is not mentioned anywhere else 🤓
https://svelte.dev/playground/04cfa076e7724b47a6144a919132d2aa?version=5.19.2
Not a big fan tho.
Maybe I could have another #await to remove all then ?
If you have some condition before the fetch ? Want to cancel ?
If you want to format things differently you wrap the result to a function that goes on top of the file ?
It will run multiple times without awaiting. So it's either going into a infinite loop or thing happen not at the right time.
I'm trying to find THE way :)