Use Object.values
This commit is contained in:
@@ -9,7 +9,6 @@ import PointerEventType from './pointer/EventType.js';
|
|||||||
import Target from './events/Target.js';
|
import Target from './events/Target.js';
|
||||||
import {PASSIVE_EVENT_LISTENERS} from './has.js';
|
import {PASSIVE_EVENT_LISTENERS} from './has.js';
|
||||||
import {VOID} from './functions.js';
|
import {VOID} from './functions.js';
|
||||||
import {getValues} from './obj.js';
|
|
||||||
import {listen, unlistenByKey} from './events.js';
|
import {listen, unlistenByKey} from './events.js';
|
||||||
|
|
||||||
class MapBrowserEventHandler extends Target {
|
class MapBrowserEventHandler extends Target {
|
||||||
@@ -193,7 +192,7 @@ class MapBrowserEventHandler extends Target {
|
|||||||
) {
|
) {
|
||||||
this.trackedTouches_[id] = event;
|
this.trackedTouches_[id] = event;
|
||||||
}
|
}
|
||||||
this.activePointers_ = getValues(this.trackedTouches_);
|
this.activePointers_ = Object.values(this.trackedTouches_);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ import {
|
|||||||
toUserCoordinate,
|
toUserCoordinate,
|
||||||
} from '../proj.js';
|
} from '../proj.js';
|
||||||
import {getUid} from '../util.js';
|
import {getUid} from '../util.js';
|
||||||
import {getValues} from '../obj.js';
|
|
||||||
import {listen, unlistenByKey} from '../events.js';
|
import {listen, unlistenByKey} from '../events.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -324,7 +323,7 @@ class Snap extends PointerInteraction {
|
|||||||
* @return {boolean} If the event was consumed.
|
* @return {boolean} If the event was consumed.
|
||||||
*/
|
*/
|
||||||
handleUpEvent(evt) {
|
handleUpEvent(evt) {
|
||||||
const featuresToUpdate = getValues(this.pendingFeatures_);
|
const featuresToUpdate = Object.values(this.pendingFeatures_);
|
||||||
if (featuresToUpdate.length) {
|
if (featuresToUpdate.length) {
|
||||||
featuresToUpdate.forEach(this.updateFeature_.bind(this));
|
featuresToUpdate.forEach(this.updateFeature_.bind(this));
|
||||||
this.pendingFeatures_ = {};
|
this.pendingFeatures_ = {};
|
||||||
|
|||||||
@@ -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.
|
* Determine if an object has any properties.
|
||||||
* @param {Object} object The object to check.
|
* @param {Object} object The object to check.
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import {assert} from '../asserts.js';
|
|||||||
import {containsExtent, equals, wrapAndSliceX} from '../extent.js';
|
import {containsExtent, equals, wrapAndSliceX} from '../extent.js';
|
||||||
import {extend} from '../array.js';
|
import {extend} from '../array.js';
|
||||||
import {getUid} from '../util.js';
|
import {getUid} from '../util.js';
|
||||||
import {getValues, isEmpty} from '../obj.js';
|
import {isEmpty} from '../obj.js';
|
||||||
import {listen, unlistenByKey} from '../events.js';
|
import {listen, unlistenByKey} from '../events.js';
|
||||||
import {xhr} from '../featureloader.js';
|
import {xhr} from '../featureloader.js';
|
||||||
|
|
||||||
@@ -704,7 +704,7 @@ class VectorSource extends Source {
|
|||||||
} else if (this.featuresRtree_) {
|
} else if (this.featuresRtree_) {
|
||||||
features = this.featuresRtree_.getAll();
|
features = this.featuresRtree_.getAll();
|
||||||
if (!isEmpty(this.nullGeometryFeatures_)) {
|
if (!isEmpty(this.nullGeometryFeatures_)) {
|
||||||
extend(features, getValues(this.nullGeometryFeatures_));
|
extend(features, Object.values(this.nullGeometryFeatures_));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return /** @type {Array<import("../Feature.js").default<Geometry>>} */ (
|
return /** @type {Array<import("../Feature.js").default<Geometry>>} */ (
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ import {
|
|||||||
doubleClick,
|
doubleClick,
|
||||||
never,
|
never,
|
||||||
} from '../../../../../src/ol/events/condition.js';
|
} from '../../../../../src/ol/events/condition.js';
|
||||||
import {getValues} from '../../../../../src/ol/obj.js';
|
|
||||||
|
|
||||||
describe('ol.interaction.Modify', function () {
|
describe('ol.interaction.Modify', function () {
|
||||||
let target, map, layer, source, features;
|
let target, map, layer, source, features;
|
||||||
@@ -965,7 +964,7 @@ describe('ol.interaction.Modify', function () {
|
|||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
getModifyListeners = function (feature, modify) {
|
getModifyListeners = function (feature, modify) {
|
||||||
const listeners = feature.listeners_['change'];
|
const listeners = feature.listeners_['change'];
|
||||||
const candidates = getValues(modify);
|
const candidates = Object.values(modify);
|
||||||
return listeners.filter(function (listener) {
|
return listeners.filter(function (listener) {
|
||||||
return candidates.indexOf(listener) !== -1;
|
return candidates.indexOf(listener) !== -1;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import expect from '../expect.js';
|
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('ol/obj.js', () => {
|
||||||
describe('assign()', function () {
|
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 () {
|
describe('isEmpty()', function () {
|
||||||
it('checks if an object has any properties', function () {
|
it('checks if an object has any properties', function () {
|
||||||
expect(isEmpty({})).to.be(true);
|
expect(isEmpty({})).to.be(true);
|
||||||
|
|||||||
Reference in New Issue
Block a user