Ticket #57: 57.patch

File 57.patch, 2.8 kB (added by sbenthall, 1 year ago)

patch with regression test

  • tests/lib/GeoExt/data/LayerStore.html

    old new  
    7676         
    7777        function test_add_remove(t) { 
    7878             
    79             t.plan(2); 
     79            t.plan(3); 
    8080             
    8181            var map = new OpenLayers.Map("mappanel"); 
    8282            var store = new GeoExt.data.LayerStore({ 
     
    9191             
    9292            store.remove(record); 
    9393            t.eq(store.getCount(), 0, "removing a single record from the store removes one record"); 
     94 
     95            //test adding a record with the same id 
     96            store.add([record]); 
     97            store.add(store.getAt(0).copy()); 
     98            t.eq(map.layers.length,store.getCount(),"number of OpenLayers map layers equals number of records after adding record with same id"); 
    9499             
     100 
     101             
    95102        } 
    96103         
    97104        function test_reorder(t) { 
  • lib/GeoExt/data/LayerStore.js

    old new  
    110110                "remove": this.onRemove, 
    111111                scope: this 
    112112            }); 
     113            this.data.on({ 
     114                "replace" : this.onReplace, 
     115                scope: this 
     116            }); 
    113117        } 
    114118    }, 
    115119 
     
    130134                "remove": this.onRemove, 
    131135                scope: this 
    132136            }); 
     137            this.data.un({ 
     138                "replace" : this.onReplace, 
     139                scope: this 
     140            }); 
    133141            this.map = null; 
    134142        } 
    135143    }, 
     
    236244            this.map.removeLayer(record.get("layer")); 
    237245            delete this._removing; 
    238246        } 
     247    }, 
     248 
     249    /** 
     250     * Method: onReplace 
     251     * Handler for a store's data collections' replace event 
     252     *  
     253     * Parameters: 
     254     * key - {String} 
     255     * oldRecord - {Object} In this case, a record that has been replaced. 
     256     * newRecord - {Object} In this case, a record that is replacing oldRecord. 
     257     */ 
     258    onReplace: function(key, oldRecord, newRecord){ 
     259        this.remove(oldRecord); 
    239260    } 
    240261}; 
    241262 
  • modifications.txt

    old new  
    1515 * Let components do special processing before being added to or removed from a MapPanel (#45) 
    1616 * Add ScaleSlider and tips (#16) 
    1717 * gxtheme css for geoext styles compatible with ext's xtheme (#51) 
     18 * Keeping LayerStore and bound Map in sync when a record is replaced by add() method (and regression test) (#57)