Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
perf(jqLite): expose the low-level jqLite.data/removeData calls
Browse files Browse the repository at this point in the history
- updated the internal jqLite helpers to use the low-level jqLite.data/removeData to avoid unnecessary jq wrappers and loops
- updated $compile to use the low-level jqLite.data/removeData to avoid unnecessary jq wrappers at link time
  • Loading branch information
jbedard authored and rodyhaddad committed Jul 18, 2014
1 parent 71eb190 commit 3c46c94
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
24 changes: 14 additions & 10 deletions src/jqLite.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,25 +417,22 @@ function jqLiteController(element, name) {
}

function jqLiteInheritedData(element, name, value) {
element = jqLite(element);

// if element is the document object work with the html element instead
// this makes $(document).scope() possible
if(element[0].nodeType == 9) {
element = element.find('html');
if(element.nodeType == 9) {
element = element.documentElement;
}
var names = isArray(name) ? name : [name];

while (element.length) {
var node = element[0];
while (element) {
for (var i = 0, ii = names.length; i < ii; i++) {
if ((value = element.data(names[i])) !== undefined) return value;
if ((value = jqLite.data(element, names[i])) !== undefined) return value;
}

// If dealing with a document fragment node with a host element, and no parent, use the host
// element as the parent. This enables directives within a Shadow DOM or polyfilled Shadow DOM
// to lookup parent controllers.
element = jqLite(node.parentNode || (node.nodeType === 11 && node.host));
element = element.parentNode || (element.nodeType === 11 && element.host);
}
}

Expand Down Expand Up @@ -510,18 +507,25 @@ function getBooleanAttrName(element, name) {
return booleanAttr && BOOLEAN_ELEMENTS[element.nodeName] && booleanAttr;
}

forEach({
data: jqLiteData,
removeData: jqLiteRemoveData
}, function(fn, name) {
JQLite[name] = fn;
});

forEach({
data: jqLiteData,
inheritedData: jqLiteInheritedData,

scope: function(element) {
// Can't use jqLiteData here directly so we stay compatible with jQuery!
return jqLite(element).data('$scope') || jqLiteInheritedData(element.parentNode || element, ['$isolateScope', '$scope']);
return jqLite.data(element, '$scope') || jqLiteInheritedData(element.parentNode || element, ['$isolateScope', '$scope']);
},

isolateScope: function(element) {
// Can't use jqLiteData here directly so we stay compatible with jQuery!
return jqLite(element).data('$isolateScope') || jqLite(element).data('$isolateScopeNoTemplate');
return jqLite.data(element, '$isolateScope') || jqLite.data(element, '$isolateScopeNoTemplate');
},

controller: jqLiteController,
Expand Down
2 changes: 1 addition & 1 deletion src/ng/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
if (nodeLinkFn) {
if (nodeLinkFn.scope) {
childScope = scope.$new();
jqLite(node).data('$scope', childScope);
jqLite.data(node, '$scope', childScope);
} else {
childScope = scope;
}
Expand Down

0 comments on commit 3c46c94

Please sign in to comment.