Side navigation
#10544 closed bug (fixed)
Opened October 20, 2011 02:24PM UTC
Closed November 01, 2012 01:30AM UTC
Remove ALL special meanings of "." in keys for $.fn.data
Reported by: | Darsain | Owned by: | dmethvin |
---|---|---|---|
Priority: | low | Milestone: | 1.9 |
Component: | data | Version: | 1.2.6 |
Keywords: | Cc: | dmethvin | |
Blocked by: | Blocking: |
Description
$.fn.data() doesn't behave the same way how $.data() does when using a key namespacing.
Example: if you have a data key "name.key" and it doesn't exist, the $.fn.data() will return the "name" key instead, while $.data() returns undefined, which is what I'd expect to get
Test: http://jsfiddle.net/pNCP8/3/ (test is for 1.6.4, but 1.7b2 has the same issue)
Fix:
@@ -1943,9 +1943,7 @@ data = dataAttr( this[0], key, data ); } - return data === undefined && parts[1] ? - this.data( parts[0] ) : - data; + return data; } else { return this.each(function() {
Now, since I see that it is deliberately coded that way, I don't know if this is a bug, or a "feature". I've asked on #jquery-dev, but after a few hours of no reply I'm just posting it here. In case of a "feature" decision, I'd like to know the resoning behind it :)
Attachments (0)
Change History (11)
Changed October 20, 2011 04:17PM UTC by comment:1
component: | unfiled → data |
---|---|
keywords: | → needsreview |
priority: | undecided → low |
Changed October 20, 2011 04:18PM UTC by comment:2
Our docs don't appear to state whether or not namespaced keys are officially supported, but let me find out and I'll post back on this ticket (unless someone is able to answer before that).
Changed October 20, 2011 04:35PM UTC by comment:3
cc: | → DaveMethvin, dmethvin |
---|---|
owner: | → gnarf |
status: | new → assigned |
Confirmed with @gnarf that this is a bug. CC'ing DaveMethvin for further input.
Changed October 20, 2011 06:26PM UTC by comment:4
_comment0: | Actualy, seems I was wrong about it being a bug... I'm not sure WHY we are doing this, but it is a unit tested feature: \ \ Unit tests are here: \ \ https://github.com/jquery/jquery/blob/f2c1d2e016018ba14cd3f1612f9a1803d5e1709e/test/unit/data.js#L246-283 \ \ I can't seem to find the trac ticket that details this feature. \ \ It is currently not documented, so we should document it if we plan on keeping it around. I'm not sure how many people are using it. → 1319135627646868 |
---|---|
cc: | DaveMethvin, dmethvin → DaveMethvin, dmethvin, kswedberg |
keywords: | needsreview → needsreview needsdocs |
Actualy, seems I was wrong about it being a bug... I'm not sure WHY we are doing this, but it is a unit tested feature:
Unit tests are here:
I can't seem to find the trac ticket that details this feature.
It is currently not documented, so we should document it if we plan on keeping it around. I'm not sure how many people are using it.
Personally, I don't think we should be supporting "namespaced" data
Changed October 20, 2011 08:01PM UTC by comment:5
_comment0: | After a discussion in IRC with timmy and dave, we have tentatively decided that because of the potential for dependency on this behavior is quite high, especially considering this behavior extends as far back as jQuery 1.2.6: http://jsfiddle.net/gnarf/pNCP8/4/ \ \ Our current strategy is to mark this "namespaced data" and the special meaning the dot has in the {{{getData}}} and {{{setData}}} events as deprecated as of 1.7. We will document the current (deprecated) behavior - and then set it up for removal in 1.8. → 1319141094535758 |
---|---|
_comment1: | After a discussion in IRC with timmy and dave, we have tentatively decided that the potential for dependency on this behavior is quite high, especially considering this behavior extends as far back as jQuery 1.2.6: http://jsfiddle.net/gnarf/pNCP8/4/ \ \ Our current strategy is to mark this "namespaced data" and the special meaning the dot has in the {{{getData}}} and {{{setData}}} events as deprecated as of 1.7. We will document the current (deprecated) behavior - and then set it up for removal in 1.8. → 1319141124060383 |
milestone: | None → 1.8 |
summary: | Different behavior between $.fn.data() and $.data() with namespaced key names → Remove ALL special meanings of "." in keys for $.fn.data |
version: | 1.7b2 → 1.2.6 |
After a discussion in IRC with timmy and dave, we have tentatively decided that the potential for dependency on this behavior is quite high, especially considering this behavior extends as far back as jQuery 1.2.6: http://jsfiddle.net/gnarf/pNCP8/4/ We also agree that this behavior is broken, and should be removed.
Our current strategy is to mark this "namespaced data" and the special meaning the dot has in the
getDataand
setDataevents as deprecated as of 1.7. We will document the current (deprecated) behavior - and then set it up for removal in 1.8.
Changed October 24, 2011 03:44PM UTC by comment:6
As a workaround for the OP of this bug ticket. You can always get your key via
.data()["foo.bar"]
Changed October 24, 2011 03:54PM UTC by comment:7
Following a further discussion on IRC, it appears that we *may* opt to add a notice about this being deprecated in the 1.7 release post as opposed to having it mentioned in the docs. Given that the behaviour we have now was never documented, this probably makes the most sense.
Something along the lines of 'Using data keys that have a "." in them in jQuery 1.7 and below can cause some strange behaviors. These strange behaviors are being deprecated and will be removed in 1.8.' with specific references to namespacing if we want to be technically correct :)
JohnResig had some further concerns with this which may be mentioned at the next -meeting. Will update if the resolution changes.
Changed March 10, 2012 04:06PM UTC by comment:8
cc: | DaveMethvin, dmethvin, kswedberg → dmethvin, kswedberg |
---|
We're deprecating data events in 1.8 and removing them in 1.9 so this will sort itself out naturally.
Changed June 11, 2012 09:50PM UTC by comment:9
cc: | dmethvin, kswedberg → dmethvin |
---|---|
keywords: | needsreview needsdocs |
milestone: | 1.8 → 1.9 |
To be removed in 1.9 when data events die of natural causes. They were never documented so they don't need to be un-documented.
Changed November 01, 2012 01:20AM UTC by comment:10
owner: | gnarf → dmethvin |
---|
Changed November 01, 2012 01:30AM UTC by comment:11
resolution: | → fixed |
---|---|
status: | assigned → closed |
Fix #10544. Remove deprecated .data() event namespaced triggering.
Data events were horribly slow, never documented, and caused strange interpretation of data items with dots in them.
Changeset: e8cf41a051a62bf1f19beab1a5c1d643f121e28e