Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cdb16ba

Browse files
committedMar 22, 2017
fix(jqLite): make jqLite invoke jqLite.cleanData as a method
The previous implementation of jqLite didn't use cleanData from the jqLite object but instead used a cached version which maede it impossible to monkey-patch jqLite.cleanData similarly to how you can do it in jQuery. This commit enables one of the tests so far run only with jQuery to run with jqLite as well. Ref #8486 Ref #8695
1 parent 233f47b commit cdb16ba

File tree

2 files changed

+41
-49
lines changed

2 files changed

+41
-49
lines changed
 

‎src/jqLite.js

+7-11
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,6 @@ function jqLiteHasData(node) {
201201
return false;
202202
}
203203

204-
function jqLiteCleanData(nodes) {
205-
for (var i = 0, ii = nodes.length; i < ii; i++) {
206-
jqLiteRemoveData(nodes[i]);
207-
}
208-
}
209-
210204
function jqLiteBuildFragment(html, context) {
211205
var tmp, tag, wrap,
212206
fragment = context.createDocumentFragment(),
@@ -309,13 +303,11 @@ function jqLiteClone(element) {
309303
}
310304

311305
function jqLiteDealoc(element, onlyDescendants) {
312-
if (!onlyDescendants) jqLiteRemoveData(element);
306+
if (!onlyDescendants && element.nodeType === NODE_TYPE_ELEMENT) jqLite.cleanData([element]);
313307

314308
if (element.querySelectorAll) {
315309
var descendants = element.querySelectorAll('*');
316-
for (var i = 0, l = descendants.length; i < l; i++) {
317-
jqLiteRemoveData(descendants[i]);
318-
}
310+
jqLite.cleanData(descendants);
319311
}
320312
}
321313

@@ -613,7 +605,11 @@ forEach({
613605
data: jqLiteData,
614606
removeData: jqLiteRemoveData,
615607
hasData: jqLiteHasData,
616-
cleanData: jqLiteCleanData
608+
cleanData: function jqLiteCleanData(nodes) {
609+
for (var i = 0, ii = nodes.length; i < ii; i++) {
610+
jqLiteRemoveData(nodes[i]);
611+
}
612+
}
617613
}, function(fn, name) {
618614
JQLite[name] = fn;
619615
});

‎test/ng/compileSpec.js

+34-38
Original file line numberDiff line numberDiff line change
@@ -2100,28 +2100,26 @@ describe('$compile', function() {
21002100

21012101
it('should work in jqLite and jQuery with jQuery.cleanData last patched by Angular', runTest);
21022102

2103-
if (jQuery) {
2104-
it('should work with another library patching jQuery.cleanData after Angular', function() {
2105-
var cleanedCount = 0;
2106-
var currentCleanData = jqLite.cleanData;
2107-
jqLite.cleanData = function(elems) {
2108-
cleanedCount += elems.length;
2109-
// Don't return the output and explicitly pass only the first parameter
2110-
// so that we're sure we're not relying on either of them. jQuery UI patch
2111-
// behaves in this way.
2112-
currentCleanData(elems);
2113-
};
2103+
it('should work with another library patching jqLite/jQuery.cleanData after Angular', function() {
2104+
var cleanedCount = 0;
2105+
var currentCleanData = jqLite.cleanData;
2106+
jqLite.cleanData = function(elems) {
2107+
cleanedCount += elems.length;
2108+
// Don't return the output and explicitly pass only the first parameter
2109+
// so that we're sure we're not relying on either of them. jQuery UI patch
2110+
// behaves in this way.
2111+
currentCleanData(elems);
2112+
};
21142113

2115-
runTest();
2114+
runTest();
21162115

2117-
// The initial ng-repeat div is dumped after parsing hence we expect cleanData
2118-
// count to be one larger than size of the iterated array.
2119-
expect(cleanedCount).toBe(is.length + 1);
2116+
// The initial ng-repeat div is dumped after parsing hence we expect cleanData
2117+
// count to be one larger than size of the iterated array.
2118+
expect(cleanedCount).toBe(is.length + 1);
21202119

2121-
// Restore the previous cleanData.
2122-
jqLite.cleanData = currentCleanData;
2123-
});
2124-
}
2120+
// Restore the previous cleanData.
2121+
jqLite.cleanData = currentCleanData;
2122+
});
21252123
});
21262124

21272125
describe('replace and not exactly one root element', function() {
@@ -8640,28 +8638,26 @@ describe('$compile', function() {
86408638

86418639
it('should work without external libraries (except jQuery)', testCleanup);
86428640

8643-
if (jQuery) {
8644-
it('should work with another library patching jQuery.cleanData after AngularJS', function() {
8645-
var cleanedCount = 0;
8646-
var currentCleanData = jqLite.cleanData;
8647-
jqLite.cleanData = function(elems) {
8648-
cleanedCount += elems.length;
8649-
// Don't return the output and explicitly pass only the first parameter
8650-
// so that we're sure we're not relying on either of them. jQuery UI patch
8651-
// behaves in this way.
8652-
currentCleanData(elems);
8653-
};
8641+
it('should work with another library patching jqLite/jQuery.cleanData after AngularJS', function() {
8642+
var cleanedCount = 0;
8643+
var currentCleanData = jqLite.cleanData;
8644+
jqLite.cleanData = function(elems) {
8645+
cleanedCount += elems.length;
8646+
// Don't return the output and explicitly pass only the first parameter
8647+
// so that we're sure we're not relying on either of them. jQuery UI patch
8648+
// behaves in this way.
8649+
currentCleanData(elems);
8650+
};
86548651

8655-
testCleanup();
8652+
testCleanup();
86568653

8657-
// The ng-repeat template is removed/cleaned (the +1)
8658-
// and each clone of the ng-repeat template is also removed (xs.length)
8659-
expect(cleanedCount).toBe(xs.length + 1);
8654+
// The ng-repeat template is removed/cleaned (the +1)
8655+
// and each clone of the ng-repeat template is also removed (xs.length)
8656+
expect(cleanedCount).toBe(xs.length + 1);
86608657

8661-
// Restore the previous cleanData.
8662-
jqLite.cleanData = currentCleanData;
8663-
});
8664-
}
8658+
// Restore the previous cleanData.
8659+
jqLite.cleanData = currentCleanData;
8660+
});
86658661
});
86668662

86678663

0 commit comments

Comments
 (0)
This repository has been archived.