[Commits] r1086 - in core/trunk/geoext: lib/GeoExt/widgets/tree tests/lib/GeoExt/widgets/tree

commits at geoext.org commits at geoext.org
Tue Jun 16 17:19:10 CEST 2009


Author: ahocevar
Date: 2009-06-16 17:19:10 +0200 (Tue, 16 Jun 2009)
New Revision: 1086

Modified:
   core/trunk/geoext/lib/GeoExt/widgets/tree/LayerContainer.js
   core/trunk/geoext/lib/GeoExt/widgets/tree/LayerNode.js
   core/trunk/geoext/tests/lib/GeoExt/widgets/tree/LayerContainer.html
Log:
clean up after ourselves properly, which we did not do enough and not right before. onDestroy() is not available everywhere in Ext, we have to override destroy(). r=tschaub (closes #90)


Modified: core/trunk/geoext/lib/GeoExt/widgets/tree/LayerContainer.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/widgets/tree/LayerContainer.js	2009-06-16 15:10:03 UTC (rev 1085)
+++ core/trunk/geoext/lib/GeoExt/widgets/tree/LayerContainer.js	2009-06-16 15:19:10 UTC (rev 1086)
@@ -100,16 +100,6 @@
         }
     },
 
-    /** private: method[onDestroy]
-     */
-    onDestroy: function() {
-        if(this.layerStore) {
-            this.layerStore.un("add", this.onStoreAdd, this);
-            this.layerStore.un("remove", this.onStoreRemove, this);
-        }
-        GeoExt.tree.LayerContainer.superclass.onDestroy.apply(this, arguments);
-    },
-    
     /** private: method[recordIndexToNodeIndex]
      *  :param index: ``Number`` The record index in the layer store.
      *  :return: ``Number`` The appropriate child node index for the record.
@@ -220,8 +210,17 @@
             this.layerStore.insert(newRecordIndex, [record]);
             delete this._reordering;
         }
+    },
+
+    /** private: method[destroy]
+     */
+    destroy: function() {
+        if(this.layerStore) {
+            this.layerStore.un("add", this.onStoreAdd, this);
+            this.layerStore.un("remove", this.onStoreRemove, this);
+        }
+        GeoExt.tree.LayerContainer.superclass.destroy.apply(this, arguments);
     }
-    
 });
 
 /**

Modified: core/trunk/geoext/lib/GeoExt/widgets/tree/LayerNode.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/widgets/tree/LayerNode.js	2009-06-16 15:10:03 UTC (rev 1085)
+++ core/trunk/geoext/lib/GeoExt/widgets/tree/LayerNode.js	2009-06-16 15:19:10 UTC (rev 1086)
@@ -64,11 +64,11 @@
         node.visibilityChanging = false;
     },
     
-    /** private: method[onDestroy]
+    /** private: method[destroy]
      */
-    onDestroy: function() {
+    destroy: function() {
         delete this.radio;
-        GeoExt.tree.LayerNodeUI.superclass.onDestroy.call(this);
+        GeoExt.tree.LayerNodeUI.superclass.destroy.call(this);
     }
 });
 
@@ -225,53 +225,84 @@
      *  state
      */
     addVisibilityEventHandlers: function() {
-        this.layer.events.register("visibilitychanged", this, function() {
-            if(!this.visibilityChanging &&
-                    this.attributes.checked != this.layer.getVisibility()) {
-                this.getUI().toggleCheck(this.layer.getVisibility());
-            }
-        });
+        this.layer.events.on({
+            "visibilitychanged": this.onLayerVisibilityChanged,
+            scope: this
+        }); 
         this.on({
-            "checkchange": function(node, checked) {
-                if (checked && this.layer.isBaseLayer && this.layer.map) {
-                    this.layer.map.setBaseLayer(this.layer);
-                }
-                this.layer.setVisibility(checked);
-            },
+            "checkchange": this.onCheckChange,
             scope: this
         });
     },
     
+    /** private: method[onLayerVisiilityChanged
+     *  handler for visibilitychanged events on the layer
+     */
+    onLayerVisibilityChanged: function() {
+        if(!this.visibilityChanging &&
+                this.attributes.checked != this.layer.getVisibility()) {
+            this.getUI().toggleCheck(this.layer.getVisibility());
+        }
+    },
+    
+    /** private: method[onCheckChange]
+     *  :param node: ``GeoExt.tree.LayerNode``
+     *  :param checked: ``Boolean``
+     *  handler for checkchange events 
+     */
+    onCheckChange: function(node, checked) {
+        if (checked && this.layer.isBaseLayer && this.layer.map) {
+            this.layer.map.setBaseLayer(this.layer);
+        }
+        this.layer.setVisibility(checked);
+    },
+    
     /** private: method[addStoreEventHandlers]
      *  Adds handlers that make sure the node disappeares when the layer is
      *  removed from the store, and appears when it is re-added.
      */
     addStoreEventHandlers: function() {
         this.layerStore.on({
-            "add": function(store, records, index) {
-                var l;
-                for(var i=0; i<records.length; ++i) {
-                    l = records[i].get("layer");
-                    if(this.layer == l) {
-                        this.getUI().show();
-                    } else if (this.layer == l.name) {
-                        // layer is a string, which means the node has not yet
-                        // been rendered because the layer was not found. But
-                        // now we have the layer and can render.
-                        this.render(bulkRender);
-                        return;
-                    }
-                }
-            },
-            "remove": function(store, record, index) {
-                if(this.layer == record.get("layer")) {
-                    this.getUI().hide();
-                }
-            },
+            "add": this.onStoreAdd,
+            "remove": this.onStoreRemove,
             scope: this
         });
     },
     
+    /** private: method[onStoreAdd]
+     *  :param store: ``Ext.data.Store``
+     *  :param records: ``Array(Ext.data.Record)``
+     *  :param index: ``Nmber``
+     *  handler for add events on the store 
+     */
+    onStoreAdd: function(store, records, index) {
+        var l;
+        for(var i=0; i<records.length; ++i) {
+            l = records[i].get("layer");
+            if(this.layer == l) {
+                this.getUI().show();
+            } else if (this.layer == l.name) {
+                // layer is a string, which means the node has not yet
+                // been rendered because the layer was not found. But
+                // now we have the layer and can render.
+                this.render(bulkRender);
+                return;
+            }
+        }
+    },
+    
+    /** private: method[onStoreRemove]
+     *  :param store: ``Ext.data.Store``
+     *  :param record: ``Ext.data.Record``
+     *  :param index: ``Nmber``
+     *  handler for remove events on the store 
+     */
+    onStoreRemove: function(store, record, index) {
+        if(this.layer == record.get("layer")) {
+            this.getUI().hide();
+        }
+    },
+    
     /** private: method[addChildNodes]
      *  Calls the add method of a node type configured as ``childNodeType``
      *  to add children.
@@ -282,6 +313,22 @@
         } else if(typeof this.childNodeType.add === "function") {
             this.childNodeType.add(this);
         }
+    },
+    
+    /** private: method[destroy]
+     */
+    destroy: function() {
+        this.layer.events.un({
+            "visibilitychanged": this.onLayerVisibilityChanged,
+            scope: this
+        });
+        delete this.layer;
+        this.layerStore.un("add", this.onStoreAdd, this);
+        this.layerStore.un("remove", this.onStoreRemove, this);
+        delete this.layerStore;
+        this.un("checkchange", this.onCheckChange, this);
+
+        GeoExt.tree.LayerNode.superclass.destroy.call(this);
     }
 });
 

Modified: core/trunk/geoext/tests/lib/GeoExt/widgets/tree/LayerContainer.html
===================================================================
--- core/trunk/geoext/tests/lib/GeoExt/widgets/tree/LayerContainer.html	2009-06-16 15:10:03 UTC (rev 1085)
+++ core/trunk/geoext/tests/lib/GeoExt/widgets/tree/LayerContainer.html	2009-06-16 15:19:10 UTC (rev 1086)
@@ -54,7 +54,7 @@
             t.ok(node.firstChild.layer === layer, "child layer is correct");
 
             node.destroy();
-            //map.destroy();
+            map.destroy();
             
         }
         
@@ -117,7 +117,7 @@
             t.eq(root.childNodes[3].layer.name, "c", "[c, a, b, d] first layer drawn at bottom of root");
             
             root.destroy();
-            //map.destroy();
+            map.destroy();
             
         }
         



More information about the Commits mailing list