perf(jqLite): expose the low-level jqLite.data/removeData calls
- 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
This commit is contained in:
+14
-10
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
+1
-1
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user