Skip to content
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

Suggesting an inconsistency inside defaults function #178

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

elenaparaschiv
Copy link

@elenaparaschiv elenaparaschiv commented Aug 20, 2017

There is an inaccuracy regarding the comment in line 87, regarding allowing for empty/ zero values

// Replace values with defaults only if undefined (allow empty/ zero values) 

Problem:
Calling the defaults function, if object has a value of null, its value will be overwritten by the defs value.
Below is an example:

defaults({color: null}, {color:'grey', wheels:2})  
 // returns {color: "grey", wheels: 2}

This is inconsistent with the comment, which should allow for empty/ zero values.
To fix it, null can be swapped for undefined.

Solution:
With this fix, the expected output is returned.

{color: null, wheels: 2},

If the authors consider to not replace this code due to reasons such that it might brake the code for existing users of accounting.js, I suggest to at least change the comment to be more accurate, for example:

// Replace values with defaults only if undefined.

Thanks to @gordonmzhu for the inspiration behind this pull request.

The comment in line 87 is inaccurate
```Replace values with defaults only if undefined (allow empty/zero values) 
```

__ Problem:__ 
We try to pass in 2 objects inside defaults function and we get an unexpected result.
```
defaults({color: null}, {color:'grey', wheels:2})  
 // returns {color: "grey", wheels: 2}
```
This output shows that the null value is overwritten by the defs value. This is inaccurate and inconsistent with the comment.

__Solution:__
With this fix, the expected output is corrected to return
```
{color: null, wheels: 2},
```
@elenaparaschiv elenaparaschiv changed the title Solves an inconsistency inside defaults function Suggesting an inconsistency inside defaults function Aug 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant