`or` cant be used when or condition value can be `false`

This issue has been tracked since 2022-05-28.

When I want to use a provided @arg whos value can be false and I want to default to true the or helper doesnt work as I need. See this example:

<Foo
	@bar={{or @argThatCanBeFalse true}}
/>

If @argThatCanBeFalse is sent in as false @bar will be resolved to true.

This is because or uses the truthConvert util that does a regular double not operator (!!): https://github.com/jmurphyau/ember-truth-helpers/blob/master/addon/utils/truth-convert.js#L11

Should we change the or helper to only treat undefined (and maybe null) as false values or should we create a new helper. Called something like or-nullish or or-undefined or something that works more like the Nullish coalescing operator (??) ?

I can do a PR if this is something that that maintainers want to add to the project. First question then is if we should change the current or helper or what the new one should then be called 😅

tehhowch wrote this answer on 2022-06-10

Count me as "Definitely against changing the semantics of {{or}}" The behavior you describe is 100% what I expect to happen, given that {{or}} is for truth testing and not picking a value to use.

I would suggest implementing your own "nullish coalesing" template helper. Possible names:

  • arg-or
  • or-default
sukima wrote this answer on 2022-10-11

Two workarounds:

Out of the box

<Foo @bar={{if (eq @argThatCanBeFalse false) false true}} />

Custom nullish helper

// app/helpers/with-default.js
import { helper } from '@ember/component/helper';

export default helper(([value, defaultValue]) => (value ?? defaultValue));
<Foo @bar={{with-default @argThatCanBeFalse true}} />
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

YOU MAY BE INTERESTED

Issue Title Created Date Updated Date