Bug Tracker

Opened 8 years ago

Closed 8 years ago

Last modified 7 years ago

#10113 closed bug (wontfix)

Set internal null flag for data-attrs that are removed

Reported by: Rick Waldron Owned by: Rick Waldron
Priority: blocker Milestone: 1.7
Component: data Version: 1.6.2
Keywords: Cc: cowboy
Blocked by: Blocking:

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 (9)

comment:1 Changed 8 years ago by Rick Waldron

Component: unfileddata
Milestone: None1.6.3
Owner: set to Rick Waldron
Priority: undecidedblocker
Status: newassigned

comment:2 Changed 8 years 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.

  1. It's gonna be a lot slower to change the DOM every time you set data.
  2. 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 8 years ago by Rick Waldron

Further tests, thanks to Ben Alman http://jsfiddle.net/rwaldron/cAcgZ/

comment:4 Changed 8 years ago by timmywil

Blocking: 10026 added

comment:5 Changed 8 years ago by Rick Waldron

Milestone: 1.6.31.7

comment:6 Changed 8 years ago by Rick Waldron

Blocking: 10026 removed

comment:7 Changed 8 years 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 8 years ago by dmethvin

Keywords: needsdocs added
Resolution: wontfix
Status: assignedclosed

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.

comment:9 Changed 7 years ago by addyosmani

Keywords: needsdocs removed

Docs updated.

Note: See TracTickets for help on using tickets.