Closed boris-petrov closed 2 years ago
I much prefer the behavior it is using now. It aligns with how Ember templates treat empty arrays. Changing it will make it behave different then how Ember handles empty arrays.
{{#each (array) as |item|}}
This never is handled
{{else}}
This is handled as the items are empty
{{/each}}
{{#if (array)}}
Never gets called
{{else}}
Treated as falsey 'cause the array is empty
{{/if}}
{{if (array) "Not shown" "shown because falsey"}}
Well, I guess that's a matter of taste. I personally would prefer to have the same behavior in JS and in HBS for similar things - so if ([]) ...
to behave the same as {{if (array) ...}}
. each
is a bit different as it doesn't have a direct equivalent in JS (I mean the else
part of course) - so I agree that the current behavior is OK. But for the if
examples I think that's confusing to people. Besides, you could just write {{if someArray.length ...}}
and that would work the way you want.
So after a nice discussion I'll close the issue as ember-truth-helpers
does the correct thing according to the RFC (even though the RFC says that ember-truth-helpers
does something else - the RFC is wrong in this case).
Will return
1
.Will return
[]
.That's because of this line. I believe this is confusing to users. It was for me at least. Of course, doing it the other way will be a horrible breaking change so a major version is the least you could do if you decide to change it.