Author: pyaschenko
Date: 2008-12-02 13:22:11 -0500 (Tue, 02 Dec 2008)
New Revision: 11495
Modified:
trunk/framework/impl/src/main/javascript/memory.js
Log:
https://jira.jboss.org/jira/browse/RF-5073
Modified: trunk/framework/impl/src/main/javascript/memory.js
===================================================================
--- trunk/framework/impl/src/main/javascript/memory.js 2008-12-02 17:09:06 UTC (rev
11494)
+++ trunk/framework/impl/src/main/javascript/memory.js 2008-12-02 18:22:11 UTC (rev
11495)
@@ -6,21 +6,30 @@
if (!window.RichFaces.Memory) {
window.RichFaces.Memory = {
- cleaners: {},
+ nodeCleaners: {},
+ componentCleaners: {},
addCleaner: function (name, cleaner) {
- this.cleaners[name] = cleaner;
+ this.nodeCleaners[name] = cleaner;
},
- applyCleaners: function (node, isAjax) {
- for (var name in this.cleaners) {
- this.cleaners[name](node, isAjax);
+ addComponentCleaner: function (name, cleaner, checker) {
+ this.componentCleaners[name] = {cleaner: cleaner, checker: checker};
+ },
+
+ applyCleaners: function (node, isAjax, componentNodes) {
+ for (var name in this.nodeCleaners) {
+ this.nodeCleaners[name](node, isAjax);
}
+ for (var name in this.componentCleaners) {
+ if (this.componentCleaners[name].checker(node, isAjax))
+ componentNodes.push(node);
+ }
},
- clean: function (oldNode, isAjax) {
+ _clean: function (oldNode, isAjax, componentNodes) {
if (oldNode) {
- this.applyCleaners(oldNode, isAjax);
+ this.applyCleaners(oldNode, isAjax, componentNodes);
//node.all is quicker than recursive traversing
//window doesn't have "all" attribute
@@ -31,20 +40,36 @@
var length = all.length;
for (var counter = 0; counter < length; counter++ ) {
- this.applyCleaners(all[counter], isAjax);
+ this.applyCleaners(all[counter], isAjax, componentNodes);
}
} else {
var node = oldNode.firstChild;
while (node) {
- this.clean(node, isAjax);
+ this._clean(node, isAjax, componentNodes);
node = node.nextSibling;
}
}
}
+ },
+
+ _cleanComponentNodes: function (oldNodes, isAjax) {
+ for (var i=0; i<oldNodes.length; i++) {
+ var node = oldNodes[i];
+ for (var name in this.componentCleaners) {
+ this.componentCleaners[name].cleaner(node, isAjax);
+ }
+ }
+ },
+
+ clean: function (oldNode, isAjax) {
+ var componentNodes = [];
+ this._clean(oldNode, isAjax, componentNodes);
+ this._cleanComponentNodes(componentNodes, isAjax);
+ componentNodes = null;
}
};
- window.RichFaces.Memory.addCleaner("richfaces", function(node, isAjax) {
+ window.RichFaces.Memory.addComponentCleaner("richfaces", function(node,
isAjax) {
var component = node.component;
if (component) {
var destructorName = component["rich:destructor"];
@@ -56,6 +81,8 @@
}
}
}
+ }, function(node, isAjax) {
+ return (node.component && node.component["rich:destructor"]);
});
if (window.attachEvent) {