You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've recently began working with svelte for one of my projects that builds on top of enums for managing different variations of data. While enums (TS) are awesome for working with i.e. different types of shapes for rendering, it seems to be very cumbersome to work with them in svelte files since only if is available for matching them. To tackle this and other related problems, this request is for the introduction of the case (or match, switch … name is not really relevant) operator in svelte templates.
I have searched through the issues and haven't found a related one, but I'm sorry if this is a duplicate.
Describe the proposed solution
Add the case operator, with (would be fancy) optional enforcing of exhaustive matching.
An example usage:
<scripttype="ts">
// a simple enumexportenumShape {Cat,Bunny,Dog,Plan,Car,Circle,}exportlet shape: Shape;exportlet name: string;
</script>
{#caseshape}
// first declaration acts as 'otherwise' to ensure an exhaustive pattern
<p>Animal is hiding!</p>
{:caseShape.Cat}
<p>=^._.^=</p>
{:caseShape.Dog}
<p>▼・ᴥ・▼</p>
{/case}
{#casename}
<p>Welcome {name}!</p>
{:case"John"}
<p>Welcome back {name}!</p>
{/case}
Alternatives considered
Simple matching with if is the current solution, but I've also considered using an auxiliary function to do the matching for me and return the right component.
Importance
would make my life easier
Edit 1: Changed title to more concise description
The text was updated successfully, but these errors were encountered:
Chaostheorie
changed the title
[Feature Request] Case operator (Pattern Matching)
[Feature Request] Pattern Matching Operator
Jul 5, 2021
Describe the problem
I've recently began working with svelte for one of my projects that builds on top of enums for managing different variations of data. While enums (TS) are awesome for working with i.e. different types of shapes for rendering, it seems to be very cumbersome to work with them in svelte files since only
if
is available for matching them. To tackle this and other related problems, this request is for the introduction of thecase
(ormatch
,switch
… name is not really relevant) operator in svelte templates.I have searched through the issues and haven't found a related one, but I'm sorry if this is a duplicate.
Describe the proposed solution
Add the case operator, with (would be fancy) optional enforcing of exhaustive matching.
An example usage:
Alternatives considered
Simple matching with
if
is the current solution, but I've also considered using an auxiliary function to do the matching for me and return the right component.Importance
would make my life easier
Edit 1: Changed title to more concise description
The text was updated successfully, but these errors were encountered: