diff --git a/src/ol/Disposable.js b/src/ol/Disposable.js index 633e2017aa..b3d9ee28ac 100644 --- a/src/ol/Disposable.js +++ b/src/ol/Disposable.js @@ -1,7 +1,7 @@ /** * @module ol/Disposable */ -import {nullFunction} from './index.js'; +import {UNDEFINED} from './functions.js'; /** * Objects that need to clean up after themselves. @@ -30,5 +30,5 @@ Disposable.prototype.dispose = function() { * Extension point for disposable objects. * @protected */ -Disposable.prototype.disposeInternal = nullFunction; +Disposable.prototype.disposeInternal = UNDEFINED; export default Disposable; diff --git a/src/ol/View.js b/src/ol/View.js index 826bbb55dd..b8e473e5e9 100644 --- a/src/ol/View.js +++ b/src/ol/View.js @@ -2,7 +2,8 @@ * @module ol/View */ import {DEFAULT_TILE_SIZE} from './tilegrid/common.js'; -import {inherits, getUid, nullFunction} from './index.js'; +import {inherits, getUid} from './index.js'; +import {UNDEFINED} from './functions.js'; import {createExtent, none as centerNone} from './centerconstraint.js'; import BaseObject from './Object.js'; import {createSnapToResolutions, createSnapToPower} from './resolutionconstraint.js'; @@ -948,7 +949,7 @@ View.prototype.fit = function(geometryOrExtent, opt_options) { const centerX = centerRotX * cosAngle - centerRotY * sinAngle; const centerY = centerRotY * cosAngle + centerRotX * sinAngle; const center = [centerX, centerY]; - const callback = options.callback ? options.callback : nullFunction; + const callback = options.callback ? options.callback : UNDEFINED; if (options.duration !== undefined) { this.animate({ diff --git a/src/ol/control/Control.js b/src/ol/control/Control.js index d8207029a0..adfaa865ec 100644 --- a/src/ol/control/Control.js +++ b/src/ol/control/Control.js @@ -1,7 +1,8 @@ /** * @module ol/control/Control */ -import {inherits, nullFunction} from '../index.js'; +import {inherits} from '../index.js'; +import {UNDEFINED} from '../functions.js'; import MapEventType from '../MapEventType.js'; import BaseObject from '../Object.js'; import {removeNode} from '../dom.js'; @@ -67,7 +68,7 @@ const Control = function(options) { /** * @type {function(ol.MapEvent)} */ - this.render = options.render ? options.render : nullFunction; + this.render = options.render ? options.render : UNDEFINED; if (options.target) { this.setTarget(options.target); @@ -118,7 +119,7 @@ Control.prototype.setMap = function(map) { const target = this.target_ ? this.target_ : map.getOverlayContainerStopEvent(); target.appendChild(this.element); - if (this.render !== nullFunction) { + if (this.render !== UNDEFINED) { this.listenerKeys.push(listen(map, MapEventType.POSTRENDER, this.render, this)); } diff --git a/src/ol/events/EventTarget.js b/src/ol/events/EventTarget.js index e304322d43..1823574e9d 100644 --- a/src/ol/events/EventTarget.js +++ b/src/ol/events/EventTarget.js @@ -1,9 +1,10 @@ /** * @module ol/events/EventTarget */ -import {inherits, nullFunction} from '../index.js'; +import {inherits} from '../index.js'; import Disposable from '../Disposable.js'; import {unlistenAll} from '../events.js'; +import {UNDEFINED} from '../functions.js'; import Event from '../events/Event.js'; /** @@ -96,7 +97,7 @@ EventTarget.prototype.dispatchEvent = function(event) { let pendingRemovals = this.pendingRemovals_[type]; delete this.pendingRemovals_[type]; while (pendingRemovals--) { - this.removeEventListener(type, nullFunction); + this.removeEventListener(type, UNDEFINED); } delete this.dispatching_[type]; } @@ -147,7 +148,7 @@ EventTarget.prototype.removeEventListener = function(type, listener) { const index = listeners.indexOf(listener); if (type in this.pendingRemovals_) { // make listener a no-op, and remove later in #dispatchEvent() - listeners[index] = nullFunction; + listeners[index] = UNDEFINED; ++this.pendingRemovals_[type]; } else { listeners.splice(index, 1); diff --git a/src/ol/featureloader.js b/src/ol/featureloader.js index 14411cf176..08a7baf0a3 100644 --- a/src/ol/featureloader.js +++ b/src/ol/featureloader.js @@ -1,7 +1,7 @@ /** * @module ol/featureloader */ -import {nullFunction} from './index.js'; +import {UNDEFINED} from './functions.js'; import FormatType from './format/FormatType.js'; import {parse} from './xml.js'; @@ -88,11 +88,11 @@ export function loadFeaturesXhr(url, format, success, failure) { export function xhr(url, format) { return loadFeaturesXhr(url, format, /** - * @param {Array.} features The loaded features. - * @param {ol.proj.Projection} dataProjection Data projection. - * @this {ol.source.Vector} - */ + * @param {Array.} features The loaded features. + * @param {ol.proj.Projection} dataProjection Data projection. + * @this {ol.source.Vector} + */ function(features, dataProjection) { this.addFeatures(features); - }, /* FIXME handle error */ nullFunction); + }, /* FIXME handle error */ UNDEFINED); } diff --git a/src/ol/functions.js b/src/ol/functions.js index dba014d1e0..0850ce61b5 100644 --- a/src/ol/functions.js +++ b/src/ol/functions.js @@ -17,3 +17,10 @@ export function TRUE() { export function FALSE() { return false; } + +/** + * A reusable function, used e.g. as a default for callbacks. + * + * @return {undefined} Nothing. + */ +export function UNDEFINED() {} diff --git a/src/ol/index.js b/src/ol/index.js index b64bdd8289..9c7c3e603a 100644 --- a/src/ol/index.js +++ b/src/ol/index.js @@ -93,14 +93,6 @@ export function inherits(childCtor, parentCtor) { } -/** - * A reusable function, used e.g. as a default for callbacks. - * - * @return {undefined} Nothing. - */ -export function nullFunction() {} - - /** * Counter for getUid. * @type {number} diff --git a/src/ol/interaction/DragBox.js b/src/ol/interaction/DragBox.js index ff50216601..255482a011 100644 --- a/src/ol/interaction/DragBox.js +++ b/src/ol/interaction/DragBox.js @@ -3,8 +3,9 @@ */ // FIXME draw drag box import Event from '../events/Event.js'; -import {inherits, nullFunction} from '../index.js'; +import {inherits} from '../index.js'; import {always, mouseOnly, mouseActionButton} from '../events/condition.js'; +import {UNDEFINED} from '../functions.js'; import PointerInteraction from '../interaction/Pointer.js'; import RenderBox from '../render/Box.js'; @@ -182,7 +183,7 @@ DragBox.prototype.getGeometry = function() { * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event. * @protected */ -DragBox.prototype.onBoxEnd = nullFunction; +DragBox.prototype.onBoxEnd = UNDEFINED; /** diff --git a/src/ol/interaction/Pointer.js b/src/ol/interaction/Pointer.js index 5f3cbd96be..00981d061f 100644 --- a/src/ol/interaction/Pointer.js +++ b/src/ol/interaction/Pointer.js @@ -1,8 +1,8 @@ /** * @module ol/interaction/Pointer */ -import {inherits, nullFunction} from '../index.js'; -import {FALSE} from '../functions.js'; +import {inherits} from '../index.js'; +import {FALSE, UNDEFINED} from '../functions.js'; import MapBrowserEventType from '../MapBrowserEventType.js'; import MapBrowserPointerEvent from '../MapBrowserPointerEvent.js'; import Interaction from '../interaction/Interaction.js'; @@ -13,7 +13,7 @@ import {getValues} from '../obj.js'; * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. * @this {ol.interaction.Pointer} */ -const handleDragEvent = nullFunction; +const handleDragEvent = UNDEFINED; /** @@ -36,7 +36,7 @@ const handleDownEvent = FALSE; * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event. * @this {ol.interaction.Pointer} */ -const handleMoveEvent = nullFunction; +const handleMoveEvent = UNDEFINED; /** diff --git a/src/ol/render/Feature.js b/src/ol/render/Feature.js index aae1cc60ee..1a0541f175 100644 --- a/src/ol/render/Feature.js +++ b/src/ol/render/Feature.js @@ -1,7 +1,7 @@ /** * @module ol/render/Feature */ -import {nullFunction} from '../index.js'; +import {UNDEFINED} from '../functions.js'; import {extend} from '../array.js'; import {createOrUpdateFromCoordinate, createOrUpdateFromFlatCoordinates, getCenter, getHeight} from '../extent.js'; import GeometryType from '../geom/GeometryType.js'; @@ -244,7 +244,7 @@ RenderFeature.prototype.getStride = function() { /** * @return {undefined} */ -RenderFeature.prototype.getStyleFunction = nullFunction; +RenderFeature.prototype.getStyleFunction = UNDEFINED; /** diff --git a/src/ol/render/canvas/Replay.js b/src/ol/render/canvas/Replay.js index f3253383d3..afa467d860 100644 --- a/src/ol/render/canvas/Replay.js +++ b/src/ol/render/canvas/Replay.js @@ -1,7 +1,8 @@ /** * @module ol/render/canvas/Replay */ -import {getUid, inherits, nullFunction} from '../../index.js'; +import {getUid, inherits} from '../../index.js'; +import {UNDEFINED} from '../../functions.js'; import {equals, reverseSubArray} from '../../array.js'; import {asColorLike} from '../../colorlike.js'; import {buffer, clone, coordinateRelationship, createEmpty, createOrUpdate, @@ -1068,7 +1069,7 @@ CanvasReplay.prototype.endGeometry = function(geometry, feature) { /** * FIXME empty description for jsdoc */ -CanvasReplay.prototype.finish = nullFunction; +CanvasReplay.prototype.finish = UNDEFINED; /** diff --git a/src/ol/renderer/Layer.js b/src/ol/renderer/Layer.js index bb64ce9e79..492c5ef242 100644 --- a/src/ol/renderer/Layer.js +++ b/src/ol/renderer/Layer.js @@ -1,13 +1,13 @@ /** * @module ol/renderer/Layer */ -import {getUid, inherits, nullFunction} from '../index.js'; +import {getUid, inherits} from '../index.js'; import ImageState from '../ImageState.js'; import Observable from '../Observable.js'; import TileState from '../TileState.js'; import {listen} from '../events.js'; import EventType from '../events/EventType.js'; -import {FALSE} from '../functions.js'; +import {FALSE, UNDEFINED} from '../functions.js'; import SourceState from '../source/State.js'; /** @@ -42,7 +42,7 @@ inherits(LayerRenderer, Observable); * @return {T|undefined} Callback result. * @template S,T */ -LayerRenderer.prototype.forEachFeatureAtCoordinate = nullFunction; +LayerRenderer.prototype.forEachFeatureAtCoordinate = UNDEFINED; /** diff --git a/src/ol/renderer/Map.js b/src/ol/renderer/Map.js index e4aaf05695..6aac6da47c 100644 --- a/src/ol/renderer/Map.js +++ b/src/ol/renderer/Map.js @@ -1,12 +1,12 @@ /** * @module ol/renderer/Map */ -import {getUid, inherits, nullFunction} from '../index.js'; +import {getUid, inherits} from '../index.js'; import Disposable from '../Disposable.js'; import {listen, unlistenByKey} from '../events.js'; import EventType from '../events/EventType.js'; import {getWidth} from '../extent.js'; -import {TRUE} from '../functions.js'; +import {TRUE, UNDEFINED} from '../functions.js'; import {visibleAtResolution} from '../layer/Layer.js'; import {getLayerRendererPlugins} from '../plugins.js'; import {iconImageCache} from '../style.js'; @@ -289,7 +289,7 @@ MapRenderer.prototype.removeLayerRendererByKey_ = function(layerKey) { * Render. * @param {?olx.FrameState} frameState Frame state. */ -MapRenderer.prototype.renderFrame = nullFunction; +MapRenderer.prototype.renderFrame = UNDEFINED; /** diff --git a/src/ol/renderer/canvas/IntermediateCanvas.js b/src/ol/renderer/canvas/IntermediateCanvas.js index f2ff25a5a4..2193b8ed72 100644 --- a/src/ol/renderer/canvas/IntermediateCanvas.js +++ b/src/ol/renderer/canvas/IntermediateCanvas.js @@ -1,10 +1,11 @@ /** * @module ol/renderer/canvas/IntermediateCanvas */ -import {inherits, nullFunction} from '../../index.js'; +import {inherits} from '../../index.js'; import {scale as scaleCoordinate} from '../../coordinate.js'; import {createCanvasContext2D} from '../../dom.js'; import {containsExtent, intersects} from '../../extent.js'; +import {UNDEFINED} from '../../functions.js'; import CanvasLayerRenderer from '../canvas/Layer.js'; import {create as createTransform, apply as applyTransform} from '../../transform.js'; @@ -123,7 +124,7 @@ IntermediateCanvasRenderer.prototype.forEachLayerAtCoordinate = function(coordin return undefined; } - if (this.getLayer().getSource().forEachFeatureAtCoordinate !== nullFunction) { + if (this.getLayer().getSource().forEachFeatureAtCoordinate !== UNDEFINED) { // for ImageCanvas sources use the original hit-detection logic, // so that for example also transparent polygons are detected return CanvasLayerRenderer.prototype.forEachLayerAtCoordinate.apply(this, arguments); diff --git a/src/ol/renderer/webgl/ImageLayer.js b/src/ol/renderer/webgl/ImageLayer.js index 9f46e75ddd..60522eed4c 100644 --- a/src/ol/renderer/webgl/ImageLayer.js +++ b/src/ol/renderer/webgl/ImageLayer.js @@ -2,7 +2,8 @@ * @module ol/renderer/webgl/ImageLayer */ import {ENABLE_RASTER_REPROJECTION} from '../../reproj/common.js'; -import {inherits, nullFunction} from '../../index.js'; +import {inherits} from '../../index.js'; +import {UNDEFINED} from '../../functions.js'; import LayerType from '../../LayerType.js'; import ViewHint from '../../ViewHint.js'; import {createCanvasContext2D} from '../../dom.js'; @@ -254,7 +255,7 @@ WebGLImageLayerRenderer.prototype.forEachLayerAtPixel = function(pixel, frameSta return undefined; } - if (this.getLayer().getSource().forEachFeatureAtCoordinate !== nullFunction) { + if (this.getLayer().getSource().forEachFeatureAtCoordinate !== UNDEFINED) { // for ImageCanvas sources use the original hit-detection logic, // so that for example also transparent polygons are detected const coordinate = applyTransform( diff --git a/src/ol/source/Source.js b/src/ol/source/Source.js index b466290e0f..495d4028bd 100644 --- a/src/ol/source/Source.js +++ b/src/ol/source/Source.js @@ -1,7 +1,8 @@ /** * @module ol/source/Source */ -import {inherits, nullFunction} from '../index.js'; +import {inherits} from '../index.js'; +import {UNDEFINED} from '../functions.js'; import BaseObject from '../Object.js'; import {get as getProjection} from '../proj.js'; import SourceState from '../source/State.js'; @@ -89,7 +90,7 @@ Source.prototype.adaptAttributions_ = function(attributionLike) { * @return {T|undefined} Callback result. * @template T */ -Source.prototype.forEachFeatureAtCoordinate = nullFunction; +Source.prototype.forEachFeatureAtCoordinate = UNDEFINED; /** diff --git a/src/ol/source/Tile.js b/src/ol/source/Tile.js index 232b23c89f..a24109f923 100644 --- a/src/ol/source/Tile.js +++ b/src/ol/source/Tile.js @@ -1,7 +1,8 @@ /** * @module ol/source/Tile */ -import {inherits, nullFunction} from '../index.js'; +import {inherits} from '../index.js'; +import {UNDEFINED} from '../functions.js'; import TileCache from '../TileCache.js'; import TileState from '../TileState.js'; import Event from '../events/Event.js'; @@ -303,7 +304,7 @@ TileSource.prototype.refresh = function() { * @param {number} y Tile coordinate y. * @param {ol.proj.Projection} projection Projection. */ -TileSource.prototype.useTile = nullFunction; +TileSource.prototype.useTile = UNDEFINED; /** diff --git a/src/ol/source/Vector.js b/src/ol/source/Vector.js index 5479cc65c2..5189ebf2f8 100644 --- a/src/ol/source/Vector.js +++ b/src/ol/source/Vector.js @@ -2,7 +2,7 @@ * @module ol/source/Vector */ -import {getUid, inherits, nullFunction} from '../index.js'; +import {getUid, inherits} from '../index.js'; import Collection from '../Collection.js'; import CollectionEventType from '../CollectionEventType.js'; import ObjectEventType from '../ObjectEventType.js'; @@ -13,7 +13,7 @@ import Event from '../events/Event.js'; import EventType from '../events/EventType.js'; import {containsExtent, equals} from '../extent.js'; import {xhr} from '../featureloader.js'; -import {TRUE} from '../functions.js'; +import {TRUE, UNDEFINED} from '../functions.js'; import {all as allStrategy} from '../loadingstrategy.js'; import {isEmpty, getValues} from '../obj.js'; import Source from '../source/Source.js'; @@ -75,7 +75,7 @@ const VectorSource = function(opt_options) { * @private * @type {ol.FeatureLoader} */ - this.loader_ = nullFunction; + this.loader_ = UNDEFINED; /** * @private diff --git a/src/ol/style/AtlasManager.js b/src/ol/style/AtlasManager.js index 81df116720..d3e9ee0239 100644 --- a/src/ol/style/AtlasManager.js +++ b/src/ol/style/AtlasManager.js @@ -1,7 +1,8 @@ /** * @module ol/style/AtlasManager */ -import {WEBGL_MAX_TEXTURE_SIZE, nullFunction} from '../index.js'; +import {WEBGL_MAX_TEXTURE_SIZE} from '../index.js'; +import {UNDEFINED} from '../functions.js'; import Atlas from '../style/Atlas.js'; @@ -180,7 +181,7 @@ AtlasManager.prototype.add = function(id, width, height, // the hit-detection atlas, to make sure that the offset is the same for // the original image and the hit-detection image. const renderHitCallback = opt_renderHitCallback !== undefined ? - opt_renderHitCallback : nullFunction; + opt_renderHitCallback : UNDEFINED; const hitInfo = /** @type {ol.AtlasInfo} */ (this.add_(true, id, width, height, renderHitCallback, opt_this)); diff --git a/test/spec/ol/renderer/vector.test.js b/test/spec/ol/renderer/vector.test.js index e66cf9a80c..b38a8dc6d5 100644 --- a/test/spec/ol/renderer/vector.test.js +++ b/test/spec/ol/renderer/vector.test.js @@ -1,4 +1,4 @@ -import {nullFunction} from '../../../../src/ol/index.js'; +import {UNDEFINED} from '../../../../src/ol/functions.js'; import {getListeners} from '../../../../src/ol/events.js'; import LineString from '../../../../src/ol/geom/LineString.js'; import Point from '../../../../src/ol/geom/Point.js'; @@ -77,7 +77,7 @@ describe('ol.renderer.vector', function() { const imageReplay = replayGroup.getReplay( style.getZIndex(), 'Image'); const setImageStyleSpy = sinon.spy(imageReplay, 'setImageStyle'); - const drawPointSpy = sinon.stub(imageReplay, 'drawPoint').callsFake(nullFunction); + const drawPointSpy = sinon.stub(imageReplay, 'drawPoint').callsFake(UNDEFINED); renderFeature(replayGroup, feature, style, squaredTolerance, listener, listenerThis); expect(setImageStyleSpy.called).to.be(false); @@ -90,7 +90,7 @@ describe('ol.renderer.vector', function() { const imageReplay = replayGroup.getReplay( style.getZIndex(), 'Image'); const setImageStyleSpy = sinon.spy(imageReplay, 'setImageStyle'); - const drawMultiPointSpy = sinon.stub(imageReplay, 'drawMultiPoint').callsFake(nullFunction); + const drawMultiPointSpy = sinon.stub(imageReplay, 'drawMultiPoint').callsFake(UNDEFINED); renderFeature(replayGroup, feature, style, squaredTolerance, listener, listenerThis); expect(setImageStyleSpy.called).to.be(false); @@ -104,7 +104,7 @@ describe('ol.renderer.vector', function() { style.getZIndex(), 'LineString'); const setFillStrokeStyleSpy = sinon.spy(lineStringReplay, 'setFillStrokeStyle'); - const drawLineStringSpy = sinon.stub(lineStringReplay, 'drawLineString').callsFake(nullFunction); + const drawLineStringSpy = sinon.stub(lineStringReplay, 'drawLineString').callsFake(UNDEFINED); renderFeature(replayGroup, feature, style, squaredTolerance, listener, listenerThis); expect(setFillStrokeStyleSpy.called).to.be(true); @@ -119,7 +119,7 @@ describe('ol.renderer.vector', function() { style.getZIndex(), 'LineString'); const setFillStrokeStyleSpy = sinon.spy(lineStringReplay, 'setFillStrokeStyle'); - const drawMultiLineStringSpy = sinon.stub(lineStringReplay, 'drawMultiLineString').callsFake(nullFunction); + const drawMultiLineStringSpy = sinon.stub(lineStringReplay, 'drawMultiLineString').callsFake(UNDEFINED); renderFeature(replayGroup, feature, style, squaredTolerance, listener, listenerThis); expect(setFillStrokeStyleSpy.called).to.be(true); @@ -135,7 +135,7 @@ describe('ol.renderer.vector', function() { style.getZIndex(), 'Polygon'); const setFillStrokeStyleSpy = sinon.spy(polygonReplay, 'setFillStrokeStyle'); - const drawPolygonSpy = sinon.stub(polygonReplay, 'drawPolygon').callsFake(nullFunction); + const drawPolygonSpy = sinon.stub(polygonReplay, 'drawPolygon').callsFake(UNDEFINED); renderFeature(replayGroup, feature, style, squaredTolerance, listener, listenerThis); expect(setFillStrokeStyleSpy.called).to.be(true); @@ -151,7 +151,7 @@ describe('ol.renderer.vector', function() { style.getZIndex(), 'Polygon'); const setFillStrokeStyleSpy = sinon.spy(polygonReplay, 'setFillStrokeStyle'); - const drawMultiPolygonSpy = sinon.stub(polygonReplay, 'drawMultiPolygon').callsFake(nullFunction); + const drawMultiPolygonSpy = sinon.stub(polygonReplay, 'drawMultiPolygon').callsFake(UNDEFINED); renderFeature(replayGroup, feature, style, squaredTolerance, listener, listenerThis); expect(setFillStrokeStyleSpy.called).to.be(true); diff --git a/test/spec/ol/style/iconimagecache.test.js b/test/spec/ol/style/iconimagecache.test.js index d53ab20e41..9128e37494 100644 --- a/test/spec/ol/style/iconimagecache.test.js +++ b/test/spec/ol/style/iconimagecache.test.js @@ -1,4 +1,4 @@ -import {nullFunction} from '../../../../src/ol/index.js'; +import {UNDEFINED} from '../../../../src/ol/functions.js'; import {listen} from '../../../../src/ol/events.js'; import {iconImageCache} from '../../../../src/ol/style.js'; import IconImage from '../../../../src/ol/style/IconImage.js'; @@ -42,13 +42,13 @@ describe('ol.style.IconImageCache', function() { src = '0'; iconImage = new IconImage(null, src); - listen(iconImage, 'change', nullFunction, false); + listen(iconImage, 'change', UNDEFINED, false); iconImageCache.set(src, null, null, iconImage); expect(iconImageCache.cacheSize_).to.eql(4); src = '4'; iconImage = new IconImage(null, src); - listen(iconImage, 'change', nullFunction, false); + listen(iconImage, 'change', UNDEFINED, false); iconImageCache.set(src, null, null, iconImage); expect(iconImageCache.cacheSize_).to.eql(5);