smartprocure/futil-js

cascade zero value problem

chris110408 opened this issue · 3 comments

when _.iteratee(x)(obj) === 0
cascade will not return the correct value.
e.g.
F.cascade(['response.totalRecords', 'totalRecords'], { response: { totalRecords: 1, startRecord: 1, endRecord: 0, results: [] } })
the result is undefined instead of 0

@daedalus28 is this an expected behavior for cascade?

If I run that in runkit, I get 1, not 0 or undefined:

https://runkit.com/daedalus28/futil-issue-339

However, if you change the snipped to be based off of endRecord which returns 0, I do see the undefined behavior.

This is a bug, especially since if the first value in a cascade is 0, the current behavior means it will continue to the next choice even though 0 is not undefined.

If I run that in runkit, I get 1, not 0 or undefined:

https://runkit.com/daedalus28/futil-issue-339

RunKit Notebook
[Remove](#)


  [futil issue 339](https://runkit.com/daedalus28/futil-issue-339)




  
    **Environment details**
  • Node 10.23.0
  • futil: 1.67.2
let F = require('futil')
F.cascade(['response.totalRecords', 'totalRecords'], { response: { totalRecords: 1, startRecord: 1, endRecord: 0, results: [] } })
F.cascade(['response.endRecord', 'response.startRecord'], { response: { totalRecords: 1, startRecord: 1, endRecord: 0, results: [] } })

Result

   Show more
   Show less

However, if you change the snipped to be based off of endRecord which returns 0, I do see the undefined behavior.

This is a bug, especially since if the first value in a cascade is 0, the current behavior means it will continue to the next choice even though 0 is not undefined.

My Bad the test case is
F.cascade(['response.totalRecords', 'totalRecords'], { response: { totalRecords: 0, startRecord: 1, endRecord: 0, results: [] } })
that return undefined instead of 0

https://runkit.com/chris110408/5fe930fb96864f001a165209