Dedicated module for collection event type enum

This commit is contained in:
Tim Schaub
2016-12-27 12:31:50 -07:00
parent 828e26ea81
commit 847efde217
9 changed files with 61 additions and 55 deletions

View File

@@ -6,8 +6,9 @@
goog.provide('ol.Collection');
goog.require('ol');
goog.require('ol.events.Event');
goog.require('ol.CollectionEventType');
goog.require('ol.Object');
goog.require('ol.events.Event');
/**
@@ -127,7 +128,7 @@ ol.Collection.prototype.insertAt = function(index, elem) {
this.array_.splice(index, 0, elem);
this.updateLength_();
this.dispatchEvent(
new ol.Collection.Event(ol.Collection.EventType.ADD, elem));
new ol.Collection.Event(ol.CollectionEventType.ADD, elem));
};
@@ -185,7 +186,7 @@ ol.Collection.prototype.removeAt = function(index) {
this.array_.splice(index, 1);
this.updateLength_();
this.dispatchEvent(
new ol.Collection.Event(ol.Collection.EventType.REMOVE, prev));
new ol.Collection.Event(ol.CollectionEventType.REMOVE, prev));
return prev;
};
@@ -202,9 +203,9 @@ ol.Collection.prototype.setAt = function(index, elem) {
var prev = this.array_[index];
this.array_[index] = elem;
this.dispatchEvent(
new ol.Collection.Event(ol.Collection.EventType.REMOVE, prev));
new ol.Collection.Event(ol.CollectionEventType.REMOVE, prev));
this.dispatchEvent(
new ol.Collection.Event(ol.Collection.EventType.ADD, elem));
new ol.Collection.Event(ol.CollectionEventType.ADD, elem));
} else {
var j;
for (j = n; j < index; ++j) {
@@ -231,25 +232,6 @@ ol.Collection.Property = {
};
/**
* @enum {string}
*/
ol.Collection.EventType = {
/**
* Triggered when an item is added to the collection.
* @event ol.Collection.Event#add
* @api stable
*/
ADD: 'add',
/**
* Triggered when an item is removed from the collection.
* @event ol.Collection.Event#remove
* @api stable
*/
REMOVE: 'remove'
};
/**
* @classdesc
* Events emitted by {@link ol.Collection} instances are instances of this
@@ -258,7 +240,7 @@ ol.Collection.EventType = {
* @constructor
* @extends {ol.events.Event}
* @implements {oli.Collection.Event}
* @param {ol.Collection.EventType} type Type.
* @param {ol.CollectionEventType} type Type.
* @param {*=} opt_element Element.
*/
ol.Collection.Event = function(type, opt_element) {

View File

@@ -0,0 +1,19 @@
goog.provide('ol.CollectionEventType');
/**
* @enum {string}
*/
ol.CollectionEventType = {
/**
* Triggered when an item is added to the collection.
* @event ol.Collection.Event#add
* @api stable
*/
ADD: 'add',
/**
* Triggered when an item is removed from the collection.
* @event ol.Collection.Event#remove
* @api stable
*/
REMOVE: 'remove'
};

View File

@@ -1,7 +1,7 @@
goog.provide('ol.interaction.Modify');
goog.require('ol');
goog.require('ol.Collection');
goog.require('ol.CollectionEventType');
goog.require('ol.Feature');
goog.require('ol.MapBrowserEvent');
goog.require('ol.MapBrowserPointerEvent');
@@ -173,9 +173,9 @@ ol.interaction.Modify = function(options) {
this.features_ = options.features;
this.features_.forEach(this.addFeature_, this);
ol.events.listen(this.features_, ol.Collection.EventType.ADD,
ol.events.listen(this.features_, ol.CollectionEventType.ADD,
this.handleFeatureAdd_, this);
ol.events.listen(this.features_, ol.Collection.EventType.REMOVE,
ol.events.listen(this.features_, ol.CollectionEventType.REMOVE,
this.handleFeatureRemove_, this);
/**

View File

@@ -1,12 +1,12 @@
goog.provide('ol.interaction.Select');
goog.require('ol');
goog.require('ol.functions');
goog.require('ol.Collection');
goog.require('ol.CollectionEventType');
goog.require('ol.array');
goog.require('ol.events');
goog.require('ol.events.Event');
goog.require('ol.events.condition');
goog.require('ol.functions');
goog.require('ol.geom.GeometryType');
goog.require('ol.interaction.Interaction');
goog.require('ol.layer.Vector');
@@ -136,9 +136,9 @@ ol.interaction.Select = function(opt_options) {
this.featureLayerAssociation_ = {};
var features = this.featureOverlay_.getSource().getFeaturesCollection();
ol.events.listen(features, ol.Collection.EventType.ADD,
ol.events.listen(features, ol.CollectionEventType.ADD,
this.addFeature_, this);
ol.events.listen(features, ol.Collection.EventType.REMOVE,
ol.events.listen(features, ol.CollectionEventType.REMOVE,
this.removeFeature_, this);
};

View File

@@ -2,6 +2,7 @@ goog.provide('ol.interaction.Snap');
goog.require('ol');
goog.require('ol.Collection');
goog.require('ol.CollectionEventType');
goog.require('ol.Object');
goog.require('ol.Observable');
goog.require('ol.coordinate');
@@ -335,9 +336,9 @@ ol.interaction.Snap.prototype.setMap = function(map) {
if (map) {
if (this.features_) {
keys.push(
ol.events.listen(this.features_, ol.Collection.EventType.ADD,
ol.events.listen(this.features_, ol.CollectionEventType.ADD,
this.handleFeatureAdd_, this),
ol.events.listen(this.features_, ol.Collection.EventType.REMOVE,
ol.events.listen(this.features_, ol.CollectionEventType.REMOVE,
this.handleFeatureRemove_, this)
);
} else if (this.source_) {

View File

@@ -3,6 +3,7 @@ goog.provide('ol.layer.Group');
goog.require('ol');
goog.require('ol.asserts');
goog.require('ol.Collection');
goog.require('ol.CollectionEventType');
goog.require('ol.Object');
goog.require('ol.events');
goog.require('ol.events.EventType');
@@ -88,9 +89,9 @@ ol.layer.Group.prototype.handleLayersChanged_ = function(event) {
var layers = this.getLayers();
this.layersListenerKeys_.push(
ol.events.listen(layers, ol.Collection.EventType.ADD,
ol.events.listen(layers, ol.CollectionEventType.ADD,
this.handleLayersAdd_, this),
ol.events.listen(layers, ol.Collection.EventType.REMOVE,
ol.events.listen(layers, ol.CollectionEventType.REMOVE,
this.handleLayersRemove_, this));
for (var id in this.listenerKeys_) {

View File

@@ -6,6 +6,7 @@ goog.provide('ol.Map');
goog.require('ol');
goog.require('ol.Collection');
goog.require('ol.CollectionEventType');
goog.require('ol.MapBrowserEvent');
goog.require('ol.MapBrowserEventHandler');
goog.require('ol.MapEvent');
@@ -391,7 +392,7 @@ ol.Map = function(options) {
control.setMap(this);
}, this);
ol.events.listen(this.controls_, ol.Collection.EventType.ADD,
ol.events.listen(this.controls_, ol.CollectionEventType.ADD,
/**
* @param {ol.Collection.Event} event Collection event.
*/
@@ -399,7 +400,7 @@ ol.Map = function(options) {
event.element.setMap(this);
}, this);
ol.events.listen(this.controls_, ol.Collection.EventType.REMOVE,
ol.events.listen(this.controls_, ol.CollectionEventType.REMOVE,
/**
* @param {ol.Collection.Event} event Collection event.
*/
@@ -416,7 +417,7 @@ ol.Map = function(options) {
interaction.setMap(this);
}, this);
ol.events.listen(this.interactions_, ol.Collection.EventType.ADD,
ol.events.listen(this.interactions_, ol.CollectionEventType.ADD,
/**
* @param {ol.Collection.Event} event Collection event.
*/
@@ -424,7 +425,7 @@ ol.Map = function(options) {
event.element.setMap(this);
}, this);
ol.events.listen(this.interactions_, ol.Collection.EventType.REMOVE,
ol.events.listen(this.interactions_, ol.CollectionEventType.REMOVE,
/**
* @param {ol.Collection.Event} event Collection event.
*/
@@ -434,7 +435,7 @@ ol.Map = function(options) {
this.overlays_.forEach(this.addOverlayInternal_, this);
ol.events.listen(this.overlays_, ol.Collection.EventType.ADD,
ol.events.listen(this.overlays_, ol.CollectionEventType.ADD,
/**
* @param {ol.Collection.Event} event Collection event.
*/
@@ -442,7 +443,7 @@ ol.Map = function(options) {
this.addOverlayInternal_(/** @type {ol.Overlay} */ (event.element));
}, this);
ol.events.listen(this.overlays_, ol.Collection.EventType.REMOVE,
ol.events.listen(this.overlays_, ol.CollectionEventType.REMOVE,
/**
* @param {ol.Collection.Event} event Collection event.
*/

View File

@@ -5,6 +5,7 @@ goog.provide('ol.source.Vector');
goog.require('ol');
goog.require('ol.Collection');
goog.require('ol.CollectionEventType');
goog.require('ol.Object');
goog.require('ol.array');
goog.require('ol.asserts');
@@ -316,7 +317,7 @@ ol.source.Vector.prototype.bindFeaturesCollection_ = function(collection) {
modifyingCollection = false;
}
});
ol.events.listen(collection, ol.Collection.EventType.ADD,
ol.events.listen(collection, ol.CollectionEventType.ADD,
function(evt) {
if (!modifyingCollection) {
modifyingCollection = true;
@@ -324,7 +325,7 @@ ol.source.Vector.prototype.bindFeaturesCollection_ = function(collection) {
modifyingCollection = false;
}
}, this);
ol.events.listen(collection, ol.Collection.EventType.REMOVE,
ol.events.listen(collection, ol.CollectionEventType.REMOVE,
function(evt) {
if (!modifyingCollection) {
modifyingCollection = true;