Better $.rmAll

I verified an issue with the previous benchmark and even wrote a
more efficient method based off el.cloneNode(false);, which I would
use if cloneNode could inherit eventListeners

Speaking of events. there is still no interface for gather all
eventListeners on a given element (or its children). Apparently the
issue is that the w3c doesn't think there is a legitimate use case
for it. Heh.
This commit is contained in:
Zixaphir 2014-01-24 16:10:04 -07:00
parent b62d82bed0
commit 51ba83538a
4 changed files with 7 additions and 26 deletions

View File

@ -575,12 +575,7 @@
})();
$.rmAll = function(root) {
var node, _i, _len, _ref;
_ref = __slice.call(root.childNodes);
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
node = _ref[_i];
root.removeChild(node);
}
return root.textContent = '';
};
$.tn = function(s) {
@ -12156,13 +12151,11 @@
}
},
clean: function() {
var board;
g.threads.forEach(function(thread) {
return thread.collect();
});
QuoteBacklink.containers = {};
board = $('.board');
return $.replace(board, board.cloneNode(false));
return $.rmAll($('.board'));
},
features: [['Thread Excerpt', ThreadExcerpt], ['Unread Count', Unread], ['Quote Threading', QuoteThreading], ['Thread Stats', ThreadStats], ['Thread Updater', ThreadUpdater], ['Thread Expansion', ExpandThread]],
disconnect: function() {

View File

@ -552,12 +552,7 @@
})();
$.rmAll = function(root) {
var node, _i, _len, _ref;
_ref = __slice.call(root.childNodes);
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
node = _ref[_i];
root.removeChild(node);
}
return root.textContent = '';
};
$.tn = function(s) {
@ -12155,13 +12150,11 @@
}
},
clean: function() {
var board;
g.threads.forEach(function(thread) {
return thread.collect();
});
QuoteBacklink.containers = {};
board = $('.board');
return $.replace(board, board.cloneNode(false));
return $.rmAll($('.board'));
},
features: [['Thread Excerpt', ThreadExcerpt], ['Unread Count', Unread], ['Quote Threading', QuoteThreading], ['Thread Stats', ThreadStats], ['Thread Updater', ThreadUpdater], ['Thread Expansion', ExpandThread]],
disconnect: function() {

View File

@ -37,8 +37,7 @@ Navigate =
g.threads.forEach (thread) -> thread.collect()
QuoteBacklink.containers = {}
board = $('.board')
$.replace board, board.cloneNode false
$.rmAll $('.board')
features: [
['Thread Excerpt', ThreadExcerpt]

View File

@ -133,12 +133,8 @@ $.rm = do ->
else
(el) -> el.parentNode?.removeChild el
$.rmAll = (root) ->
# jsperf.com/emptify-element
for node in [root.childNodes...]
# HTMLSelectElement.remove !== Element.remove
root.removeChild node
return
# jsperf.com/emptify-element/9
$.rmAll = (root) -> root.textContent = ''
$.tn = (s) ->
d.createTextNode s