Skip to content

Commit 805cdb4

Browse files
authored
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
1 parent af79c99 commit 805cdb4

File tree

5 files changed

+13
-21
lines changed

5 files changed

+13
-21
lines changed

src/data/Data.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Data.prototype = {
6161
cache[ camelCase( prop ) ] = data[ prop ];
6262
}
6363
}
64-
return cache;
64+
return value;
6565
},
6666
get: function( owner, key ) {
6767
return key === undefined ?

src/effects.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ function defaultPrefilter( elem, props, opts ) {
206206
hidden = dataShow.hidden;
207207
}
208208
} else {
209-
dataShow = dataPriv.access( elem, "fxshow", { display: restoreDisplay } );
209+
dataShow = dataPriv.set( elem, "fxshow", { display: restoreDisplay } );
210210
}
211211

212212
// Store hidden/visible for toggle so `.stop().toggle()` "reverses"

src/manipulation.js

+8-16
Original file line numberDiff line numberDiff line change
@@ -35,34 +35,26 @@ function manipulationTarget( elem, content ) {
3535
}
3636

3737
function cloneCopyEvent( src, dest ) {
38-
var i, l, type, pdataOld, udataOld, udataCur, events;
38+
var type, i, l,
39+
events = dataPriv.get( src, "events" );
3940

4041
if ( dest.nodeType !== 1 ) {
4142
return;
4243
}
4344

4445
// 1. Copy private data: events, handlers, etc.
45-
if ( dataPriv.hasData( src ) ) {
46-
pdataOld = dataPriv.get( src );
47-
events = pdataOld.events;
48-
49-
if ( events ) {
50-
dataPriv.remove( dest, "handle events" );
51-
52-
for ( type in events ) {
53-
for ( i = 0, l = events[ type ].length; i < l; i++ ) {
54-
jQuery.event.add( dest, type, events[ type ][ i ] );
55-
}
46+
if ( events ) {
47+
dataPriv.remove( dest, "handle events" );
48+
for ( type in events ) {
49+
for ( i = 0, l = events[ type ].length; i < l; i++ ) {
50+
jQuery.event.add( dest, type, events[ type ][ i ] );
5651
}
5752
}
5853
}
5954

6055
// 2. Copy user data
6156
if ( dataUser.hasData( src ) ) {
62-
udataOld = dataUser.access( src );
63-
udataCur = jQuery.extend( {}, udataOld );
64-
65-
dataUser.set( dest, udataCur );
57+
dataUser.set( dest, jQuery.extend( {}, dataUser.get( src ) ) );
6658
}
6759
}
6860

src/manipulation/domManip.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export function domManip( collection, args, callback, ignored ) {
8282
for ( i = 0; i < hasScripts; i++ ) {
8383
node = scripts[ i ];
8484
if ( rscriptType.test( node.type || "" ) &&
85-
!dataPriv.access( node, "globalEval" ) &&
85+
!dataPriv.get( node, "globalEval" ) &&
8686
jQuery.contains( doc, node ) ) {
8787

8888
if ( node.src && ( node.type || "" ).toLowerCase() !== "module" ) {

src/queue.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jQuery.extend( {
1515
// Speed up dequeue by getting out quickly if this is just a lookup
1616
if ( data ) {
1717
if ( !queue || Array.isArray( data ) ) {
18-
queue = dataPriv.access( elem, type, jQuery.makeArray( data ) );
18+
queue = dataPriv.set( elem, type, jQuery.makeArray( data ) );
1919
} else {
2020
queue.push( data );
2121
}
@@ -62,7 +62,7 @@ jQuery.extend( {
6262
// Not public - generate a queueHooks object, or return the current one
6363
_queueHooks: function( elem, type ) {
6464
var key = type + "queueHooks";
65-
return dataPriv.get( elem, key ) || dataPriv.access( elem, key, {
65+
return dataPriv.get( elem, key ) || dataPriv.set( elem, key, {
6666
empty: jQuery.Callbacks( "once memory" ).add( function() {
6767
dataPriv.remove( elem, [ type + "queue", key ] );
6868
} )

0 commit comments

Comments
 (0)