-
Notifications
You must be signed in to change notification settings - Fork 95
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
or
cant be used when or condition value can be false
#150
Comments
Count me as "Definitely against changing the semantics of I would suggest implementing your own "nullish coalesing" template helper. Possible names:
|
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}} /> |
I can't seem to replicate the behaviour that the OP is describing. Maybe the I'm running Ember 4.12 and ember-truth-helpers 3.1.1 {{log (or "OR - PRINTED" true)}} // OR - PRINTED
{{log (or "OR - PRINTED" false)}} // OR - PRINTED
{{log (or true "OR - NOT PRINTED")}} // true
{{log (or false "OR - PRINTED")}} // OR - PRINTED
{{log (and "AND - NOT PRINTED" true)}} // true
{{log (and "AND - NOT PRINTED" false)}} // false
{{log (and true "AND - PRINTED")}} // AND - PRINTED
{{log (and false "AND - NOT PRINTED")}} // false Might be related to #143
It depends how you look at it. If we convert the or helper into an equivalent javascript... |
does OP want |
Yup :) |
Ah ok. I might have misunderstood the issue, thought it was a bug report rather than a feature request, got confused with the mention of the or helper. Sorry! |
I wouldn't be against the addition of a new helper for this. Nullish coalescing is pretty common JavaScript logic these days! |
When I want to use a provided
@arg
whos value can befalse
and I want to default to true theor
helper doesnt work as I need. See this example:If
@argThatCanBeFalse
is sent in asfalse
@bar
will be resolved to true.This is because
or
uses thetruthConvert
util that does a regular double not operator (!!
): https://github.com/jmurphyau/ember-truth-helpers/blob/master/addon/utils/truth-convert.js#L11Should we change the
or
helper to only treatundefined
(and maybenull
) as false values or should we create a new helper. Called something likeor-nullish
oror-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 😅The text was updated successfully, but these errors were encountered: