Giter VIP home page Giter VIP logo

Comments (7)

sukima avatar sukima commented on July 18, 2024 1

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}} />

from ember-truth-helpers.

tehhowch avatar tehhowch commented on July 18, 2024

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

from ember-truth-helpers.

Techn1x avatar Techn1x commented on July 18, 2024

I can't seem to replicate the behaviour that the OP is describing. Maybe the and and or helpers were different at some point. The helpers do indeed seem to return the given value, rather than a Boolean cast of the value.

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

given that {{or}} is for truth testing and not picking a value to use.

It depends how you look at it. If we convert the or helper into an equivalent javascript...
const myValue = "OR - PRINTED" || true

I would expect myValue to be the string, rather than true.
image

from ember-truth-helpers.

NullVoxPopuli avatar NullVoxPopuli commented on July 18, 2024

does OP want ?? instead of || behavior?

from ember-truth-helpers.

emattias avatar emattias commented on July 18, 2024

does OP want ?? instead of || behavior?

Yup :)

from ember-truth-helpers.

Techn1x avatar Techn1x commented on July 18, 2024

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!

from ember-truth-helpers.

Techn1x avatar Techn1x commented on July 18, 2024

I wouldn't be against the addition of a new helper for this. Nullish coalescing is pretty common JavaScript logic these days!

from ember-truth-helpers.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.