[Commits] r357 - in core/trunk/geoext: lib/GeoExt/data tests/lib/GeoExt/data
commits at geoext.org
commits at geoext.org
Tue Apr 7 22:11:21 CEST 2009
Author: tschaub
Date: 2009-04-07 22:11:21 +0200 (Tue, 07 Apr 2009)
New Revision: 357
Modified:
core/trunk/geoext/lib/GeoExt/data/FeatureRecord.js
core/trunk/geoext/lib/GeoExt/data/LayerRecord.js
core/trunk/geoext/tests/lib/GeoExt/data/FeatureRecord.html
core/trunk/geoext/tests/lib/GeoExt/data/LayerRecord.html
Log:
Records that contain references to OL objects should clone those objects on copy. Done here for the FeatureRecord and LayerRecord. r=ahocevar (closes #34)
Modified: core/trunk/geoext/lib/GeoExt/data/FeatureRecord.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/data/FeatureRecord.js 2009-04-07 19:11:26 UTC (rev 356)
+++ core/trunk/geoext/lib/GeoExt/data/FeatureRecord.js 2009-04-07 20:11:21 UTC (rev 357)
@@ -22,6 +22,24 @@
]);
/**
+ * APIMethod: copy
+ * Creates a copy of this Record.
+ *
+ * Paremters:
+ * id - {String} (optional) A new Record id.
+ *
+ * Returns:
+ * {GeoExt.data.LayerRecord} A new layer record.
+ */
+GeoExt.data.FeatureRecord.prototype.copy = function(id) {
+ var feature = this.get("feature") && this.get("feature").clone();
+ return new this.constructor(
+ Ext.applyIf({feature: feature}, this.data),
+ id || this.id
+ );
+};
+
+/**
* APIFunction: GeoExt.data.FeatureRecord.create
* Creates a constructor for a FeatureRecord, optionally with additional
* fields.
Modified: core/trunk/geoext/lib/GeoExt/data/LayerRecord.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/data/LayerRecord.js 2009-04-07 19:11:26 UTC (rev 356)
+++ core/trunk/geoext/lib/GeoExt/data/LayerRecord.js 2009-04-07 20:11:21 UTC (rev 357)
@@ -30,6 +30,24 @@
]);
/**
+ * APIMethod: copy
+ * Creates a copy of this Record.
+ *
+ * Paremters:
+ * id - {String} (optional) A new Record id.
+ *
+ * Returns:
+ * {GeoExt.data.LayerRecord} A new layer record.
+ */
+GeoExt.data.LayerRecord.prototype.copy = function(id) {
+ var layer = this.get("layer") && this.get("layer").clone();
+ return new this.constructor(
+ Ext.applyIf({layer: layer}, this.data),
+ id || this.id
+ );
+};
+
+/**
* APIFunction: GeoExt.data.LayerRecord.create
* Creates a constructor for a LayerRecord, optionally with additional
* fields.
Modified: core/trunk/geoext/tests/lib/GeoExt/data/FeatureRecord.html
===================================================================
--- core/trunk/geoext/tests/lib/GeoExt/data/FeatureRecord.html 2009-04-07 19:11:26 UTC (rev 356)
+++ core/trunk/geoext/tests/lib/GeoExt/data/FeatureRecord.html 2009-04-07 20:11:21 UTC (rev 357)
@@ -46,6 +46,25 @@
record = new c({feature: feature, state: feature.name, fid: feature.fid, foo: "bar"}, feature.id);
t.eq(record.get("foo"), "bar", "foo data row set correctly");
}
+
+ function test_copy(t) {
+
+ t.plan(2);
+
+ var feature = new OpenLayers.Feature.Vector();
+ feature.fid = "foo";
+ var recordType = GeoExt.data.FeatureRecord.create();
+
+ var record = new recordType({feature: feature, fid: feature.fid});
+ var copy = record.copy();
+
+ record.set("fid", "bar");
+ t.ok(copy.get("fid") === "foo", "setting a property on original doesn't modify copy");
+
+ t.ok(copy.get("feature") !== feature, "copy does not have original feature");
+
+ }
+
</script>
<body>
<div id="mappanel"></div>
Modified: core/trunk/geoext/tests/lib/GeoExt/data/LayerRecord.html
===================================================================
--- core/trunk/geoext/tests/lib/GeoExt/data/LayerRecord.html 2009-04-07 19:11:26 UTC (rev 356)
+++ core/trunk/geoext/tests/lib/GeoExt/data/LayerRecord.html 2009-04-07 20:11:21 UTC (rev 357)
@@ -41,6 +41,24 @@
record = new c({layer: layer, title: layer.name, foo: "bar"}, layer.id);
t.eq(record.get("foo"), "bar", "foo data row set correctly");
}
+
+ function test_copy(t) {
+
+ t.plan(2);
+
+ var layer = new OpenLayers.Layer();
+ var recordType = GeoExt.data.LayerRecord.create();
+
+ var record = new recordType({layer: layer, title: layer.name});
+ var copy = record.copy();
+
+ record.set("title", "foo");
+ t.ok(copy.get("title") !== "foo", "setting a property on original doesn't modify copy");
+
+ t.ok(copy.get("layer") !== layer, "copy does not have original layer");
+
+ }
+
</script>
<body>
<div id="mappanel"></div>
More information about the Commits
mailing list