]> source.dussan.org Git - jquery.git/commitdiff
Data: Refactor to reduce size
authorRichard Gibson <richard.gibson@gmail.com>
Tue, 23 Jan 2024 03:13:23 +0000 (22:13 -0500)
committerGitHub <noreply@github.com>
Tue, 23 Jan 2024 03:13:23 +0000 (22:13 -0500)
* 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
src/effects.js
src/manipulation.js
src/manipulation/domManip.js
src/queue.js

index 2a3ccbd146be272a2ae8321eab3a2f469c750f29..25c8c64aae0eab2cf3718afc91e060423e77dea9 100644 (file)
@@ -61,7 +61,7 @@ Data.prototype = {
                                cache[ camelCase( prop ) ] = data[ prop ];
                        }
                }
-               return cache;
+               return value;
        },
        get: function( owner, key ) {
                return key === undefined ?
index 3c1bd33fd0b8fb41925432dfec179c27337b37c5..b94e2a48896727730e61bda3e76d347d5f6d5365 100644 (file)
@@ -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"
index c4bda4b5a1c57aab47847e6708ff7d43150e2002..41cb8eadbed3ee741bf6a3cc8aaa18b9b8138b5d 100644 (file)
@@ -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 ) ) );
        }
 }
 
index 39c146c89ef1016a9516d7c188ca1f44d89c8240..ef7b9a73304dc9dd7be46bfbb7a343d88e5599f6 100644 (file)
@@ -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" ) {
index 3621eaf45130c137307ec75802ca17c9d96b783d..306dbcff808db6d7740aa78f3e6449690170c3ab 100644 (file)
@@ -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 ] );
                        } )