diff --git a/modules/core/history.js b/modules/core/history.js index d6194a561..db837d45c 100644 --- a/modules/core/history.js +++ b/modules/core/history.js @@ -9,7 +9,6 @@ import _isEmpty from 'lodash-es/isEmpty'; import _forEach from 'lodash-es/forEach'; import _map from 'lodash-es/map'; import _omit from 'lodash-es/omit'; -import _reduce from 'lodash-es/reduce'; import _reject from 'lodash-es/reject'; import _values from 'lodash-es/values'; import _without from 'lodash-es/without'; diff --git a/modules/presets/collection.js b/modules/presets/collection.js index f16960173..cddd64f3a 100644 --- a/modules/presets/collection.js +++ b/modules/presets/collection.js @@ -1,5 +1,6 @@ import _filter from 'lodash-es/filter'; import _find from 'lodash-es/find'; +import _findIndex from 'lodash-es/findIndex'; import _some from 'lodash-es/some'; import _uniq from 'lodash-es/uniq'; import _values from 'lodash-es/values'; @@ -23,6 +24,11 @@ export function presetCollection(collection) { }); }, + index: function(id) { + return _findIndex(this.collection, function(d) { + return d.id === id; + }); + }, matchGeometry: function(geometry) { return presetCollection(this.collection.filter(function(d) { diff --git a/modules/presets/index.js b/modules/presets/index.js index b99309e78..bade492ed 100644 --- a/modules/presets/index.js +++ b/modules/presets/index.js @@ -10,7 +10,6 @@ import { presetCategory } from './category'; import { presetCollection } from './collection'; import { presetField } from './field'; import { presetPreset } from './preset'; -import { utilQsString } from '../util'; export { presetCategory }; export { presetCollection }; @@ -138,7 +137,7 @@ export function presetIndex() { if (d.presets) { _forEach(d.presets, function(d, id) { - var existing = all.collection.findIndex(function(p) { return p.id === id; }); + var existing = all.index(id); if (existing !== -1) { all.collection[existing] = presetPreset(id, d, _fields, visible); } else { @@ -149,7 +148,7 @@ export function presetIndex() { if (d.categories) { _forEach(d.categories, function(d, id) { - var existing = all.collection.findIndex(function(p) { return p.id === id; }); + var existing = all.index(id); if (existing !== -1) { all.collection[existing] = presetCategory(id, d, all); } else { diff --git a/modules/services/maprules.js b/modules/services/maprules.js index b55f39017..65c863f53 100644 --- a/modules/services/maprules.js +++ b/modules/services/maprules.js @@ -187,7 +187,6 @@ export default { }, // adds from mapcss-parse selector check... addRule: function(selector) { - var _areaKeys = this._areaKeys; var rule = { // checks relevant to mapcss-selector checks: this.filterRuleChecks(selector), diff --git a/test/spec/presets/collection.js b/test/spec/presets/collection.js index 5b1b559b9..64db4bcb8 100644 --- a/test/spec/presets/collection.js +++ b/test/spec/presets/collection.js @@ -84,6 +84,15 @@ describe('iD.presetCollection', function() { }); }); + describe('#index', function() { + it('returns preset position in the collection', function() { + expect(c.index('point')).to.equal(0); + }); + it('return -1 when given id for preset not in the collection', function() { + expect(c.index('foobar')).to.equal(-1); + }); + }); + describe('#matchGeometry', function() { it('returns a new collection only containing presets matching a geometry', function() { expect(c.matchGeometry('area').collection).to.include.members( diff --git a/test/spec/services/maprules.js b/test/spec/services/maprules.js index 34b741b90..51d62f0cf 100644 --- a/test/spec/services/maprules.js +++ b/test/spec/services/maprules.js @@ -300,7 +300,7 @@ describe('maprules', function() { }); }); describe('rule', function() { - var selectors, entities; + var selectors; before(function() { selectors = [ {