From 641bd7af33701f64d0d9bb4a94df00ed09dcba21 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Wed, 27 Jul 2022 15:03:47 -0600 Subject: [PATCH] Use Object.values --- src/ol/MapBrowserEventHandler.js | 3 +-- src/ol/interaction/Snap.js | 3 +-- src/ol/obj.js | 19 ------------------- src/ol/source/Vector.js | 4 ++-- .../spec/ol/interaction/modify.test.js | 3 +-- test/node/ol/obj.test.js | 9 +-------- 6 files changed, 6 insertions(+), 35 deletions(-) diff --git a/src/ol/MapBrowserEventHandler.js b/src/ol/MapBrowserEventHandler.js index aa52b2f2cf..f0cc0ecb69 100644 --- a/src/ol/MapBrowserEventHandler.js +++ b/src/ol/MapBrowserEventHandler.js @@ -9,7 +9,6 @@ import PointerEventType from './pointer/EventType.js'; import Target from './events/Target.js'; import {PASSIVE_EVENT_LISTENERS} from './has.js'; import {VOID} from './functions.js'; -import {getValues} from './obj.js'; import {listen, unlistenByKey} from './events.js'; class MapBrowserEventHandler extends Target { @@ -193,7 +192,7 @@ class MapBrowserEventHandler extends Target { ) { this.trackedTouches_[id] = event; } - this.activePointers_ = getValues(this.trackedTouches_); + this.activePointers_ = Object.values(this.trackedTouches_); } /** diff --git a/src/ol/interaction/Snap.js b/src/ol/interaction/Snap.js index 8ed90efe25..4395fb8e11 100644 --- a/src/ol/interaction/Snap.js +++ b/src/ol/interaction/Snap.js @@ -20,7 +20,6 @@ import { toUserCoordinate, } from '../proj.js'; import {getUid} from '../util.js'; -import {getValues} from '../obj.js'; import {listen, unlistenByKey} from '../events.js'; /** @@ -324,7 +323,7 @@ class Snap extends PointerInteraction { * @return {boolean} If the event was consumed. */ handleUpEvent(evt) { - const featuresToUpdate = getValues(this.pendingFeatures_); + const featuresToUpdate = Object.values(this.pendingFeatures_); if (featuresToUpdate.length) { featuresToUpdate.forEach(this.updateFeature_.bind(this)); this.pendingFeatures_ = {}; diff --git a/src/ol/obj.js b/src/ol/obj.js index 428fbf09af..e95e39d237 100644 --- a/src/ol/obj.js +++ b/src/ol/obj.js @@ -43,25 +43,6 @@ export function clear(object) { } } -/** - * Polyfill for Object.values(). Get an array of property values from an object. - * See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values - * - * @param {!Object} object The object from which to get the values. - * @return {!Array} The property values. - * @template K,V - */ -export const getValues = - typeof Object.values === 'function' - ? Object.values - : function (object) { - const values = []; - for (const property in object) { - values.push(object[property]); - } - return values; - }; - /** * Determine if an object has any properties. * @param {Object} object The object to check. diff --git a/src/ol/source/Vector.js b/src/ol/source/Vector.js index b0e45b5189..12b283c4a7 100644 --- a/src/ol/source/Vector.js +++ b/src/ol/source/Vector.js @@ -16,7 +16,7 @@ import {assert} from '../asserts.js'; import {containsExtent, equals, wrapAndSliceX} from '../extent.js'; import {extend} from '../array.js'; import {getUid} from '../util.js'; -import {getValues, isEmpty} from '../obj.js'; +import {isEmpty} from '../obj.js'; import {listen, unlistenByKey} from '../events.js'; import {xhr} from '../featureloader.js'; @@ -704,7 +704,7 @@ class VectorSource extends Source { } else if (this.featuresRtree_) { features = this.featuresRtree_.getAll(); if (!isEmpty(this.nullGeometryFeatures_)) { - extend(features, getValues(this.nullGeometryFeatures_)); + extend(features, Object.values(this.nullGeometryFeatures_)); } } return /** @type {Array>} */ ( diff --git a/test/browser/spec/ol/interaction/modify.test.js b/test/browser/spec/ol/interaction/modify.test.js index 3dfab0cac6..fc1217611e 100644 --- a/test/browser/spec/ol/interaction/modify.test.js +++ b/test/browser/spec/ol/interaction/modify.test.js @@ -25,7 +25,6 @@ import { doubleClick, never, } from '../../../../../src/ol/events/condition.js'; -import {getValues} from '../../../../../src/ol/obj.js'; describe('ol.interaction.Modify', function () { let target, map, layer, source, features; @@ -965,7 +964,7 @@ describe('ol.interaction.Modify', function () { beforeEach(function () { getModifyListeners = function (feature, modify) { const listeners = feature.listeners_['change']; - const candidates = getValues(modify); + const candidates = Object.values(modify); return listeners.filter(function (listener) { return candidates.indexOf(listener) !== -1; }); diff --git a/test/node/ol/obj.test.js b/test/node/ol/obj.test.js index 4cc1975011..5ae997553e 100644 --- a/test/node/ol/obj.test.js +++ b/test/node/ol/obj.test.js @@ -1,5 +1,5 @@ import expect from '../expect.js'; -import {assign, clear, getValues, isEmpty} from '../../../src/ol/obj.js'; +import {assign, clear, isEmpty} from '../../../src/ol/obj.js'; describe('ol/obj.js', () => { describe('assign()', function () { @@ -49,13 +49,6 @@ describe('ol/obj.js', () => { }); }); - describe('getValues()', function () { - it('gets a list of property values from an object', function () { - expect(getValues({foo: 'bar', num: 42}).sort()).to.eql([42, 'bar']); - expect(getValues([])).to.eql([]); - }); - }); - describe('isEmpty()', function () { it('checks if an object has any properties', function () { expect(isEmpty({})).to.be(true);