[Commits] r178 - sandbox/opengeo/drake/trunk/core/lib/GeoExt/data

commits at geoext.org commits at geoext.org
Tue Feb 17 20:13:31 CET 2009


Author: sbenthall
Date: 2009-02-17 20:13:31 +0100 (Tue, 17 Feb 2009)
New Revision: 178

Modified:
   sandbox/opengeo/drake/trunk/core/lib/GeoExt/data/FeatureStore.js
Log:
refactoring for prettiness


Modified: sandbox/opengeo/drake/trunk/core/lib/GeoExt/data/FeatureStore.js
===================================================================
--- sandbox/opengeo/drake/trunk/core/lib/GeoExt/data/FeatureStore.js	2009-02-17 19:01:38 UTC (rev 177)
+++ sandbox/opengeo/drake/trunk/core/lib/GeoExt/data/FeatureStore.js	2009-02-17 19:13:31 UTC (rev 178)
@@ -22,8 +22,32 @@
 
         var layer = new layerConstructor(name, layerConfig);
 
-        layer.store = this;
+        layer.gx = {};
+        layer.gx.store = this;
 
+        layer.gx.handlers = {
+            onLoad: function(store, options) {
+                this.removeFeatures(this.features, {silent: true});
+                store.each(function(record) {
+                    this.addFeatures(record.data.feature, {silent: true});
+                }, this)
+            },
+    
+            onLoadException: function() {
+                // To be overridden by subclasses.
+            },
+    
+            onAdd: function(store, records, index) {
+                for (var index = 0; index < records.length; index++) {
+                    this.addFeatures(records[index].data.feature, {silent: true});
+                }  
+            },
+    
+            onRemove: function(store, record, index) {
+                this.removeFeatures(record.data.feature,  {silent: true});
+            }
+        },
+
         //should probably be in constructor
         this.featureStoreMediator = new GeoExt.data.FeatureStoreMediator({
             store: this,
@@ -42,18 +66,23 @@
      * listeners to the new store while replacing the old with the new.
      */
      bindLayer : function(layer, initial){
-         if(layer.store && !initial){
-             this.un("load", this.layerHandlers.onLoad, layer);
-             this.un("loadexception", this.layerHandlers.onLoadException, layer);
-             this.un("add", this.layerHandlers.onAdd, layer);
-             this.un("remove", this.layerHandlers.onRemove, layer);
+        
+         if(layer.gx.store && !initial){
+             this.un("load", layer.gx.handlers.onLoad);
+             this.un("loadexception", layer.gx.handlers.onLoadException);
+             this.un("add", layer.gx.handlers.onAdd);
+             this.un("remove", layer.gx.handlers.onRemove);
          }
 
-         this.on("load", this.layerHandlers.onLoad, layer);
-         this.on("loadexception", this.layerHandlers.onLoadException, layer);
-         this.on("add", this.layerHandlers.onAdd, layer);
-         this.on("remove", this.layerHandlers.onRemove, layer);
+         this.on({
+             "load" : layer.gx.handlers.onLoad,
+             "loadexception" : layer.gx.handlers.onLoadException,
+             "add" : layer.gx.handlers.onAdd,
+             "remove" : layer.gx.handlers.onRemove,
+             scope: layer
+         });
 
+
          var updateStore = function(){
              this.update(layer);
          }
@@ -67,30 +96,6 @@
 
     },
 
-    //contains handlers to be called in scope of created OpenLayers layer
-    layerHandlers : {
-        onLoad: function(store, options) {
-            this.removeFeatures(this.features, {silent: true});
-            store.each(function(record) {
-                this.addFeatures(record.data.feature, {silent: true});
-            }, this)
-        },
-    
-        onLoadException: function() {
-            // To be overridden by subclasses.
-        },
-    
-        onAdd: function(store, records, index) {
-            for (var index = 0; index < records.length; index++) {
-                this.addFeatures(records[index].data.feature, {silent: true});
-            }  
-        },
-    
-        onRemove: function(store, record, index) {
-            this.removeFeatures(record.data.feature,  {silent: true});
-        }
-    },
-
     /**
      * Method: update
      *      Called when features are added, removed or modified. This



More information about the Commits mailing list