Export CollectionEvent from ol/Collection

This commit is contained in:
Tim Schaub
2018-02-18 22:29:50 -07:00
parent 4e0eaae9da
commit 9aae8aeb26
7 changed files with 51 additions and 49 deletions

View File

@@ -17,6 +17,33 @@ const Property = {
};
/**
* @classdesc
* Events emitted by {@link ol.Collection} instances are instances of this
* type.
*
* @constructor
* @extends {ol.events.Event}
* @implements {oli.CollectionEvent}
* @param {ol.CollectionEventType} type Type.
* @param {*=} opt_element Element.
*/
export const CollectionEvent = function(type, opt_element) {
Event.call(this, type);
/**
* The element that is added to or removed from the collection.
* @type {*}
* @api
*/
this.element = opt_element;
};
inherits(CollectionEvent, Event);
/**
* @typedef {{unique: (boolean|undefined)}}
*/
@@ -33,7 +60,7 @@ export let CollectionOptions;
*
* @constructor
* @extends {ol.Object}
* @fires ol.Collection.Event
* @fires ol.CollectionEvent
* @param {Array.<T>=} opt_array Array.
* @param {CollectionOptions=} opt_options Collection options.
* @param {boolean|undefined} opt_options.unique Disallow the same item from
@@ -162,7 +189,7 @@ Collection.prototype.insertAt = function(index, elem) {
this.array_.splice(index, 0, elem);
this.updateLength_();
this.dispatchEvent(
new Collection.Event(CollectionEventType.ADD, elem));
new CollectionEvent(CollectionEventType.ADD, elem));
};
@@ -222,7 +249,7 @@ Collection.prototype.removeAt = function(index) {
const prev = this.array_[index];
this.array_.splice(index, 1);
this.updateLength_();
this.dispatchEvent(new Collection.Event(CollectionEventType.REMOVE, prev));
this.dispatchEvent(new CollectionEvent(CollectionEventType.REMOVE, prev));
return prev;
};
@@ -242,9 +269,9 @@ Collection.prototype.setAt = function(index, elem) {
const prev = this.array_[index];
this.array_[index] = elem;
this.dispatchEvent(
new Collection.Event(CollectionEventType.REMOVE, prev));
new CollectionEvent(CollectionEventType.REMOVE, prev));
this.dispatchEvent(
new Collection.Event(CollectionEventType.ADD, elem));
new CollectionEvent(CollectionEventType.ADD, elem));
} else {
let j;
for (j = n; j < index; ++j) {
@@ -276,29 +303,4 @@ Collection.prototype.assertUnique_ = function(elem, opt_except) {
}
};
/**
* @classdesc
* Events emitted by {@link ol.Collection} instances are instances of this
* type.
*
* @constructor
* @extends {ol.events.Event}
* @implements {oli.Collection.Event}
* @param {ol.CollectionEventType} type Type.
* @param {*=} opt_element Element.
*/
Collection.Event = function(type, opt_element) {
Event.call(this, type);
/**
* The element that is added to or removed from the collection.
* @type {*}
* @api
*/
this.element = opt_element;
};
inherits(Collection.Event, Event);
export default Collection;

View File

@@ -8,13 +8,13 @@
export default {
/**
* Triggered when an item is added to the collection.
* @event ol.Collection.Event#add
* @event ol.CollectionEvent#add
* @api
*/
ADD: 'add',
/**
* Triggered when an item is removed from the collection.
* @event ol.Collection.Event#remove
* @event ol.CollectionEvent#remove
* @api
*/
REMOVE: 'remove'

View File

@@ -371,7 +371,7 @@ const PluggableMap = function(options) {
listen(this.controls, CollectionEventType.ADD,
/**
* @param {ol.Collection.Event} event Collection event.
* @param {ol.CollectionEvent} event CollectionEvent.
*/
function(event) {
event.element.setMap(this);
@@ -379,7 +379,7 @@ const PluggableMap = function(options) {
listen(this.controls, CollectionEventType.REMOVE,
/**
* @param {ol.Collection.Event} event Collection event.
* @param {ol.CollectionEvent} event CollectionEvent.
*/
function(event) {
event.element.setMap(null);
@@ -396,7 +396,7 @@ const PluggableMap = function(options) {
listen(this.interactions, CollectionEventType.ADD,
/**
* @param {ol.Collection.Event} event Collection event.
* @param {ol.CollectionEvent} event CollectionEvent.
*/
function(event) {
event.element.setMap(this);
@@ -404,7 +404,7 @@ const PluggableMap = function(options) {
listen(this.interactions, CollectionEventType.REMOVE,
/**
* @param {ol.Collection.Event} event Collection event.
* @param {ol.CollectionEvent} event CollectionEvent.
*/
function(event) {
event.element.setMap(null);
@@ -414,7 +414,7 @@ const PluggableMap = function(options) {
listen(this.overlays_, CollectionEventType.ADD,
/**
* @param {ol.Collection.Event} event Collection event.
* @param {ol.CollectionEvent} event CollectionEvent.
*/
function(event) {
this.addOverlayInternal_(/** @type {ol.Overlay} */ (event.element));
@@ -422,7 +422,7 @@ const PluggableMap = function(options) {
listen(this.overlays_, CollectionEventType.REMOVE,
/**
* @param {ol.Collection.Event} event Collection event.
* @param {ol.CollectionEvent} event CollectionEvent.
*/
function(event) {
const overlay = /** @type {ol.Overlay} */ (event.element);

View File

@@ -355,7 +355,7 @@ Modify.prototype.handleSourceRemove_ = function(event) {
/**
* @param {ol.Collection.Event} evt Event.
* @param {ol.CollectionEvent} evt Event.
* @private
*/
Modify.prototype.handleFeatureAdd_ = function(evt) {
@@ -377,7 +377,7 @@ Modify.prototype.handleFeatureChange_ = function(evt) {
/**
* @param {ol.Collection.Event} evt Event.
* @param {ol.CollectionEvent} evt Event.
* @private
*/
Modify.prototype.handleFeatureRemove_ = function(evt) {

View File

@@ -349,7 +349,7 @@ Select.getDefaultStyleFunction = function() {
/**
* @param {ol.Collection.Event} evt Event.
* @param {ol.CollectionEvent} evt Event.
* @private
*/
Select.prototype.addFeature_ = function(evt) {
@@ -361,7 +361,7 @@ Select.prototype.addFeature_ = function(evt) {
/**
* @param {ol.Collection.Event} evt Event.
* @param {ol.CollectionEvent} evt Event.
* @private
*/
Select.prototype.removeFeature_ = function(evt) {

View File

@@ -2,7 +2,7 @@
* @module ol/interaction/Snap
*/
import {getUid, inherits} from '../index.js';
import Collection from '../Collection.js';
import {CollectionEvent} from '../Collection.js';
import CollectionEventType from '../CollectionEventType.js';
import {distance as coordinateDistance, squaredDistance as squaredCoordinateDistance, closestOnCircle, closestOnSegment, squaredDistanceToSegment} from '../coordinate.js';
import {listen, unlistenByKey} from '../events.js';
@@ -214,14 +214,14 @@ Snap.prototype.getFeatures_ = function() {
/**
* @param {ol.source.Vector.Event|ol.Collection.Event} evt Event.
* @param {ol.source.Vector.Event|ol.CollectionEvent} evt Event.
* @private
*/
Snap.prototype.handleFeatureAdd_ = function(evt) {
let feature;
if (evt instanceof VectorSource.Event) {
feature = evt.feature;
} else if (evt instanceof Collection.Event) {
} else if (evt instanceof CollectionEvent) {
feature = evt.element;
}
this.addFeature(/** @type {ol.Feature} */ (feature));
@@ -229,14 +229,14 @@ Snap.prototype.handleFeatureAdd_ = function(evt) {
/**
* @param {ol.source.Vector.Event|ol.Collection.Event} evt Event.
* @param {ol.source.Vector.Event|ol.CollectionEvent} evt Event.
* @private
*/
Snap.prototype.handleFeatureRemove_ = function(evt) {
let feature;
if (evt instanceof VectorSource.Event) {
feature = evt.feature;
} else if (evt instanceof Collection.Event) {
} else if (evt instanceof CollectionEvent) {
feature = evt.element;
}
this.removeFeature(/** @type {ol.Feature} */ (feature));

View File

@@ -121,7 +121,7 @@ LayerGroup.prototype.handleLayersChanged_ = function(event) {
/**
* @param {ol.Collection.Event} collectionEvent Collection event.
* @param {ol.CollectionEvent} collectionEvent CollectionEvent.
* @private
*/
LayerGroup.prototype.handleLayersAdd_ = function(collectionEvent) {
@@ -136,7 +136,7 @@ LayerGroup.prototype.handleLayersAdd_ = function(collectionEvent) {
/**
* @param {ol.Collection.Event} collectionEvent Collection event.
* @param {ol.CollectionEvent} collectionEvent CollectionEvent.
* @private
*/
LayerGroup.prototype.handleLayersRemove_ = function(collectionEvent) {