Merge pull request #2170 from fredj/collection-item

Rename ol.Collection#getAt to ol.Collection#item
This commit is contained in:
Frédéric Junod
2014-06-06 10:13:46 +02:00
5 changed files with 28 additions and 28 deletions

View File

@@ -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];
};

View File

@@ -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) {

View File

@@ -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();

View File

@@ -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);

View File

@@ -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);
});
});
});