More switch-like Switch
#1180
Replies: 4 comments
-
Is this better? <Switch value={x()} >
<Match value={1}><StepOne /></Match>
<Match value={2}><StepTwo /></Match>
<Default>
<SomeDefaultComponent />
// lots of complex component.
</Default>
</Switch> |
Beta Was this translation helpful? Give feedback.
-
Yes, I agree that a |
Beta Was this translation helpful? Give feedback.
-
Generally speaking because of how widely shipped the components are we can't break them or really change their behavior too far outside of a major release. Which why I often direct people to solid-primitives to try out these sorts of ideas. The one benefit the current control flow has is it gives us our mutually exclusive conditionals also acting as if/elseif which allows for it to cover more ground with a single value evaluation. Of course there are ergonomics to consider and we've added a few control flow to solid-primitives like |
Beta Was this translation helpful? Give feedback.
-
I'll checked out |
Beta Was this translation helpful? Give feedback.
-
As currently implemented in Solid.js,
Switch
requires invoking signal/memo/props functions for each case. From the Solid.js docs:The (signal?) function
x
get called as many as three times — once for eachMatch
and again for thefallback
.In most programming languages, the primary benefit of
switch
is to write and evaluate an expression once and then compare it to multiple potential values without needing to repeat that expression again. It would be great if Solid'sSwitch
could provide the same benefit.This could be accomplished by adding an optional
value
attribute toSwitch
, in which to evaluate the switch expression — if that attribute is provided, then treat nestedMatch
tags as explicit values to be matched by equality, e.g.:Beta Was this translation helpful? Give feedback.
All reactions