`or` doesn't work the same way as `||` in JavaScript

This issue has been tracked since 2022-01-04.
(or (array) 1)

Will return 1.

[] || 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.

sukima wrote this answer on 2022-10-11

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
  This is handled as the items are empty

{{#if (array)}}
  Never gets called
  Treated as falsey 'cause the array is empty

{{if (array) "Not shown" "shown because falsey"}}
boris-petrov wrote this answer on 2022-10-12

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.

boris-petrov wrote this answer on 2022-10-12

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).

More Details About Repo
Owner Name jmurphyau
Repo Name ember-truth-helpers
Full Name jmurphyau/ember-truth-helpers
Language JavaScript
Created Date 2015-01-08
Updated Date 2022-11-28
Star Count 703
Watcher Count 13
Fork Count 94
Issue Count 28


Issue Title Created Date Updated Date