From b9f2f7bcb49f4011f7e702067c0ddc394d10e98c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Tue, 27 Aug 2013 22:07:03 +0200 Subject: [PATCH 1/4] Add ol.CollectionEvent#getElement --- src/ol/collection.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/ol/collection.js b/src/ol/collection.js index e73eb3376e..993efd2a6c 100644 --- a/src/ol/collection.js +++ b/src/ol/collection.js @@ -35,14 +35,23 @@ ol.CollectionEvent = function(type, opt_elem, opt_target) { goog.base(this, type, opt_target); /** + * @private * @type {*} */ - this.elem = opt_elem; + this.elem_ = opt_elem; }; goog.inherits(ol.CollectionEvent, goog.events.Event); +/** + * @return {*} The element to which this event pertains. + */ +ol.CollectionEvent.prototype.getElement = function() { + return this.elem_; +}; + + /** * @enum {string} */ From 9f2c351057864edf21b2db3196ee80037ee097c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Tue, 27 Aug 2013 22:07:45 +0200 Subject: [PATCH 2/4] Use ol.CollectionEvent#getElement in LayerGroup --- src/ol/layer/layergroup.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ol/layer/layergroup.js b/src/ol/layer/layergroup.js index b93c0e40b2..b149205765 100644 --- a/src/ol/layer/layergroup.js +++ b/src/ol/layer/layergroup.js @@ -123,7 +123,7 @@ ol.layer.LayerGroup.prototype.handleLayersChanged_ = function(event) { * @private */ ol.layer.LayerGroup.prototype.handleLayersAdd_ = function(collectionEvent) { - var layer = /** @type {ol.layer.LayerBase} */ (collectionEvent.elem); + var layer = /** @type {ol.layer.LayerBase} */ (collectionEvent.getElement()); this.listenerKeys_[goog.getUid(layer).toString()] = goog.events.listen( layer, goog.events.EventType.CHANGE, this.handleLayerChange, false, this); @@ -136,7 +136,7 @@ ol.layer.LayerGroup.prototype.handleLayersAdd_ = function(collectionEvent) { * @private */ ol.layer.LayerGroup.prototype.handleLayersRemove_ = function(collectionEvent) { - var layer = /** @type {ol.layer.LayerBase} */ (collectionEvent.elem); + var layer = /** @type {ol.layer.LayerBase} */ (collectionEvent.getElement()); var key = goog.getUid(layer).toString(); goog.events.unlistenByKey(this.listenerKeys_[key]); delete this.listenerKeys_[key]; From 9895f879f9b21b0ea022910d326858c576604fa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Tue, 27 Aug 2013 22:08:26 +0200 Subject: [PATCH 3/4] Export ol.CollectionEvent#getElement --- src/ol/collection.exports | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ol/collection.exports b/src/ol/collection.exports index 5e3dae2d8d..5d64b817fb 100644 --- a/src/ol/collection.exports +++ b/src/ol/collection.exports @@ -10,3 +10,5 @@ @exportProperty ol.Collection.prototype.remove @exportProperty ol.Collection.prototype.removeAt @exportProperty ol.Collection.prototype.setAt + +@exportProperty ol.CollectionEvent.prototype.getElement From d1e879e03f6e05065e611e7b7daf2a4970337e9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Tue, 27 Aug 2013 22:11:33 +0200 Subject: [PATCH 4/4] Use ol.Collection#getElement in tests --- test/spec/ol/collection.test.js | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/test/spec/ol/collection.test.js b/test/spec/ol/collection.test.js index ef80e683cb..3020ba0f36 100644 --- a/test/spec/ol/collection.test.js +++ b/test/spec/ol/collection.test.js @@ -117,7 +117,7 @@ describe('ol.collection', function() { goog.events.listen(collection, ol.CollectionEventType.REMOVE, cb); expect(collection.remove(1)).to.eql(1); expect(cb).to.be.called(); - expect(cb.lastCall.args[0].elem).to.eql(1); + expect(cb.lastCall.args[0].getElement()).to.eql(1); }); it('does not remove more than one matching element', function() { var collection = new ol.Collection([0, 1, 1, 2]); @@ -138,11 +138,11 @@ describe('ol.collection', function() { var collection = new ol.Collection(['a', 'b']); var added, removed; goog.events.listen(collection, ol.CollectionEventType.ADD, function(e) { - added = e.elem; + added = e.getElement(); }); goog.events.listen( collection, ol.CollectionEventType.REMOVE, function(e) { - removed = e.elem; + removed = e.getElement(); }); collection.setAt(1, 1); expect(added).to.eql(1); @@ -156,7 +156,7 @@ describe('ol.collection', function() { var removed; goog.events.listen( collection, ol.CollectionEventType.REMOVE, function(e) { - removed = e.elem; + removed = e.getElement(); }); collection.pop(); expect(removed).to.eql('a'); @@ -169,7 +169,7 @@ describe('ol.collection', function() { var added; goog.events.listen( collection, ol.CollectionEventType.ADD, function(e) { - added = e.elem; + added = e.getElement(); }); collection.insertAt(1, 1); expect(added).to.eql(1); @@ -181,7 +181,7 @@ describe('ol.collection', function() { var added = []; goog.events.listen( collection, ol.CollectionEventType.ADD, function(e) { - added.push(e.elem); + added.push(e.getElement()); }); collection.setAt(2, 0); expect(collection.getLength()).to.eql(3); @@ -230,7 +230,7 @@ describe('ol.collection', function() { var collection = new ol.Collection(); var elem; goog.events.listen(collection, ol.CollectionEventType.ADD, function(e) { - elem = e.elem; + elem = e.getElement(); }); collection.push(1); expect(elem).to.eql(1); @@ -249,16 +249,15 @@ describe('ol.collection', function() { goog.events.listen(collection, ol.CollectionEventType.ADD, cb1); goog.events.listen(collection, ol.CollectionEventType.REMOVE, cb2); collection.setAt(0, 2); - expect(cb2.lastCall.args[0].elem).to.eql(1); - expect(cb1.lastCall.args[0].elem).to.eql(2); + expect(cb2.lastCall.args[0].getElement()).to.eql(1); + expect(cb1.lastCall.args[0].getElement()).to.eql(2); }); }); describe('pop', function() { it('triggers remove', function() { - var elem; goog.events.listen(collection, ol.CollectionEventType.REMOVE, cb1); collection.pop(); - expect(cb1.lastCall.args[0].elem).to.eql(1); + expect(cb1.lastCall.args[0].getElement()).to.eql(1); }); }); });