Switch Case action examples (Beta 7)

@George @Teodor can you provide of a "How To" of using newly added Switch Case?

2 Likes

Switch Case appears to you?

I can't fine it anywhere either. I think it got missed in the update.

I could be wrong.

But I think it's beta, within beta, lol

From what I understand, you have to install Server Connect Beta.
I don't know if it makes sense, because it's already a beta, version 7.

I have the latest version with experimental features turned on. So you see it in your UI? Can you post a screenshot?

This has been added to Wappler 7 beta 7.
Make sure you're also on the Beta extensions channel as the Select - Case is available there.

The usage is quite easy, you add Select and choose an expression for it:

And then you can add as many cases as you expect with specific values:

So inside each case you add the steps that should be executed for this specific case.

5 Likes

As I said, you have to be on the beta channel, it's not enough to have the beta wappler, the channel has to be beta.

2 Likes

Yes you need to switch the Extensions channel to beta to be able to use this feature.

I assume 'Break' is added automatically after each case. Is it possible to choose where it's added?

There is no break needed as it is an exact match of the given case value, so the first exact match is executed

I'm guessing he probably wants to use break in a creative way, to e.g. prevent further steps to be executed:

case "hello":
    doSomething();
    if !doSomethingElse();
        break
    doSomethingElseElse();

I know it's not needed, but it could be useful, particularly as there's no 'else if' (yet?). Eg:

switch ('Teodor') {
  case 'George':
  case 'Teodor':
  case 'Patrick':
    console.log = "Wappler Team";
    break;
  case 'Ben':
  case 'Brian':
    console.log = "Great Wappler Videos";
    break;
  default:
    console.log = "Wappler user";
}

// returns 'Wappler Team

1 Like

The select case action has a single expression ( in the select) that is exact matched to all case values and first one wins.

We will be also introducing a multiple conditions action where you have different multiple conditions to match.

@George except technical approach and convenience is there any performance difference between "Switch Case" and just many Conditions?

In summary, Switch Case is typically faster and more readable for numerous discrete conditions, while if-else chains offer more flexibility but can be slower and harder to maintain as complexity grows.

1 Like

Will this be similar to an elseif option? It would be very useful to have both switch and elseif.

Yes, it is like an elseif. Instead of exact values like in the select action you can have multiple expressions. It will work the same as the select action, the first matched expression will execute.

2 Likes

Hey George, any update on when we get the multiple conditions action? And when the switch case will be out of the beta channel?

2 Likes

The new case action is supported only in Wappler 7 and its beta channel to avoid mixtures with old Wappler 6 stable versions.

So as long as Wappler 7 is in beta the actions will remain in the beta channel

Will see about the multi condition action soon.