Replies: 3 comments 14 replies
-
Have you seen #13246 (comment), in particular the last example? |
Beta Was this translation helpful? Give feedback.
2 replies
-
@adiguba i love this and really need this. However i would need this on svelte 4 as we cant switch to svelte 5 anytime soon (we need a custom renderer ). |
Beta Was this translation helpful? Give feedback.
7 replies
-
@adiguba It would be great if you could put up an up-to-date PR for this. I'd love to dig into the failing test case and see if we can resolve that. |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I'm not sure where is the best place to put this, but I have some thoughts on the implementation of
{#if}
in Svelte.$.if()
call.<--[--><--]-->
or<!--[!--><--]-->
I tried to make an alternative implementation, and I wrote a new function
$.choose()
to replace$.if()
(which I kept for compatibility)$.choose()
is used for an{#if}{:else if}{:else}{/if}
block, whatever the number of else/if.<--[--><--]-->
,<!--[1--><--]-->
,<!--[2--><--]-->
, ... or<!--[!--><--]-->
You can play with it here : https://adiguba-svelte-5-test-git-if-alt-adigubas-projects.vercel.app/
And check the code here : https://github.com/adiguba/svelte/tree/if-alt
A simple example (see generated code) :
=> The generated code is a little shorter, but it is above all a real if/else in javascript !
Another exemple with transitions : elements are added to the DOM based on others conditions, so when using transition the blocks are on the same position.
=> On current Svelte elements are added from the bottom, unless we interrupt a transition.
So sometime the IF is below the ELSE...
On the new implementation the IF is always before the ELSE.
Remark :
I launched pnpm test, and it break 2 tests :
I don't think there is a solution to this that is compatible with tree-shaking, so it's a breaking-change
I think this can be a good PR and I would create it if it makes sense...
But perhaps post 5.0 ?
Thanks for reading
Beta Was this translation helpful? Give feedback.
All reactions