OpenLayers OpenLayers

Changeset 5777

Show
Ignore:
Timestamp:
01/16/08 12:35:51 (11 months ago)
Author:
euzuro
Message:

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.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/lib/OpenLayers/Tile/WFS.js

    r5614 r5777  
    6868        if(this.request) { 
    6969            this.request.transport.abort(); 
     70            //this.request.destroy(); 
     71            this.request = null; 
    7072        } 
    7173    }, 
     
    109111    */ 
    110112    loadFeaturesForRegion:function(success, failure) { 
     113        if(this.request) { 
     114            this.request.transport.abort(); 
     115            //this.request.destroy(); 
     116        } 
    111117        this.request = OpenLayers.loadURL(this.url, null, this, success); 
    112118    }, 
     
    142148            this.events.triggerEvent("loadend");  
    143149        } 
     150 
     151        //request produced with success, we can delete the request object. 
     152        //this.request.destroy(); 
     153        this.request = null; 
    144154    }, 
    145155 
  • trunk/openlayers/tests/Tile/test_WFS.html

    r5709 r5777  
    2828 
    2929    function test_Tile_WFS_requestSuccess(t) { 
    30         t.plan(1); 
     30        t.plan(2); 
     31 
     32        var tile = { 
     33            'request': {} 
     34        }; 
     35             
     36        OpenLayers.Tile.WFS.prototype.requestSuccess.apply(tile, []); 
     37         
     38        t.ok(tile.request == null, "request property on tile set to null"); 
     39 
    3140        var layer = {}; // bogus layer 
    3241        var position = new OpenLayers.Pixel(10,20); 
     
    4251    } 
    4352     
     53    function test_Tile_WFS_loadFeaturesForRegion(t) { 
     54        t.plan(9); 
     55         
     56        var tile = { 
     57            'url': {} 
     58        }; 
     59 
     60        var g_Success = {};      
     61 
     62        var tLoadURL = OpenLayers.loadURL; 
     63        OpenLayers.loadURL = function(url, params, caller, onComplete) { 
     64            t.ok(url == tile.url, "tile's url correctly passed as 1st param to loadURL"); 
     65            t.ok(params == null, "null passed as 2nd param to loadURL"); 
     66            t.ok(caller == tile, "tile passed as 3rd param to loadURL"); 
     67            t.ok(onComplete == g_Success, "success param from loadFeaturesForRegion() passed as 4th param to loadURL"); 
     68        }; 
     69         
     70      //no running request -- 4 tests 
     71        OpenLayers.Tile.WFS.prototype.loadFeaturesForRegion.apply(tile, [g_Success]); 
     72 
     73      //running request (cancelled) -- 4 tests + 1 test (for request abort) 
     74        tile.request = { 
     75            'transport': { 
     76                'abort': function() { 
     77                    t.ok(true, "request aborted"); 
     78                } 
     79            } 
     80        }; 
     81        OpenLayers.Tile.WFS.prototype.loadFeaturesForRegion.apply(tile, [g_Success]); 
     82                 
     83        OpenLayers.loadURL = tLoadURL; 
     84    } 
     85     
    4486    function test_Tile_WFS_destroy(t) { 
    45         t.plan(8); 
     87        t.plan(9); 
    4688 
    4789        var layer = {}; // bogus layer 
     
    74116        t.ok(tile.position == null, "tile.position set to null"); 
    75117        t.ok(_gAbort, "request transport is aborted"); 
     118        t.ok(tile.request == null, "tile.request set to null"); 
    76119         
    77120        t.ok(tile.events == null, "tile.events set to null");