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

Shouldn't initialising a object prop with undefined fallback to its default? #138

Open
ruiramos opened this issue Jan 29, 2015 · 1 comment
Labels

Comments

@ruiramos
Copy link

Hey all,
Unlike all other types of props, if you initialise an object property that has a defined default value with undefined, the default value is not used and the object is set to null.

Example: http://requirebin.com/?gist=dda59c50c9326e84064b

Not sure if this a bug or by design but it does feel a bit weird.

This happens because undefined objects are converted null in the dataTypes object definition:
(lines 645, object.set)

if (newType !== 'object' && _.isUndefined(newVal)) {
    newVal = null;
    newType = 'object';
}

... but properties only gets the default value if the value is not undefined:
(lines 551 Object.defineProperty.get)

if (typeof result !== 'undefined') { 
    (...)
    return result
}

We could easily fix this by changing that first null to undefined so that undefined objects keep their undefined value, although I don't know if that would have any side effects in other parts of the code.

Thanks !
Rui

@bear bear added the question label Jan 29, 2015
@cdaringe
Copy link
Member

Hey @ruiramos. Clear fiddle. I agree, it does not produce naturally expected results.
This was a pretty early commit in the project that @HenrikJoreteg committed back in May last year. There are checks against null in the codebase which appear to be dependent on that null being set. Maybe you can test updating said checks and the blocks you pointed out, add test or two, and run the test suite?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants