Skip to content

Commit

Permalink
Data: do not create data cache when fetching single property
Browse files Browse the repository at this point in the history
Closes gh-2554
  • Loading branch information
jbedard authored and mgol committed Sep 7, 2015
1 parent 5adf04a commit f5bf9bc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/data/Data.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -72,13 +72,11 @@ Data.prototype = {
return cache; return cache;
}, },
get: function( owner, key ) { get: function( owner, key ) {
var cache = this.cache( owner );

return key === undefined ? return key === undefined ?
cache : this.cache( owner ) :


// Always use camelCase key (gh-2257) // Always use camelCase key (gh-2257)
cache[ jQuery.camelCase( key ) ]; owner[ this.expando ] && owner[ this.expando ][ jQuery.camelCase( key ) ];
}, },
access: function( owner, key, value ) { access: function( owner, key, value ) {


Expand Down
16 changes: 16 additions & 0 deletions test/unit/data.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -882,3 +882,19 @@ QUnit.test( "Check that the expando is removed when there's no more data", funct
} }
} }
} ); } );

QUnit.test( ".data(prop) does not create expando", function( assert ) {
assert.expect( 1 );

var key,
div = jQuery( "<div/>" );

div.data("foo");
assert.equal( false, jQuery.hasData( div[0] ) );
// Make sure no expando has been added
for ( key in div[ 0 ] ) {
if ( /^jQuery/.test( key ) ) {
assert.ok( false, "Expando was created on access" );
}
}
} );

0 comments on commit f5bf9bc

Please sign in to comment.