[Commits] r1085 - in core/trunk/geoext: lib/GeoExt/data tests/lib/GeoExt/data

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


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

Modified:
   core/trunk/geoext/lib/GeoExt/data/LayerStore.js
   core/trunk/geoext/tests/lib/GeoExt/data/LayerStore.html
Log:
Unbind the store when the map is being destroyed. r=tschaub (closes #88)


Modified: core/trunk/geoext/lib/GeoExt/data/LayerStore.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/data/LayerStore.js	2009-06-16 09:51:04 UTC (rev 1084)
+++ core/trunk/geoext/lib/GeoExt/data/LayerStore.js	2009-06-16 15:10:03 UTC (rev 1085)
@@ -239,11 +239,18 @@
      *  Handler for a map's removelayer event
      */
     onRemoveLayer: function(evt){
-        if(!this._removing) {
-            var layer = evt.layer;
-            this._removing = true;
-            this.remove(this.getById(layer.id));
-            delete this._removing;
+        //TODO replace the check for undloadDestroy with a listener for the
+        // map's beforedestroy event, doing unbind(). This can be done as soon
+        // as http://trac.openlayers.org/ticket/2136 is fixed.
+        if(this.map.unloadDestroy) {
+            if(!this._removing) {
+                var layer = evt.layer;
+                this._removing = true;
+                this.remove(this.getById(layer.id));
+                delete this._removing;
+            }
+        } else {
+            this.unbind();
         }
     },
     
@@ -369,6 +376,13 @@
      */
     onReplace: function(key, oldRecord, newRecord){
         this.removeMapLayer(oldRecord);
+    },
+    
+    /** private: method[destroy]
+     */
+    destroy: function() {
+        this.unbind();
+        GeoExt.data.LayerStore.superclass.destroy.call(this);
     }
 };
 

Modified: core/trunk/geoext/tests/lib/GeoExt/data/LayerStore.html
===================================================================
--- core/trunk/geoext/tests/lib/GeoExt/data/LayerStore.html	2009-06-16 09:51:04 UTC (rev 1084)
+++ core/trunk/geoext/tests/lib/GeoExt/data/LayerStore.html	2009-06-16 15:10:03 UTC (rev 1085)
@@ -390,7 +390,37 @@
             
         }
         
+        function test_map_destroy(t) {
+            t.plan(1);
+            
+            var map = new OpenLayers.Map({div: "mappanel", allOverlays: true});
+            var a = new OpenLayers.Layer("a");
+            var b = new OpenLayers.Layer("b");
+            map.addLayers([a, b]);
 
+            var store = new GeoExt.data.LayerStore({
+                map: map
+            });
+            
+            var count = 0;
+            // destroying and adding this.control to the map in the remove
+            // handler will cause exceptions when done while the map is being
+            // destroyed. This is the pattern that helped investigating #88.
+            this.control = new OpenLayers.Control();
+            store.on("remove", function() {
+                count++;
+                this.control.destroy();
+                this.control = new OpenLayers.Control();
+                map.addControl(this.control);
+            }, this);
+            
+            map.removeLayer(a);
+            map.destroy();
+            
+            t.eq(count, 1, "store's remove handler called once");
+        }
+        
+
     </script>
   </head>  
   <body>



More information about the Commits mailing list