Use Object.values

This commit is contained in:
Tim Schaub
2022-07-27 15:03:47 -06:00
parent f2d989b299
commit 641bd7af33
6 changed files with 6 additions and 35 deletions

View File

@@ -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_);
}
/**

View File

@@ -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_ = {};

View File

@@ -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<K,V>} object The object from which to get the values.
* @return {!Array<V>} 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.

View File

@@ -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<import("../Feature.js").default<Geometry>>} */ (