Single provide from ol/collection.js
This commit is contained in:
@@ -4,58 +4,11 @@
|
||||
*/
|
||||
|
||||
goog.provide('ol.Collection');
|
||||
goog.provide('ol.CollectionEvent');
|
||||
goog.provide('ol.CollectionEventType');
|
||||
|
||||
goog.require('ol.events.Event');
|
||||
goog.require('ol.Object');
|
||||
|
||||
|
||||
/**
|
||||
* @enum {string}
|
||||
*/
|
||||
ol.CollectionEventType = {
|
||||
/**
|
||||
* Triggered when an item is added to the collection.
|
||||
* @event ol.CollectionEvent#add
|
||||
* @api stable
|
||||
*/
|
||||
ADD: 'add',
|
||||
/**
|
||||
* Triggered when an item is removed from the collection.
|
||||
* @event ol.CollectionEvent#remove
|
||||
* @api stable
|
||||
*/
|
||||
REMOVE: 'remove'
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*/
|
||||
ol.CollectionEvent = function(type, opt_element) {
|
||||
|
||||
ol.events.Event.call(this, type);
|
||||
|
||||
/**
|
||||
* The element that is added to or removed from the collection.
|
||||
* @type {*}
|
||||
* @api stable
|
||||
*/
|
||||
this.element = opt_element;
|
||||
|
||||
};
|
||||
ol.inherits(ol.CollectionEvent, ol.events.Event);
|
||||
|
||||
|
||||
/**
|
||||
* @enum {string}
|
||||
*/
|
||||
@@ -74,7 +27,7 @@ ol.CollectionProperty = {
|
||||
*
|
||||
* @constructor
|
||||
* @extends {ol.Object}
|
||||
* @fires ol.CollectionEvent
|
||||
* @fires ol.Collection.Event
|
||||
* @param {!Array.<T>=} opt_array Array.
|
||||
* @template T
|
||||
* @api stable
|
||||
@@ -181,7 +134,7 @@ ol.Collection.prototype.insertAt = function(index, elem) {
|
||||
this.array_.splice(index, 0, elem);
|
||||
this.updateLength_();
|
||||
this.dispatchEvent(
|
||||
new ol.CollectionEvent(ol.CollectionEventType.ADD, elem));
|
||||
new ol.Collection.Event(ol.Collection.EventType.ADD, elem));
|
||||
};
|
||||
|
||||
|
||||
@@ -239,7 +192,7 @@ ol.Collection.prototype.removeAt = function(index) {
|
||||
this.array_.splice(index, 1);
|
||||
this.updateLength_();
|
||||
this.dispatchEvent(
|
||||
new ol.CollectionEvent(ol.CollectionEventType.REMOVE, prev));
|
||||
new ol.Collection.Event(ol.Collection.EventType.REMOVE, prev));
|
||||
return prev;
|
||||
};
|
||||
|
||||
@@ -256,9 +209,9 @@ ol.Collection.prototype.setAt = function(index, elem) {
|
||||
var prev = this.array_[index];
|
||||
this.array_[index] = elem;
|
||||
this.dispatchEvent(
|
||||
new ol.CollectionEvent(ol.CollectionEventType.REMOVE, prev));
|
||||
new ol.Collection.Event(ol.Collection.EventType.REMOVE, prev));
|
||||
this.dispatchEvent(
|
||||
new ol.CollectionEvent(ol.CollectionEventType.ADD, elem));
|
||||
new ol.Collection.Event(ol.Collection.EventType.ADD, elem));
|
||||
} else {
|
||||
var j;
|
||||
for (j = n; j < index; ++j) {
|
||||
@@ -275,3 +228,48 @@ ol.Collection.prototype.setAt = function(index, elem) {
|
||||
ol.Collection.prototype.updateLength_ = function() {
|
||||
this.set(ol.CollectionProperty.LENGTH, this.array_.length);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @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
|
||||
* type.
|
||||
*
|
||||
* @constructor
|
||||
* @extends {ol.events.Event}
|
||||
* @implements {oli.Collection.Event}
|
||||
* @param {ol.Collection.EventType} type Type.
|
||||
* @param {*=} opt_element Element.
|
||||
*/
|
||||
ol.Collection.Event = function(type, opt_element) {
|
||||
|
||||
ol.events.Event.call(this, type);
|
||||
|
||||
/**
|
||||
* The element that is added to or removed from the collection.
|
||||
* @type {*}
|
||||
* @api stable
|
||||
*/
|
||||
this.element = opt_element;
|
||||
|
||||
};
|
||||
ol.inherits(ol.Collection.Event, ol.events.Event);
|
||||
|
||||
Reference in New Issue
Block a user