Closed
Description
I'm not sure if this is an actual bug or if there is a decision behind this behavior.
Nonetheless, I would argue that it would be better for getIn()
to return undefined
in the case of an intermediary key not existing, because it would make for easier to read code. And it would also make sense since the value is "not defined" for all intents and purposes.
I have run into this issue with code like this:
var data = immutable.fromJS({
items: [ { name: 'Test' }, null, { name: 'Another test' } ]
});
var selectedItems = immutable.Set();
// Select all items
selectedItems = data.get('items').keySeq().toSet();
// Somewhere else:
selectedItems.map(function(id) {
var item = data.getIn(['items', id, 'name']); // Throws TypeError because of the null item
// [...]
});
Metadata
Metadata
Assignees
Labels
No labels