Skip to content

Commit

Permalink
Optimize element purging. (RStankov, Andrew Dupont)
Browse files Browse the repository at this point in the history
  • Loading branch information
savetheclocktower committed May 12, 2010
1 parent d9aee20 commit 9a752d7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* Optimize element purging. (RStankov, Andrew Dupont)

* Add `Element.purge` for cleaning up event listeners and element storage keys on elements that will be removed from the page. Make `Element.update` perform similar cleanup automatically. (Andrew Dupont, Tobie Langel)

* The second argument to Event.Handler callbacks is the target element when no selector is present, or the matching element when a selector is present. Callbacks are always bound to the original element. (sam)
Expand Down
9 changes: 4 additions & 5 deletions src/dom/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,10 @@ Element.cache = { };
// Performs cleanup on an element before it is removed from the page.
// See `Element#purge`.
function purgeElement(element) {
// Must go first because it relies on Element.Storage.
Element.stopObserving(element);

var uid = element._prototypeUID;
if (uid) {
// Must go first because it relies on Element.Storage.
Element.stopObserving(element);
element._prototypeUID = void 0;
delete Element.Storage[uid];
}
Expand Down Expand Up @@ -573,7 +572,7 @@ Element.Methods = {
// Purge the element's existing contents of all storage keys and
// event listeners, since said content will be replaced no matter
// what.
var descendants = Element.select(element, '*'),
var descendants = element.getElementsByTagName('*'),
i = descendants.length;
while (i--) purgeElement(descendants[i]);

Expand Down Expand Up @@ -3824,7 +3823,7 @@ Element.addMethods({
if (!(element = $(element))) return;
purgeElement(element);

var descendants = Element.select(element, '*'),
var descendants = element.getElementsByTagName('*'),
i = descendants.length;

while (i--) purgeElement(descendants[i]);
Expand Down

0 comments on commit 9a752d7

Please sign in to comment.