Ticket #10113 (closed bug: wontfix)
Set internal null flag for data-attrs that are removed
| Reported by: | rwaldron | Owned by: | rwaldron |
|---|---|---|---|
| Priority: | blocker | Milestone: | 1.7 |
| Component: | data | Version: | 1.6.2 |
| Keywords: | Cc: | cowboy | |
| Blocking: | Blocked by: |
Description
Instead of brute removal (as seen in my 10026), Ben Alman has suggested (and I agree) that removal should not actually touch the DOM (if possible), but instead keep an internal flag that notes that this data-attr has been removed - this state should be reflected in the object returned by calling .fn.data()
Change History
comment:1 Changed 21 months ago by rwaldron
- Owner set to rwaldron
- Priority changed from undecided to blocker
- Status changed from new to assigned
- Component changed from unfiled to data
- Milestone changed from None to 1.6.3
comment:2 Changed 21 months ago by cowboy
Yeah.. if you don't set an internal flag but instead change the attribute on $.fn.removeData then the behavior of $.fn.data(key, value) NOT changing the attr would be somewhat inconsistent. And you don't want to make that consistent by writing data to data attributes for 2 reasons.
- It's gonna be a lot slower to change the DOM every time you set data.
- How can you store complex data like functions and regexes in a data attribute string?
Anyways, I made an example fiddle. http://jsfiddle.net/cowboy/5GCgT/
Using data- attributes as declarative HTML that can be used by jQuery only to pre-populate $.fn.data(key) makes sense. And the $.fn.data and $.fn.removeData methods should never change or modify the underlying attribute.
comment:3 Changed 21 months ago by rwaldron
Further tests, thanks to Ben Alman http://jsfiddle.net/rwaldron/cAcgZ/
comment:7 Changed 20 months ago by dmethvin
- Cc cowboy added
Adding some kind of "been there done that" flag for this one special case seems like overkill. Perhaps the easiest solution is to document that if there is no property by that name in the internal data cache, we go out to look for data- attributes. If you don't want it to re-query the data- attribute, set the name to a value like null or undefined instead of using .removeData(). Does that sound reasonable?
comment:8 Changed 20 months ago by dmethvin
- Keywords needsdocs added
- Status changed from assigned to closed
- Resolution set to wontfix
OK, I'm closing this with the needsdocs tag.
jQuery.fn.data("name") will attempt to find a data- item again if you use .removeData("name"), so set it to null or undefined instead if you don't want that behavior.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
