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

get or getIn on List using a key that is a string, object, or void 0 does not return correct notSetValue #486

Closed
dashed opened this issue May 28, 2015 · 8 comments
Labels

Comments

@dashed
Copy link
Contributor

dashed commented May 28, 2015

const {List} = require('immutable');

const foo = List();

const NOT_SET = {};
console.log(foo.get('bar', NOT_SET) !== NOT_SET); // => true (expected false)
console.log(foo.getIn(['bar'], NOT_SET) !== NOT_SET); // => true (expected false)

// this regression breaks .hasIn()
console.log(foo.has('bar')); // => false
console.log(foo.hasIn(['bar'])); // => true (expected false)
@dashed
Copy link
Contributor Author

dashed commented May 28, 2015

Using immutable@3.7.3.

@leebyron
Copy link
Collaborator

Thank you for the report!

@leebyron leebyron added the bug label May 28, 2015
@dashed
Copy link
Contributor Author

dashed commented May 28, 2015

I tried other types of keys:

const {List} = require('immutable');

const foo = List();

[
    'bar',
    true,
    false,
    null,
    void 0,
    {},
    42,
    42.5
].forEach(function(key) {

    const NOT_SET = {};

    let ret = false;

    ret = (foo.get(key, NOT_SET) !== NOT_SET) || ret;
    ret = (foo.getIn([key], NOT_SET) !== NOT_SET) || ret;

    ret = foo.has(key) || ret;
    ret = foo.hasIn([key]) || ret;

    if(ret) {
        console.log('broken for key', key);
    }
});
// broken for key bar
// broken for key undefined
// broken for key {}

@leebyron
Copy link
Collaborator

Thanks for your investigation!

@dashed dashed changed the title get or getIn on List using a string key does not return correct notSetValue get or getIn on List using a key that is a string, object, or void 0 does not return correct notSetValue May 28, 2015
@mhagmajer
Copy link

+1

@mhagmajer
Copy link

Immutable.List([7]).getIn(0) // throws error whereas 7 was expected
Immutable.List([7]).getIn('0') // returns 7 as expected

@leebyron
Copy link
Collaborator

leebyron commented Aug 1, 2016

It looks like the second should probably also throw an error. getIn expects an Iterable collection of keys. Strings are Iterable but often not considered collections because that leads to confusion.

Would you please open a separate issue for this other issue?

@mhagmajer
Copy link

Thanks @leebyron, I realized that I was calling getIn incorrectly. I created a new issue at #940 for strings in getIn.

@leebyron leebyron closed this as completed Mar 4, 2017
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