Skip to content

Commit

Permalink
No ticket. Use data_priv methods instead of jQuery._removeData and jQ…
Browse files Browse the repository at this point in the history
…uery._data; Remove needless, internal second argument of jQuery.cleanData. Closes gh-1234
  • Loading branch information
markelog authored and rwaldron committed Apr 8, 2013
1 parent 1a39396 commit e873141
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 35 deletions.
4 changes: 2 additions & 2 deletions src/attributes.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -131,14 +131,14 @@ jQuery.fn.extend({
} else if ( type === core_strundefined || type === "boolean" ) { } else if ( type === core_strundefined || type === "boolean" ) {
if ( this.className ) { if ( this.className ) {
// store className if set // store className if set
jQuery._data( this, "__className__", this.className ); data_priv.set( this, "__className__", this.className );
} }


// If the element has a class name or if we're passed "false", // If the element has a class name or if we're passed "false",
// then remove the whole classname (if there was one, the above saved it). // then remove the whole classname (if there was one, the above saved it).
// Otherwise bring back whatever was previously saved (if anything), // Otherwise bring back whatever was previously saved (if anything),
// falling back to the empty string if nothing was stored. // falling back to the empty string if nothing was stored.
this.className = this.className || value === false ? "" : jQuery._data( this, "__className__" ) || ""; this.className = this.className || value === false ? "" : data_priv.get( this, "__className__" ) || "";
} }
}); });
}, },
Expand Down
6 changes: 3 additions & 3 deletions src/css.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function showHide( elements, show ) {
continue; continue;
} }


values[ index ] = jQuery._data( elem, "olddisplay" ); values[ index ] = data_priv.get( elem, "olddisplay" );
display = elem.style.display; display = elem.style.display;
if ( show ) { if ( show ) {
// Reset the inline display of this element to learn if it is // Reset the inline display of this element to learn if it is
Expand All @@ -78,15 +78,15 @@ function showHide( elements, show ) {
// in a stylesheet to whatever the default browser style is // in a stylesheet to whatever the default browser style is
// for such an element // for such an element
if ( elem.style.display === "" && isHidden( elem ) ) { if ( elem.style.display === "" && isHidden( elem ) ) {
values[ index ] = jQuery._data( elem, "olddisplay", css_defaultDisplay(elem.nodeName) ); values[ index ] = data_priv.access( elem, "olddisplay", css_defaultDisplay(elem.nodeName) );
} }
} else { } else {


if ( !values[ index ] ) { if ( !values[ index ] ) {
hidden = isHidden( elem ); hidden = isHidden( elem );


if ( display && display !== "none" || !hidden ) { if ( display && display !== "none" || !hidden ) {
jQuery._data( elem, "olddisplay", hidden ? display : jQuery.css( elem, "display" ) ); data_priv.set( elem, "olddisplay", hidden ? display : jQuery.css(elem, "display") );
} }
} }
} }
Expand Down
9 changes: 0 additions & 9 deletions src/data.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -183,15 +183,6 @@ Data.prototype = {
} }
}; };


// This will be used by remove()/cleanData() in manipulation to sever
// remaining references to node objects. One day we'll replace the dual
// arrays with a WeakMap and this won't be an issue.
// (Splices the data objects out of the internal cache arrays)
function data_discard( owner ) {
data_user.discard( owner );
data_priv.discard( owner );
}

// These may be used throughout the jQuery core codebase // These may be used throughout the jQuery core codebase
data_user = new Data(); data_user = new Data();
data_priv = new Data(); data_priv = new Data();
Expand Down
11 changes: 6 additions & 5 deletions src/effects.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ function defaultPrefilter( elem, props, opts ) {


length = handled.length; length = handled.length;
if ( length ) { if ( length ) {
dataShow = jQuery._data( elem, "fxshow" ) || jQuery._data( elem, "fxshow", {} ); dataShow = data_priv.get( elem, "fxshow" ) || data_priv.access( elem, "fxshow", {} );
if ( "hidden" in dataShow ) { if ( "hidden" in dataShow ) {
hidden = dataShow.hidden; hidden = dataShow.hidden;
} }
Expand All @@ -336,7 +336,8 @@ function defaultPrefilter( elem, props, opts ) {
} }
anim.done(function() { anim.done(function() {
var prop; var prop;
jQuery._removeData( elem, "fxshow" );
data_priv.remove( elem, "fxshow" );
for ( prop in orig ) { for ( prop in orig ) {
jQuery.style( elem, prop, orig[ prop ] ); jQuery.style( elem, prop, orig[ prop ] );
} }
Expand Down Expand Up @@ -479,7 +480,7 @@ jQuery.fn.extend({
anim.stop( true ); anim.stop( true );
}; };
// Empty animations, or finishing resolves immediately // Empty animations, or finishing resolves immediately
if ( empty || jQuery._data( this, "finish" ) ) { if ( empty || data_priv.get( this, "finish" ) ) {
anim.stop( true ); anim.stop( true );
} }
}; };
Expand Down Expand Up @@ -509,7 +510,7 @@ jQuery.fn.extend({
var dequeue = true, var dequeue = true,
index = type != null && type + "queueHooks", index = type != null && type + "queueHooks",
timers = jQuery.timers, timers = jQuery.timers,
data = jQuery._data( this ); data = data_priv.get( this );


if ( index ) { if ( index ) {
if ( data[ index ] && data[ index ].stop ) { if ( data[ index ] && data[ index ].stop ) {
Expand Down Expand Up @@ -545,7 +546,7 @@ jQuery.fn.extend({
} }
return this.each(function() { return this.each(function() {
var index, var index,
data = jQuery._data( this ), data = data_priv.get( this ),
queue = data[ type + "queue" ], queue = data[ type + "queue" ],
hooks = data[ type + "queueHooks" ], hooks = data[ type + "queueHooks" ],
timers = jQuery.timers, timers = jQuery.timers,
Expand Down
9 changes: 3 additions & 6 deletions src/event.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -196,10 +196,7 @@ jQuery.event = {
// Remove the expando if it's no longer used // Remove the expando if it's no longer used
if ( jQuery.isEmptyObject( events ) ) { if ( jQuery.isEmptyObject( events ) ) {
delete elemData.handle; delete elemData.handle;

data_priv.remove( elem, "events" );
// removeData also checks for emptiness and clears the expando if empty
// so use it instead of delete
jQuery._removeData( elem, "events" );
} }
}, },


Expand Down Expand Up @@ -287,7 +284,7 @@ jQuery.event = {
special.bindType || type; special.bindType || type;


// jQuery handler // jQuery handler
handle = ( jQuery._data( cur, "events" ) || {} )[ event.type ] && jQuery._data( cur, "handle" ); handle = ( data_priv.get( cur, "events" ) || {} )[ event.type ] && data_priv.get( cur, "handle" );
if ( handle ) { if ( handle ) {
handle.apply( cur, data ); handle.apply( cur, data );
} }
Expand Down Expand Up @@ -340,7 +337,7 @@ jQuery.event = {
var i, j, ret, matched, handleObj, var i, j, ret, matched, handleObj,
handlerQueue = [], handlerQueue = [],
args = core_slice.call( arguments ), args = core_slice.call( arguments ),
handlers = ( jQuery._data( this, "events" ) || {} )[ event.type ] || [], handlers = ( data_priv.get( this, "events" ) || {} )[ event.type ] || [],
special = jQuery.event.special[ event.type ] || {}; special = jQuery.event.special[ event.type ] || {};


// Use the fix-ed jQuery.Event rather than the (read-only) native event // Use the fix-ed jQuery.Event rather than the (read-only) native event
Expand Down
9 changes: 6 additions & 3 deletions src/manipulation.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ jQuery.extend({
return fragment; return fragment;
}, },


cleanData: function( elems, /* internal */ acceptData ) { cleanData: function( elems ) {
var data, elem, type, var data, elem, type,
l = elems.length, l = elems.length,
i = 0, i = 0,
Expand All @@ -451,7 +451,7 @@ jQuery.extend({
for ( ; i < l; i++ ) { for ( ; i < l; i++ ) {
elem = elems[ i ]; elem = elems[ i ];


if ( acceptData || jQuery.acceptData( elem ) ) { if ( jQuery.acceptData( elem ) ) {


data = data_priv.access( elem ); data = data_priv.access( elem );


Expand All @@ -468,7 +468,10 @@ jQuery.extend({
} }
} }
// Discard any remaining `private` and `user` data // Discard any remaining `private` and `user` data
data_discard( elem ); // One day we'll replace the dual arrays with a WeakMap and this won't be an issue.
// (Splices the data objects out of the internal cache arrays)
data_user.discard( elem );
data_priv.discard( elem );
} }
} }
}); });
Expand Down
13 changes: 6 additions & 7 deletions src/queue.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ jQuery.extend({


if ( elem ) { if ( elem ) {
type = ( type || "fx" ) + "queue"; type = ( type || "fx" ) + "queue";
queue = jQuery._data( elem, type ); queue = data_priv.get( elem, type );


// Speed up dequeue by getting out quickly if this is just a lookup // Speed up dequeue by getting out quickly if this is just a lookup
if ( data ) { if ( data ) {
if ( !queue || jQuery.isArray(data) ) { if ( !queue || jQuery.isArray( data ) ) {
queue = jQuery._data( elem, type, jQuery.makeArray(data) ); queue = data_priv.access( elem, type, jQuery.makeArray(data) );
} else { } else {
queue.push( data ); queue.push( data );
} }
Expand Down Expand Up @@ -57,10 +57,9 @@ jQuery.extend({
// not intended for public consumption - generates a queueHooks object, or returns the current one // not intended for public consumption - generates a queueHooks object, or returns the current one
_queueHooks: function( elem, type ) { _queueHooks: function( elem, type ) {
var key = type + "queueHooks"; var key = type + "queueHooks";
return jQuery._data( elem, key ) || jQuery._data( elem, key, { return data_priv.get( elem, key ) || data_priv.access( elem, key, {
empty: jQuery.Callbacks("once memory").add(function() { empty: jQuery.Callbacks("once memory").add(function() {
jQuery._removeData( elem, type + "queue" ); data_priv.remove( elem, [ type + "queue", key ] );
jQuery._removeData( elem, key );
}) })
}); });
} }
Expand Down Expand Up @@ -135,7 +134,7 @@ jQuery.fn.extend({
type = type || "fx"; type = type || "fx";


while( i-- ) { while( i-- ) {
tmp = jQuery._data( elements[ i ], type + "queueHooks" ); tmp = data_priv.get( elements[ i ], type + "queueHooks" );
if ( tmp && tmp.empty ) { if ( tmp && tmp.empty ) {
count++; count++;
tmp.empty.add( resolve ); tmp.empty.add( resolve );
Expand Down

0 comments on commit e873141

Please sign in to comment.