Skip to content

Commit b5f7c9e

Browse files
jbedardmgol
authored andcommitted
Data: Combine register and cache methods
Closes gh-2553
1 parent ce3b4a6 commit b5f7c9e

File tree

1 file changed

+27
-33
lines changed

1 file changed

+27
-33
lines changed

src/data/Data.js

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,44 +12,38 @@ Data.uid = 1;
1212

1313
Data.prototype = {
1414

15-
register: function( owner ) {
16-
var value = {};
17-
18-
// If it is a node unlikely to be stringify-ed or looped over
19-
// use plain assignment
20-
if ( owner.nodeType ) {
21-
owner[ this.expando ] = value;
22-
23-
// Otherwise secure it in a non-enumerable property
24-
// configurable must be true to allow the property to be
25-
// deleted when data is removed
26-
} else {
27-
Object.defineProperty( owner, this.expando, {
28-
value: value,
29-
configurable: true
30-
} );
31-
}
32-
return owner[ this.expando ];
33-
},
3415
cache: function( owner ) {
3516

36-
// We can accept data for non-element nodes in modern browsers,
37-
// but we should not, see #8335.
38-
// Always return an empty object.
39-
if ( !acceptData( owner ) ) {
40-
return {};
41-
}
42-
4317
// Check if the owner object already has a cache
44-
var cache = owner[ this.expando ];
45-
46-
// If so, return it
47-
if ( cache ) {
48-
return cache;
18+
var value = owner[ this.expando ];
19+
20+
// If not, create one
21+
if ( !value ) {
22+
value = {};
23+
24+
// We can accept data for non-element nodes in modern browsers,
25+
// but we should not, see #8335.
26+
// Always return an empty object.
27+
if ( acceptData( owner ) ) {
28+
29+
// If it is a node unlikely to be stringify-ed or looped over
30+
// use plain assignment
31+
if ( owner.nodeType ) {
32+
owner[ this.expando ] = value;
33+
34+
// Otherwise secure it in a non-enumerable property
35+
// configurable must be true to allow the property to be
36+
// deleted when data is removed
37+
} else {
38+
Object.defineProperty( owner, this.expando, {
39+
value: value,
40+
configurable: true
41+
} );
42+
}
43+
}
4944
}
5045

51-
// If not, register one
52-
return this.register( owner );
46+
return value;
5347
},
5448
set: function( owner, data, value ) {
5549
var prop,

0 commit comments

Comments
 (0)