Remove static members from BaseObject

This commit is contained in:
Tim Schaub
2018-02-25 08:48:53 -07:00
parent ef92649017
commit 4e6cf58de1
13 changed files with 76 additions and 73 deletions

View File

@@ -5,7 +5,7 @@ import {assert} from './asserts.js';
import {listen, unlisten, unlistenByKey} from './events.js';
import EventType from './events/EventType.js';
import {inherits} from './index.js';
import BaseObject from './Object.js';
import BaseObject, {getChangeEventType} from './Object.js';
import Geometry from './geom/Geometry.js';
import Style from './style/Style.js';
@@ -90,7 +90,7 @@ const Feature = function(opt_geometryOrProperties) {
this.geometryChangeKey_ = null;
listen(
this, BaseObject.getChangeEventType(this.geometryName_),
this, getChangeEventType(this.geometryName_),
this.handleGeometryChanged_, this);
if (opt_geometryOrProperties !== undefined) {
@@ -266,11 +266,11 @@ Feature.prototype.setId = function(id) {
*/
Feature.prototype.setGeometryName = function(name) {
unlisten(
this, BaseObject.getChangeEventType(this.geometryName_),
this, getChangeEventType(this.geometryName_),
this.handleGeometryChanged_, this);
this.geometryName_ = name;
listen(
this, BaseObject.getChangeEventType(this.geometryName_),
this, getChangeEventType(this.geometryName_),
this.handleGeometryChanged_, this);
this.handleGeometryChanged_();
};

View File

@@ -3,7 +3,7 @@
*/
import {inherits} from './index.js';
import GeolocationProperty from './GeolocationProperty.js';
import BaseObject from './Object.js';
import BaseObject, {getChangeEventType} from './Object.js';
import {listen} from './events.js';
import EventType from './events/EventType.js';
import {circular as circularPolygon} from './geom/Polygon.js';
@@ -79,10 +79,10 @@ const Geolocation = function(opt_options) {
this.watchId_ = undefined;
listen(
this, BaseObject.getChangeEventType(GeolocationProperty.PROJECTION),
this, getChangeEventType(GeolocationProperty.PROJECTION),
this.handleProjectionChanged_, this);
listen(
this, BaseObject.getChangeEventType(GeolocationProperty.TRACKING),
this, getChangeEventType(GeolocationProperty.TRACKING),
this.handleTrackingChanged_, this);
if (options.projection !== undefined) {

View File

@@ -7,6 +7,40 @@ import Observable from './Observable.js';
import Event from './events/Event.js';
import {assign} from './obj.js';
/**
* @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
*/
const BaseObjectEvent = function(type, key, oldValue) {
Event.call(this, type);
/**
* The name of the property whose value is changing.
* @type {string}
* @api
*/
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
*/
this.oldValue = oldValue;
};
inherits(BaseObjectEvent, Event);
/**
* @classdesc
* Abstract base class; normally only used for creating subclasses and not
@@ -85,11 +119,11 @@ const changeEventTypeCache = {};
* @param {string} key Key name.
* @return {string} Change name.
*/
BaseObject.getChangeEventType = function(key) {
export function getChangeEventType(key) {
return changeEventTypeCache.hasOwnProperty(key) ?
changeEventTypeCache[key] :
(changeEventTypeCache[key] = 'change:' + key);
};
}
/**
@@ -133,10 +167,10 @@ BaseObject.prototype.getProperties = function() {
*/
BaseObject.prototype.notify = function(key, oldValue) {
let eventType;
eventType = BaseObject.getChangeEventType(key);
this.dispatchEvent(new BaseObject.Event(eventType, key, oldValue));
eventType = getChangeEventType(key);
this.dispatchEvent(new BaseObjectEvent(eventType, key, oldValue));
eventType = ObjectEventType.PROPERTYCHANGE;
this.dispatchEvent(new BaseObject.Event(eventType, key, oldValue));
this.dispatchEvent(new BaseObjectEvent(eventType, key, oldValue));
};
@@ -191,35 +225,4 @@ BaseObject.prototype.unset = function(key, opt_silent) {
};
/**
* @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
*/
BaseObject.Event = function(type, key, oldValue) {
Event.call(this, type);
/**
* The name of the property whose value is changing.
* @type {string}
* @api
*/
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
*/
this.oldValue = oldValue;
};
inherits(BaseObject.Event, Event);
export default BaseObject;

View File

@@ -3,7 +3,7 @@
*/
import {inherits} from './index.js';
import MapEventType from './MapEventType.js';
import BaseObject from './Object.js';
import BaseObject, {getChangeEventType} from './Object.js';
import OverlayPositioning from './OverlayPositioning.js';
import {CLASS_SELECTABLE} from './css.js';
import {removeNode, removeChildren, outerWidth, outerHeight} from './dom.js';
@@ -126,23 +126,23 @@ const Overlay = function(options) {
this.mapPostrenderListenerKey = null;
listen(
this, BaseObject.getChangeEventType(Property.ELEMENT),
this, getChangeEventType(Property.ELEMENT),
this.handleElementChanged, this);
listen(
this, BaseObject.getChangeEventType(Property.MAP),
this, getChangeEventType(Property.MAP),
this.handleMapChanged, this);
listen(
this, BaseObject.getChangeEventType(Property.OFFSET),
this, getChangeEventType(Property.OFFSET),
this.handleOffsetChanged, this);
listen(
this, BaseObject.getChangeEventType(Property.POSITION),
this, getChangeEventType(Property.POSITION),
this.handlePositionChanged, this);
listen(
this, BaseObject.getChangeEventType(Property.POSITIONING),
this, getChangeEventType(Property.POSITIONING),
this.handlePositioningChanged, this);
if (options.element !== undefined) {

View File

@@ -10,7 +10,7 @@ import MapBrowserEventType from './MapBrowserEventType.js';
import MapEvent from './MapEvent.js';
import MapEventType from './MapEventType.js';
import MapProperty from './MapProperty.js';
import BaseObject from './Object.js';
import BaseObject, {getChangeEventType} from './Object.js';
import ObjectEventType from './ObjectEventType.js';
import TileQueue from './TileQueue.js';
import View from './View.js';
@@ -346,13 +346,13 @@ const PluggableMap = function(options) {
this.skippedFeatureUids_ = {};
listen(
this, BaseObject.getChangeEventType(MapProperty.LAYERGROUP),
this, getChangeEventType(MapProperty.LAYERGROUP),
this.handleLayerGroupChanged_, this);
listen(this, BaseObject.getChangeEventType(MapProperty.VIEW),
listen(this, getChangeEventType(MapProperty.VIEW),
this.handleViewChanged_, this);
listen(this, BaseObject.getChangeEventType(MapProperty.SIZE),
listen(this, getChangeEventType(MapProperty.SIZE),
this.handleSizeChanged_, this);
listen(this, BaseObject.getChangeEventType(MapProperty.TARGET),
listen(this, getChangeEventType(MapProperty.TARGET),
this.handleTargetChanged_, this);
// setProperties will trigger the rendering of the map if the map

View File

@@ -5,7 +5,7 @@
import {inherits} from '../index.js';
import {listen} from '../events.js';
import EventType from '../events/EventType.js';
import BaseObject from '../Object.js';
import {getChangeEventType} from '../Object.js';
import Control from '../control/Control.js';
import {getTransformFromProjections, identityTransform, get as getProjection} from '../proj.js';
@@ -48,7 +48,7 @@ const MousePosition = function(opt_options) {
});
listen(this,
BaseObject.getChangeEventType(PROJECTION),
getChangeEventType(PROJECTION),
this.handleProjectionChanged_, this);
if (options.coordinateFormat) {

View File

@@ -6,7 +6,7 @@ import Collection from '../Collection.js';
import PluggableMap from '../PluggableMap.js';
import MapEventType from '../MapEventType.js';
import MapProperty from '../MapProperty.js';
import BaseObject from '../Object.js';
import {getChangeEventType} from '../Object.js';
import ObjectEventType from '../ObjectEventType.js';
import Overlay from '../Overlay.js';
import OverlayPositioning from '../OverlayPositioning.js';
@@ -270,7 +270,7 @@ OverviewMap.prototype.handleMapPropertyChange_ = function(event) {
*/
OverviewMap.prototype.bindView_ = function(view) {
listen(view,
BaseObject.getChangeEventType(ViewProperty.ROTATION),
getChangeEventType(ViewProperty.ROTATION),
this.handleRotationChanged_, this);
};
@@ -282,7 +282,7 @@ OverviewMap.prototype.bindView_ = function(view) {
*/
OverviewMap.prototype.unbindView_ = function(view) {
unlisten(view,
BaseObject.getChangeEventType(ViewProperty.ROTATION),
getChangeEventType(ViewProperty.ROTATION),
this.handleRotationChanged_, this);
};

View File

@@ -2,7 +2,7 @@
* @module ol/control/ScaleLine
*/
import {inherits} from '../index.js';
import BaseObject from '../Object.js';
import {getChangeEventType} from '../Object.js';
import {assert} from '../asserts.js';
import Control from '../control/Control.js';
import ScaleLineUnits from '../control/ScaleLineUnits.js';
@@ -98,7 +98,7 @@ const ScaleLine = function(opt_options) {
});
listen(
this, BaseObject.getChangeEventType(UNITS),
this, getChangeEventType(UNITS),
this.handleUnitsChanged_, this);
this.setUnits(/** @type {ol.control.ScaleLineUnits} */ (options.units) ||

View File

@@ -6,7 +6,7 @@ import EventType from '../events/EventType.js';
import Feature from '../Feature.js';
import MapBrowserEventType from '../MapBrowserEventType.js';
import MapBrowserPointerEvent from '../MapBrowserPointerEvent.js';
import BaseObject from '../Object.js';
import {getChangeEventType} from '../Object.js';
import {squaredDistance as squaredCoordinateDistance} from '../coordinate.js';
import {listen} from '../events.js';
import Event from '../events/Event.js';
@@ -365,7 +365,7 @@ const Draw = function(options) {
}
listen(this,
BaseObject.getChangeEventType(InteractionProperty.ACTIVE),
getChangeEventType(InteractionProperty.ACTIVE),
this.updateState_, this);
};

View File

@@ -3,7 +3,7 @@
*/
import {inherits} from '../index.js';
import Collection from '../Collection.js';
import BaseObject from '../Object.js';
import {getChangeEventType} from '../Object.js';
import {listen} from '../events.js';
import Event from '../events/Event.js';
import {TRUE} from '../functions.js';
@@ -80,7 +80,7 @@ const Translate = function(opt_options) {
this.lastFeature_ = null;
listen(this,
BaseObject.getChangeEventType(InteractionProperty.ACTIVE),
getChangeEventType(InteractionProperty.ACTIVE),
this.handleActiveChanged_, this);
};

View File

@@ -4,7 +4,7 @@
import {getUid, inherits} from '../index.js';
import Collection from '../Collection.js';
import CollectionEventType from '../CollectionEventType.js';
import BaseObject from '../Object.js';
import {getChangeEventType} from '../Object.js';
import ObjectEventType from '../ObjectEventType.js';
import {assert} from '../asserts.js';
import {listen, unlistenByKey} from '../events.js';
@@ -58,7 +58,7 @@ const LayerGroup = function(opt_options) {
this.listenerKeys_ = {};
listen(this,
BaseObject.getChangeEventType(Property.LAYERS),
getChangeEventType(Property.LAYERS),
this.handleLayersChanged_, this);
if (layers) {

View File

@@ -3,7 +3,7 @@
*/
import {listen} from '../events.js';
import {inherits} from '../index.js';
import BaseObject from '../Object.js';
import {getChangeEventType} from '../Object.js';
import {createCanvasContext2D} from '../dom.js';
import VectorLayer from '../layer/Vector.js';
import {clamp} from '../math.js';
@@ -81,7 +81,7 @@ const Heatmap = function(opt_options) {
this.styleCache_ = null;
listen(this,
BaseObject.getChangeEventType(Property.GRADIENT),
getChangeEventType(Property.GRADIENT),
this.handleGradientChanged_, this);
this.setGradient(options.gradient ? options.gradient : DEFAULT_GRADIENT);
@@ -91,10 +91,10 @@ const Heatmap = function(opt_options) {
this.setRadius(options.radius !== undefined ? options.radius : 8);
listen(this,
BaseObject.getChangeEventType(Property.BLUR),
getChangeEventType(Property.BLUR),
this.handleStyleChanged_, this);
listen(this,
BaseObject.getChangeEventType(Property.RADIUS),
getChangeEventType(Property.RADIUS),
this.handleStyleChanged_, this);
this.handleStyleChanged_();

View File

@@ -4,7 +4,7 @@
import {listen, unlistenByKey} from '../events.js';
import EventType from '../events/EventType.js';
import {getUid, inherits} from '../index.js';
import BaseObject from '../Object.js';
import {getChangeEventType} from '../Object.js';
import BaseLayer from '../layer/Base.js';
import LayerProperty from '../layer/Property.js';
import {assign} from '../obj.js';
@@ -63,7 +63,7 @@ const Layer = function(options) {
}
listen(this,
BaseObject.getChangeEventType(LayerProperty.SOURCE),
getChangeEventType(LayerProperty.SOURCE),
this.handleSourcePropertyChange_, this);
const source = options.source ? options.source : null;