Add Event to ol.Object

This commit is contained in:
Tim Schaub
2016-12-04 14:30:40 -07:00
parent daba1fbcb6
commit c00906cde9
6 changed files with 50 additions and 45 deletions

View File

@@ -1,5 +1,4 @@
goog.provide('ol.Object');
goog.provide('ol.ObjectEvent');
goog.require('ol');
goog.require('ol.Observable');
@@ -7,39 +6,6 @@ goog.require('ol.events.Event');
goog.require('ol.obj');
/**
* @classdesc
* Events emitted by {@link ol.Object} instances are instances of this type.
*
* @param {string} type The event type.
* @param {string} key The property name.
* @param {*} oldValue The old value for `key`.
* @extends {ol.events.Event}
* @implements {oli.ObjectEvent}
* @constructor
*/
ol.ObjectEvent = function(type, key, oldValue) {
ol.events.Event.call(this, type);
/**
* The name of the property whose value is changing.
* @type {string}
* @api stable
*/
this.key = key;
/**
* The old value. To get the new value use `e.target.get(e.key)` where
* `e` is the event object.
* @type {*}
* @api stable
*/
this.oldValue = oldValue;
};
ol.inherits(ol.ObjectEvent, ol.events.Event);
/**
* @classdesc
* Abstract base class; normally only used for creating subclasses and not
@@ -82,7 +48,7 @@ ol.inherits(ol.ObjectEvent, ol.events.Event);
* @constructor
* @extends {ol.Observable}
* @param {Object.<string, *>=} opt_values An object with key-value pairs.
* @fires ol.ObjectEvent
* @fires ol.Object.Event
* @api
*/
ol.Object = function(opt_values) {
@@ -167,9 +133,9 @@ ol.Object.prototype.getProperties = function() {
ol.Object.prototype.notify = function(key, oldValue) {
var eventType;
eventType = ol.Object.getChangeEventType(key);
this.dispatchEvent(new ol.ObjectEvent(eventType, key, oldValue));
this.dispatchEvent(new ol.Object.Event(eventType, key, oldValue));
eventType = ol.Object.EventType.PROPERTYCHANGE;
this.dispatchEvent(new ol.ObjectEvent(eventType, key, oldValue));
this.dispatchEvent(new ol.Object.Event(eventType, key, oldValue));
};
@@ -231,8 +197,41 @@ ol.Object.prototype.unset = function(key, opt_silent) {
ol.Object.EventType = {
/**
* Triggered when a property is changed.
* @event ol.ObjectEvent#propertychange
* @event ol.Object.Event#propertychange
* @api stable
*/
PROPERTYCHANGE: 'propertychange'
};
/**
* @classdesc
* Events emitted by {@link ol.Object} instances are instances of this type.
*
* @param {string} type The event type.
* @param {string} key The property name.
* @param {*} oldValue The old value for `key`.
* @extends {ol.events.Event}
* @implements {oli.Object.Event}
* @constructor
*/
ol.Object.Event = function(type, key, oldValue) {
ol.events.Event.call(this, type);
/**
* The name of the property whose value is changing.
* @type {string}
* @api stable
*/
this.key = key;
/**
* The old value. To get the new value use `e.target.get(e.key)` where
* `e` is the event object.
* @type {*}
* @api stable
*/
this.oldValue = oldValue;
};
ol.inherits(ol.Object.Event, ol.events.Event);