mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Data: Refactor to reduce size
* Return the new value from `set(owner, key, value)`. * Use `set(owner, key, value)` rather than `access(owner, key, value)`. Close gh-5392
This commit is contained in:
parent
af79c99939
commit
805cdb43fd
@ -61,7 +61,7 @@ Data.prototype = {
|
|||||||
cache[ camelCase( prop ) ] = data[ prop ];
|
cache[ camelCase( prop ) ] = data[ prop ];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return cache;
|
return value;
|
||||||
},
|
},
|
||||||
get: function( owner, key ) {
|
get: function( owner, key ) {
|
||||||
return key === undefined ?
|
return key === undefined ?
|
||||||
|
2
src/effects.js
vendored
2
src/effects.js
vendored
@ -206,7 +206,7 @@ function defaultPrefilter( elem, props, opts ) {
|
|||||||
hidden = dataShow.hidden;
|
hidden = dataShow.hidden;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
dataShow = dataPriv.access( elem, "fxshow", { display: restoreDisplay } );
|
dataShow = dataPriv.set( elem, "fxshow", { display: restoreDisplay } );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store hidden/visible for toggle so `.stop().toggle()` "reverses"
|
// Store hidden/visible for toggle so `.stop().toggle()` "reverses"
|
||||||
|
@ -35,34 +35,26 @@ function manipulationTarget( elem, content ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function cloneCopyEvent( src, dest ) {
|
function cloneCopyEvent( src, dest ) {
|
||||||
var i, l, type, pdataOld, udataOld, udataCur, events;
|
var type, i, l,
|
||||||
|
events = dataPriv.get( src, "events" );
|
||||||
|
|
||||||
if ( dest.nodeType !== 1 ) {
|
if ( dest.nodeType !== 1 ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1. Copy private data: events, handlers, etc.
|
// 1. Copy private data: events, handlers, etc.
|
||||||
if ( dataPriv.hasData( src ) ) {
|
if ( events ) {
|
||||||
pdataOld = dataPriv.get( src );
|
dataPriv.remove( dest, "handle events" );
|
||||||
events = pdataOld.events;
|
for ( type in events ) {
|
||||||
|
for ( i = 0, l = events[ type ].length; i < l; i++ ) {
|
||||||
if ( events ) {
|
jQuery.event.add( dest, type, events[ type ][ i ] );
|
||||||
dataPriv.remove( dest, "handle events" );
|
|
||||||
|
|
||||||
for ( type in events ) {
|
|
||||||
for ( i = 0, l = events[ type ].length; i < l; i++ ) {
|
|
||||||
jQuery.event.add( dest, type, events[ type ][ i ] );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Copy user data
|
// 2. Copy user data
|
||||||
if ( dataUser.hasData( src ) ) {
|
if ( dataUser.hasData( src ) ) {
|
||||||
udataOld = dataUser.access( src );
|
dataUser.set( dest, jQuery.extend( {}, dataUser.get( src ) ) );
|
||||||
udataCur = jQuery.extend( {}, udataOld );
|
|
||||||
|
|
||||||
dataUser.set( dest, udataCur );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ export function domManip( collection, args, callback, ignored ) {
|
|||||||
for ( i = 0; i < hasScripts; i++ ) {
|
for ( i = 0; i < hasScripts; i++ ) {
|
||||||
node = scripts[ i ];
|
node = scripts[ i ];
|
||||||
if ( rscriptType.test( node.type || "" ) &&
|
if ( rscriptType.test( node.type || "" ) &&
|
||||||
!dataPriv.access( node, "globalEval" ) &&
|
!dataPriv.get( node, "globalEval" ) &&
|
||||||
jQuery.contains( doc, node ) ) {
|
jQuery.contains( doc, node ) ) {
|
||||||
|
|
||||||
if ( node.src && ( node.type || "" ).toLowerCase() !== "module" ) {
|
if ( node.src && ( node.type || "" ).toLowerCase() !== "module" ) {
|
||||||
|
@ -15,7 +15,7 @@ jQuery.extend( {
|
|||||||
// 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 || Array.isArray( data ) ) {
|
if ( !queue || Array.isArray( data ) ) {
|
||||||
queue = dataPriv.access( elem, type, jQuery.makeArray( data ) );
|
queue = dataPriv.set( elem, type, jQuery.makeArray( data ) );
|
||||||
} else {
|
} else {
|
||||||
queue.push( data );
|
queue.push( data );
|
||||||
}
|
}
|
||||||
@ -62,7 +62,7 @@ jQuery.extend( {
|
|||||||
// Not public - generate a queueHooks object, or return the current one
|
// Not public - generate a queueHooks object, or return the current one
|
||||||
_queueHooks: function( elem, type ) {
|
_queueHooks: function( elem, type ) {
|
||||||
var key = type + "queueHooks";
|
var key = type + "queueHooks";
|
||||||
return dataPriv.get( elem, key ) || dataPriv.access( elem, key, {
|
return dataPriv.get( elem, key ) || dataPriv.set( elem, key, {
|
||||||
empty: jQuery.Callbacks( "once memory" ).add( function() {
|
empty: jQuery.Callbacks( "once memory" ).add( function() {
|
||||||
dataPriv.remove( elem, [ type + "queue", key ] );
|
dataPriv.remove( elem, [ type + "queue", key ] );
|
||||||
} )
|
} )
|
||||||
|
Loading…
Reference in New Issue
Block a user