From 805cdb43fd02c3a5783c06b5ec2c9519be0682ab Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Mon, 22 Jan 2024 22:13:23 -0500 Subject: [PATCH] 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 --- src/data/Data.js | 2 +- src/effects.js | 2 +- src/manipulation.js | 24 ++++++++---------------- src/manipulation/domManip.js | 2 +- src/queue.js | 4 ++-- 5 files changed, 13 insertions(+), 21 deletions(-) diff --git a/src/data/Data.js b/src/data/Data.js index 2a3ccbd14..25c8c64aa 100644 --- a/src/data/Data.js +++ b/src/data/Data.js @@ -61,7 +61,7 @@ Data.prototype = { cache[ camelCase( prop ) ] = data[ prop ]; } } - return cache; + return value; }, get: function( owner, key ) { return key === undefined ? diff --git a/src/effects.js b/src/effects.js index 3c1bd33fd..b94e2a488 100644 --- a/src/effects.js +++ b/src/effects.js @@ -206,7 +206,7 @@ function defaultPrefilter( elem, props, opts ) { hidden = dataShow.hidden; } } else { - dataShow = dataPriv.access( elem, "fxshow", { display: restoreDisplay } ); + dataShow = dataPriv.set( elem, "fxshow", { display: restoreDisplay } ); } // Store hidden/visible for toggle so `.stop().toggle()` "reverses" diff --git a/src/manipulation.js b/src/manipulation.js index c4bda4b5a..41cb8eadb 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -35,34 +35,26 @@ function manipulationTarget( elem, content ) { } 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 ) { return; } // 1. Copy private data: events, handlers, etc. - if ( dataPriv.hasData( src ) ) { - pdataOld = dataPriv.get( src ); - events = pdataOld.events; - - if ( events ) { - 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 ] ); - } + if ( events ) { + 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 if ( dataUser.hasData( src ) ) { - udataOld = dataUser.access( src ); - udataCur = jQuery.extend( {}, udataOld ); - - dataUser.set( dest, udataCur ); + dataUser.set( dest, jQuery.extend( {}, dataUser.get( src ) ) ); } } diff --git a/src/manipulation/domManip.js b/src/manipulation/domManip.js index 39c146c89..ef7b9a733 100644 --- a/src/manipulation/domManip.js +++ b/src/manipulation/domManip.js @@ -82,7 +82,7 @@ export function domManip( collection, args, callback, ignored ) { for ( i = 0; i < hasScripts; i++ ) { node = scripts[ i ]; if ( rscriptType.test( node.type || "" ) && - !dataPriv.access( node, "globalEval" ) && + !dataPriv.get( node, "globalEval" ) && jQuery.contains( doc, node ) ) { if ( node.src && ( node.type || "" ).toLowerCase() !== "module" ) { diff --git a/src/queue.js b/src/queue.js index 3621eaf45..306dbcff8 100644 --- a/src/queue.js +++ b/src/queue.js @@ -15,7 +15,7 @@ jQuery.extend( { // Speed up dequeue by getting out quickly if this is just a lookup if ( data ) { if ( !queue || Array.isArray( data ) ) { - queue = dataPriv.access( elem, type, jQuery.makeArray( data ) ); + queue = dataPriv.set( elem, type, jQuery.makeArray( data ) ); } else { queue.push( data ); } @@ -62,7 +62,7 @@ jQuery.extend( { // Not public - generate a queueHooks object, or return the current one _queueHooks: function( elem, type ) { 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() { dataPriv.remove( elem, [ type + "queue", key ] ); } ) -- 2.39.5