-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Glimmer2 inline {{unless}}
#13019
Glimmer2 inline {{unless}}
#13019
Conversation
@@ -22,7 +22,7 @@ import { assert } from 'ember-metal/debug'; | |||
@for Ember.Templates.helpers | |||
@public | |||
*/ | |||
export default function inlineIf(args) { | |||
function inlineIf(args) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could write export function inlineIf(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks
@chancancode Do you think there is value in repeating all the existing inline if tests for inline unless? (I'm currently just testing the main use, outlined below) If so, any ideas on how I might avoid simply duplicating them? moduleFor('Helpers test: inline {{unless}}', class extends SharedHelperConditionalsTest {
templateFor({ cond, truthy, falsy }) {
return `{{unless ${cond} ${falsy} ${truthy}}}`;
}
}, BASIC_TRUTHY_TESTS, BASIC_FALSY_TESTS); |
@GavinJoyce yeah, I think we should test them. I think we mostly did the work to make them fairly reusable (by "duplicating" a few lines we get 20+ tests). I think there are a few kinds of scenarios:
|
@GavinJoyce in your specific example: moduleFor('Helpers test: inline {{unless}}', class extends SharedHelperConditionalsTest {
templateFor({ cond, truthy, falsy }) {
return `{{unless ${cond} ${falsy} ${truthy}}}`;
}
}, BASIC_TRUTHY_TESTS, BASIC_FALSY_TESTS); I think this level of duplication is acceptable. The main boilerplate here is the Besides that, I think all the code here are actually saying something meaningful. (I probably would prefer not having to do the |
Thanks, I'll spend some time tomorrow trying to make the tests as succinct as possible |
🤘 |
Of course, if only difference is just the string
I am 50-50 on these kinds of DRY-ing refactor. IMO this makes things much harder to read/reason about and usually isn't worth it when the amount of duplication is not that high. I think when the factor is just 2 (if, unless), the repetition is cheaper than the extra cognitive overhead, but I will probably be happy with whatever you decided is better. |
☔ The latest upstream changes (presumably #13047) made this pull request unmergeable. Please resolve the merge conflicts. |
'The inline form of the `if` and `unless` helpers expect two or ' + | ||
'three arguments, e.g. `{{if trialExpired \'Expired\' expiryDate}}` ', | ||
args.length === 2 || args.length === 3 | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would be nice to provide different asserting messages for {{if}}
and {{unless}}
but having a generic message now allows the tests to be compatible with HTMLBars. Perhaps I should add a TODO?
@chancancode this is ready for review. I didn't use I used your "without inverse" trick for |
{{unless}}
{{unless}}
☔ The latest upstream changes (presumably #13087) made this pull request unmergeable. Please resolve the merge conflicts. |
Rebased and merged in #13092, thanks @GavinJoyce! |
follow on from #12920
part of the Glimmer Big-Picture Integration Checklist
TODO: