Fixed issue for undefined data values that breaks chaining #501
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Added a check in $el.data(key,val) that looks to see whether or not a value was submitted rather than whether or not a value is undefined.
Looking for definededness causes the return value to be the previously stored data for the key rather than the calling element. This can break subsequent calls in a chain, eg
var foo = 1;
var bar;
$(element).data('foo', foo).data('bar',bar).appendTo(otherElement)
This chain would error out because the second attempt at setting data, for key 'bar', would try to return the original value for the key instead of attempting to set the value and returning the calling element.
You still can't set the data to undefined, that pre-existing concern already seems to be explicitly checked and prevented in jQuery.data(), this fix just ensures that the chain remains stable under what would likely be the most common expectation.
I think setting a value to undefined is a valid use case, though, and would be easily addressed by removing lines 102 and 104, but I don't know enough about the reasoning behind disallowing it to suggest this right now.