[Commits] r745 - in core/trunk/geoext: lib/GeoExt/data tests/lib/GeoExt/data
commits at geoext.org
commits at geoext.org
Thu May 14 22:51:14 CEST 2009
Author: sbenthall
Date: 2009-05-14 22:51:13 +0200 (Thu, 14 May 2009)
New Revision: 745
Modified:
core/trunk/geoext/lib/GeoExt/data/LayerStore.js
core/trunk/geoext/tests/lib/GeoExt/data/LayerStore.html
Log:
Prevents LayerStore and Map from getting out of sync when a record is replaced. Thanks to tschaub for future-proofing tests. r=tschaub (closes #57)
Modified: core/trunk/geoext/lib/GeoExt/data/LayerStore.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/data/LayerStore.js 2009-05-14 20:48:10 UTC (rev 744)
+++ core/trunk/geoext/lib/GeoExt/data/LayerStore.js 2009-05-14 20:51:13 UTC (rev 745)
@@ -151,6 +151,10 @@
"remove": this.onRemove,
scope: this
});
+ this.data.on({
+ "replace" : this.onReplace,
+ scope: this
+ });
},
/**
@@ -170,6 +174,8 @@
this.un("add", this.onAdd, this);
this.un("remove", this.onRemove, this);
+ this.data.un("replace", this.onReplace, this);
+
this.map = null;
}
},
@@ -324,10 +330,34 @@
var layer = record.get("layer");
if (this.map.getLayer(layer.id) != null) {
this._removing = true;
- this.map.removeLayer(record.get("layer"));
+ this.removeMapLayer(record);
delete this._removing;
}
}
+ },
+
+ /**
+ * Method: removeMapLayers
+ * Removes a record's layer from the bound map.
+ *
+ * Parameters:
+ * record - {<Ext.data.Record>}
+ */
+ removeMapLayer: function(record){
+ this.map.removeLayer(record.get("layer"));
+ },
+
+ /**
+ * Method: onReplace
+ * Handler for a store's data collections' replace event
+ *
+ * Parameters:
+ * key - {String}
+ * oldRecord - {Object} In this case, a record that has been replaced.
+ * newRecord - {Object} In this case, a record that is replacing oldRecord.
+ */
+ onReplace: function(key, oldRecord, newRecord){
+ this.removeMapLayer(oldRecord);
}
};
Modified: core/trunk/geoext/tests/lib/GeoExt/data/LayerStore.html
===================================================================
--- core/trunk/geoext/tests/lib/GeoExt/data/LayerStore.html 2009-05-14 20:48:10 UTC (rev 744)
+++ core/trunk/geoext/tests/lib/GeoExt/data/LayerStore.html 2009-05-14 20:51:13 UTC (rev 745)
@@ -169,7 +169,7 @@
function test_add_remove(t) {
- t.plan(2);
+ t.plan(6);
var map = new OpenLayers.Map("mappanel");
var store = new GeoExt.data.LayerStore({
@@ -184,7 +184,19 @@
store.remove(record);
t.eq(store.getCount(), 0, "removing a single record from the store removes one record");
+
+ // add back the original and prepare to add copy
+ store.add([record]);
+ t.eq(store.getCount(), 1, "store has a single record before adding copy");
+ t.eq(map.layers.length, 1, "map has a single layer before adding copy");
+ // create a copy of the record with the same layer
+ var copy = record.copy(); // record with same id will replace original
+ copy.set("layer", record.get("layer")); // force records to have same layer
+ store.add(copy);
+ t.eq(store.getCount(), 1, "store has a single record after adding copy");
+ t.eq(map.layers.length, 1, "map has a single layer after adding copy");
+
}
function test_reorder(t) {
More information about the Commits
mailing list