Convert ol.CollectionEvent#getElement method into element property
This commit is contained in:
@@ -9,6 +9,15 @@
|
||||
var oli;
|
||||
|
||||
|
||||
|
||||
/** @interface */
|
||||
oli.CollectionEvent = function() {};
|
||||
|
||||
|
||||
/** @type {*} */
|
||||
oli.CollectionEvent.prototype.element;
|
||||
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*/
|
||||
|
||||
@@ -11,5 +11,3 @@
|
||||
@exportProperty ol.Collection.prototype.remove
|
||||
@exportProperty ol.Collection.prototype.removeAt
|
||||
@exportProperty ol.Collection.prototype.setAt
|
||||
|
||||
@exportProperty ol.CollectionEvent.prototype.getElement
|
||||
|
||||
@@ -26,32 +26,24 @@ ol.CollectionEventType = {
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {goog.events.Event}
|
||||
* @implements {oli.CollectionEvent}
|
||||
* @param {ol.CollectionEventType} type Type.
|
||||
* @param {*=} opt_elem Element.
|
||||
* @param {*=} opt_element Element.
|
||||
* @param {Object=} opt_target Target.
|
||||
*/
|
||||
ol.CollectionEvent = function(type, opt_elem, opt_target) {
|
||||
ol.CollectionEvent = function(type, opt_element, opt_target) {
|
||||
|
||||
goog.base(this, type, opt_target);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {*}
|
||||
*/
|
||||
this.elem_ = opt_elem;
|
||||
this.element = opt_element;
|
||||
|
||||
};
|
||||
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}
|
||||
*/
|
||||
|
||||
@@ -120,7 +120,7 @@ ol.layer.Group.prototype.handleLayersChanged_ = function(event) {
|
||||
* @private
|
||||
*/
|
||||
ol.layer.Group.prototype.handleLayersAdd_ = function(collectionEvent) {
|
||||
var layer = /** @type {ol.layer.Base} */ (collectionEvent.getElement());
|
||||
var layer = /** @type {ol.layer.Base} */ (collectionEvent.element);
|
||||
this.listenerKeys_[goog.getUid(layer).toString()] = goog.events.listen(
|
||||
layer, [ol.ObjectEventType.PROPERTYCHANGE, goog.events.EventType.CHANGE],
|
||||
this.handleLayerChange_, false, this);
|
||||
@@ -133,7 +133,7 @@ ol.layer.Group.prototype.handleLayersAdd_ = function(collectionEvent) {
|
||||
* @private
|
||||
*/
|
||||
ol.layer.Group.prototype.handleLayersRemove_ = function(collectionEvent) {
|
||||
var layer = /** @type {ol.layer.Base} */ (collectionEvent.getElement());
|
||||
var layer = /** @type {ol.layer.Base} */ (collectionEvent.element);
|
||||
var key = goog.getUid(layer).toString();
|
||||
goog.events.unlistenByKey(this.listenerKeys_[key]);
|
||||
delete this.listenerKeys_[key];
|
||||
|
||||
@@ -110,7 +110,7 @@ ol.render.FeaturesOverlay.prototype.handleFeatureChange_ = function() {
|
||||
ol.render.FeaturesOverlay.prototype.handleFeaturesAdd_ =
|
||||
function(collectionEvent) {
|
||||
goog.asserts.assert(!goog.isNull(this.featureChangeListenerKeys_));
|
||||
var feature = /** @type {ol.Feature} */ (collectionEvent.getElement());
|
||||
var feature = /** @type {ol.Feature} */ (collectionEvent.element);
|
||||
this.featureChangeListenerKeys_[goog.getUid(feature).toString()] =
|
||||
goog.events.listen(feature, goog.events.EventType.CHANGE,
|
||||
this.handleFeatureChange_, false, this);
|
||||
@@ -125,7 +125,7 @@ ol.render.FeaturesOverlay.prototype.handleFeaturesAdd_ =
|
||||
ol.render.FeaturesOverlay.prototype.handleFeaturesRemove_ =
|
||||
function(collectionEvent) {
|
||||
goog.asserts.assert(!goog.isNull(this.featureChangeListenerKeys_));
|
||||
var feature = /** @type {ol.Feature} */ (collectionEvent.getElement());
|
||||
var feature = /** @type {ol.Feature} */ (collectionEvent.element);
|
||||
var key = goog.getUid(feature).toString();
|
||||
goog.events.unlistenByKey(this.featureChangeListenerKeys_[key]);
|
||||
delete this.featureChangeListenerKeys_[key];
|
||||
|
||||
@@ -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].getElement()).to.eql(1);
|
||||
expect(cb.lastCall.args[0].element).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.getElement();
|
||||
added = e.element;
|
||||
});
|
||||
goog.events.listen(
|
||||
collection, ol.CollectionEventType.REMOVE, function(e) {
|
||||
removed = e.getElement();
|
||||
removed = e.element;
|
||||
});
|
||||
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.getElement();
|
||||
removed = e.element;
|
||||
});
|
||||
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.getElement();
|
||||
added = e.element;
|
||||
});
|
||||
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.getElement());
|
||||
added.push(e.element);
|
||||
});
|
||||
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.getElement();
|
||||
elem = e.element;
|
||||
});
|
||||
collection.push(1);
|
||||
expect(elem).to.eql(1);
|
||||
@@ -249,15 +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].getElement()).to.eql(1);
|
||||
expect(cb1.lastCall.args[0].getElement()).to.eql(2);
|
||||
expect(cb2.lastCall.args[0].element).to.eql(1);
|
||||
expect(cb1.lastCall.args[0].element).to.eql(2);
|
||||
});
|
||||
});
|
||||
describe('pop', function() {
|
||||
it('triggers remove', function() {
|
||||
goog.events.listen(collection, ol.CollectionEventType.REMOVE, cb1);
|
||||
collection.pop();
|
||||
expect(cb1.lastCall.args[0].getElement()).to.eql(1);
|
||||
expect(cb1.lastCall.args[0].element).to.eql(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -274,7 +274,7 @@ describe('ol.collection', function() {
|
||||
var collection = new ol.Collection();
|
||||
var elems = [];
|
||||
goog.events.listen(collection, ol.CollectionEventType.ADD, function(e) {
|
||||
elems.push(e.getElement());
|
||||
elems.push(e.element);
|
||||
});
|
||||
collection.extend([1, 2]);
|
||||
expect(elems).to.eql([1, 2]);
|
||||
|
||||
Reference in New Issue
Block a user