New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: new template behavior: switch statements #584
Comments
Wouldn't it make more sense to call it "case" instead of "when" to be consistent with the language? |
what language? :) |
Javascript (and most other programming languages?) |
This syntax allows rendering things inside the switch but outside the whens. {{#switch this.property}}
{{when "foo"}}
{{when "bar"}}
{{else}}
{{!-- a catch all case? --}}
{{/switch}} Edit: on a second thought, it's not clear how to handle the first when/case. Perhaps: {{#switch this.property when "foo"}}
{{when "bar"}}
{{else}}
{{!-- a catch all case? --}}
{{/switch}} ¯_(ツ)_/¯ |
https://www.rubyguides.com/2015/10/ruby-case/ case capacity
when 0
"You ran out of gas."
when 1..20
"The tank is almost empty. Quickly, find a gas station!"
when 21..70
"You should be ok for now."
when 71..100
"The tank is almost full."
else
"Error: capacity has an invalid value (#{capacity})"
end |
is this the point we start having the jsx conversation? 🤪😇🤓 |
in JSX, it's super easy to have unmaintainable code. restrictions are beautiful ❤️ ✨ 🎉 |
With the possibility of truth helpers landing in core, I'm not sure if it's worth a switch statement: {{#if (eq this.property "foo")}}
{{else if (eq this.property "bar")}}
{{else}}
{{/if}} Sure, a little bit more verbose and maybe more error prone because of the |
Considering that Ember is a JavaScript framework, I would think we might favor the JS terminology of Note that I'd really like to see an addon that adds this as a Handlebars helper (the above Handlebars issue has some examples), but I'm not convinced it should be part of the core framework. I would definitely use it in some projects (I found the above link when looking for a |
we could do an addon that does a build time transform that converts switch to ifs. I think that'd be neat. |
Possible usage:
this could probably be implemented as an addon, actually, so I don't know how valuable this would be:
but then, as @miguelcobain mentioned, it'd be possible to render outside of the
when
blocks, which we wouldn't want.The text was updated successfully, but these errors were encountered: