See #964 - not only should we cancel ajax requests when we destroy the tile, but also when we initiate a new response. which is to say that when we instruct the tile to run a new request, we can discard the old one(s). that is what this patch does (as well as cleaning up memory in the destroy). Note that I have added this.request.destroy(); call, but commented out. this is a nod to future development/improvement of the OpenLayers.Ajax.Base and OpenLayers.Ajax.Request class to give it its own destroy() method. Just for fun I'll go ahead and open a separate ticket for that: #1277. Thanks elemoine for the reviews and the good dialogue to finishing up this patch.

git-svn-id: http://svn.openlayers.org/trunk/openlayers@5777 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
euzuro
2008-01-16 17:35:51 +00:00
parent 28659c9ebc
commit 52220873e3
2 changed files with 55 additions and 2 deletions

View File

@@ -67,6 +67,8 @@ OpenLayers.Tile.WFS = OpenLayers.Class(OpenLayers.Tile, {
this.url = null;
if(this.request) {
this.request.transport.abort();
//this.request.destroy();
this.request = null;
}
},
@@ -108,6 +110,10 @@ OpenLayers.Tile.WFS = OpenLayers.Class(OpenLayers.Tile, {
* failure - {function}
*/
loadFeaturesForRegion:function(success, failure) {
if(this.request) {
this.request.transport.abort();
//this.request.destroy();
}
this.request = OpenLayers.loadURL(this.url, null, this, success);
},
@@ -141,6 +147,10 @@ OpenLayers.Tile.WFS = OpenLayers.Class(OpenLayers.Tile, {
if (this.events) {
this.events.triggerEvent("loadend");
}
//request produced with success, we can delete the request object.
//this.request.destroy();
this.request = null;
},
/**

View File

@@ -27,7 +27,16 @@
}
function test_Tile_WFS_requestSuccess(t) {
t.plan(1);
t.plan(2);
var tile = {
'request': {}
};
OpenLayers.Tile.WFS.prototype.requestSuccess.apply(tile, []);
t.ok(tile.request == null, "request property on tile set to null");
var layer = {}; // bogus layer
var position = new OpenLayers.Pixel(10,20);
var bounds = new OpenLayers.Bounds(1,2,3,4);
@@ -41,8 +50,41 @@
}
function test_Tile_WFS_loadFeaturesForRegion(t) {
t.plan(9);
var tile = {
'url': {}
};
var g_Success = {};
var tLoadURL = OpenLayers.loadURL;
OpenLayers.loadURL = function(url, params, caller, onComplete) {
t.ok(url == tile.url, "tile's url correctly passed as 1st param to loadURL");
t.ok(params == null, "null passed as 2nd param to loadURL");
t.ok(caller == tile, "tile passed as 3rd param to loadURL");
t.ok(onComplete == g_Success, "success param from loadFeaturesForRegion() passed as 4th param to loadURL");
};
//no running request -- 4 tests
OpenLayers.Tile.WFS.prototype.loadFeaturesForRegion.apply(tile, [g_Success]);
//running request (cancelled) -- 4 tests + 1 test (for request abort)
tile.request = {
'transport': {
'abort': function() {
t.ok(true, "request aborted");
}
}
};
OpenLayers.Tile.WFS.prototype.loadFeaturesForRegion.apply(tile, [g_Success]);
OpenLayers.loadURL = tLoadURL;
}
function test_Tile_WFS_destroy(t) {
t.plan(8);
t.plan(9);
var layer = {}; // bogus layer
var position = new OpenLayers.Pixel(10,20);
@@ -73,6 +115,7 @@
t.ok(tile.size == null, "tile.size set to null");
t.ok(tile.position == null, "tile.position set to null");
t.ok(_gAbort, "request transport is aborted");
t.ok(tile.request == null, "tile.request set to null");
t.ok(tile.events == null, "tile.events set to null");