From 4525276c6e5894080dc8554bc1621c7b6fcc22e2 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Thu, 5 Jun 2014 15:48:13 +0200 Subject: [PATCH] Rename ol.Collection#getAt to ol.Collection#item TouchList, DOMStringList, DOMTokenList, NodeList all have an `item(index)` function to retrieve an item from a list. We should do the same. --- src/ol/collection.js | 4 +-- src/ol/interaction/selectinteraction.js | 2 +- test/spec/ol/collection.test.js | 36 ++++++++++++------------- test/spec/ol/layer/layergroup.test.js | 2 +- test/spec/ol/map.test.js | 12 ++++----- 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/ol/collection.js b/src/ol/collection.js index 1c64540447..64cbd6de94 100644 --- a/src/ol/collection.js +++ b/src/ol/collection.js @@ -144,9 +144,9 @@ ol.Collection.prototype.getArray = function() { * Get the element at the provided index. * @param {number} index Index. * @return {*} Element. - * @todo api + * @todo api stable */ -ol.Collection.prototype.getAt = function(index) { +ol.Collection.prototype.item = function(index) { return this.array_[index]; }; diff --git a/src/ol/interaction/selectinteraction.js b/src/ol/interaction/selectinteraction.js index 8c4f669f45..98b3fb2020 100644 --- a/src/ol/interaction/selectinteraction.js +++ b/src/ol/interaction/selectinteraction.js @@ -135,7 +135,7 @@ ol.interaction.Select.prototype.handleMapBrowserEvent = }, undefined, this.layerFilter_); if (goog.isDef(feature) && features.getLength() == 1 && - features.getAt(0) == feature) { + features.item(0) == feature) { // No change } else { if (features.getLength() !== 0) { diff --git a/test/spec/ol/collection.test.js b/test/spec/ol/collection.test.js index a5d4922ff7..b9e0008083 100644 --- a/test/spec/ol/collection.test.js +++ b/test/spec/ol/collection.test.js @@ -11,7 +11,7 @@ describe('ol.collection', function() { it('creates an empty collection', function() { expect(collection.getLength()).to.eql(0); expect(collection.getArray()).to.be.empty(); - expect(collection.getAt(0)).to.be(undefined); + expect(collection.item(0)).to.be(undefined); }); }); @@ -19,9 +19,9 @@ describe('ol.collection', function() { it('creates the expected collection', function() { var array = [0, 1, 2]; var collection = new ol.Collection(array); - expect(collection.getAt(0)).to.eql(0); - expect(collection.getAt(1)).to.eql(1); - expect(collection.getAt(2)).to.eql(2); + expect(collection.item(0)).to.eql(0); + expect(collection.item(1)).to.eql(1); + expect(collection.item(2)).to.eql(2); }); }); @@ -30,7 +30,7 @@ describe('ol.collection', function() { collection.push(1); expect(collection.getLength()).to.eql(1); expect(collection.getArray()).to.eql([1]); - expect(collection.getAt(0)).to.eql(1); + expect(collection.item(0)).to.eql(1); }); }); @@ -40,7 +40,7 @@ describe('ol.collection', function() { collection.pop(); expect(collection.getLength()).to.eql(0); expect(collection.getArray()).to.be.empty(); - expect(collection.getAt(0)).to.be(undefined); + expect(collection.item(0)).to.be(undefined); }); }); @@ -48,9 +48,9 @@ describe('ol.collection', function() { it('inserts elements at the correct location', function() { collection = new ol.Collection([0, 2]); collection.insertAt(1, 1); - expect(collection.getAt(0)).to.eql(0); - expect(collection.getAt(1)).to.eql(1); - expect(collection.getAt(2)).to.eql(2); + expect(collection.item(0)).to.eql(0); + expect(collection.item(1)).to.eql(1); + expect(collection.item(2)).to.eql(2); }); }); @@ -58,8 +58,8 @@ describe('ol.collection', function() { it('sets at the correct location', function() { collection.setAt(1, 1); expect(collection.getLength()).to.eql(2); - expect(collection.getAt(0)).to.be(undefined); - expect(collection.getAt(1)).to.eql(1); + expect(collection.item(0)).to.be(undefined); + expect(collection.item(1)).to.eql(1); }); }); @@ -67,8 +67,8 @@ describe('ol.collection', function() { it('removes elements at the correction', function() { var collection = new ol.Collection([0, 1, 2]); collection.removeAt(1); - expect(collection.getAt(0)).to.eql(0); - expect(collection.getAt(1)).to.eql(2); + expect(collection.item(0)).to.eql(0); + expect(collection.item(1)).to.eql(2); }); }); @@ -185,9 +185,9 @@ describe('ol.collection', function() { }); collection.setAt(2, 0); expect(collection.getLength()).to.eql(3); - expect(collection.getAt(0)).to.be(undefined); - expect(collection.getAt(1)).to.be(undefined); - expect(collection.getAt(2)).to.eql(0); + expect(collection.item(0)).to.be(undefined); + expect(collection.item(1)).to.be(undefined); + expect(collection.item(2)).to.eql(0); expect(added.length).to.eql(3); expect(added[0]).to.eql(undefined); expect(added[1]).to.eql(undefined); @@ -267,8 +267,8 @@ describe('ol.collection', function() { collection.extend([1, 2]); expect(collection.getLength()).to.eql(2); expect(collection.getArray()).to.eql([1, 2]); - expect(collection.getAt(0)).to.eql(1); - expect(collection.getAt(1)).to.eql(2); + expect(collection.item(0)).to.eql(1); + expect(collection.item(1)).to.eql(2); }); it('fires events', function() { var collection = new ol.Collection(); diff --git a/test/spec/ol/layer/layergroup.test.js b/test/spec/ol/layer/layergroup.test.js index d28ca09773..d26885f25f 100644 --- a/test/spec/ol/layer/layergroup.test.js +++ b/test/spec/ol/layer/layergroup.test.js @@ -184,7 +184,7 @@ describe('ol.layer.Group', function() { }); expect(layerGroup.getLayers()).to.be.a(ol.Collection); expect(layerGroup.getLayers().getLength()).to.be(1); - expect(layerGroup.getLayers().getAt(0)).to.be(layer); + expect(layerGroup.getLayers().item(0)).to.be(layer); goog.dispose(layer); goog.dispose(layerGroup); diff --git a/test/spec/ol/map.test.js b/test/spec/ol/map.test.js index 84e5776329..b449d78b4c 100644 --- a/test/spec/ol/map.test.js +++ b/test/spec/ol/map.test.js @@ -15,7 +15,7 @@ describe('ol.Map', function() { expect(length).to.be.greaterThan(0); for (var i = 0; i < length; ++i) { - expect(interactions.getAt(i).getMap()).to.be(map); + expect(interactions.item(i).getMap()).to.be(map); } }); }); @@ -209,7 +209,7 @@ describe('ol.Map', function() { options.mouseWheelZoom = true; var interactions = ol.interaction.defaults(options); expect(interactions.getLength()).to.eql(1); - expect(interactions.getAt(0)).to.be.a(ol.interaction.MouseWheelZoom); + expect(interactions.item(0)).to.be.a(ol.interaction.MouseWheelZoom); }); }); @@ -223,8 +223,8 @@ describe('ol.Map', function() { it('create double click interaction with default delta', function() { var interactions = ol.interaction.defaults(options); expect(interactions.getLength()).to.eql(1); - expect(interactions.getAt(0)).to.be.a(ol.interaction.DoubleClickZoom); - expect(interactions.getAt(0).delta_).to.eql(1); + expect(interactions.item(0)).to.be.a(ol.interaction.DoubleClickZoom); + expect(interactions.item(0).delta_).to.eql(1); }); }); @@ -233,8 +233,8 @@ describe('ol.Map', function() { options.zoomDelta = 7; var interactions = ol.interaction.defaults(options); expect(interactions.getLength()).to.eql(1); - expect(interactions.getAt(0)).to.be.a(ol.interaction.DoubleClickZoom); - expect(interactions.getAt(0).delta_).to.eql(7); + expect(interactions.item(0)).to.be.a(ol.interaction.DoubleClickZoom); + expect(interactions.item(0).delta_).to.eql(7); }); }); });