diff --git a/modules/presets/index.js b/modules/presets/index.js index 12f8e3a0e9..789c3cb9cf 100644 --- a/modules/presets/index.js +++ b/modules/presets/index.js @@ -19,14 +19,14 @@ export function presetIndex() { // a presetCollection with methods for // loading new data and returning defaults - var all = presetCollection([]), - defaults = { area: all, line: all, point: all, vertex: all, relation: all }, - fields = {}, - universal = [], - recent = presetCollection([]); + var all = presetCollection([]); + var _defaults = { area: all, line: all, point: all, vertex: all, relation: all }; + var _fields = {}; + var _universal = []; + var _recent = presetCollection([]); // Index of presets by (geometry, tag key). - var index = { + var _index = { point: {}, vertex: {}, line: {}, @@ -43,9 +43,9 @@ export function presetIndex() { geometry = 'point'; } - var geometryMatches = index[geometry], - best = -1, - match; + var geometryMatches = _index[geometry]; + var best = -1; + var match; for (var k in entity.tags) { // If any part of an address is present, @@ -86,9 +86,9 @@ export function presetIndex() { // (see `Way#isArea()`). In other words, the keys of L form the whitelist, // and the subkeys form the blacklist. all.areaKeys = function() { - var areaKeys = {}, - ignore = ['barrier', 'highway', 'footway', 'railway', 'type'], // probably a line.. - presets = _reject(all.collection, 'suggestion'); + var areaKeys = {}; + var ignore = ['barrier', 'highway', 'footway', 'railway', 'type']; // probably a line.. + var presets = _reject(all.collection, 'suggestion'); // whitelist presets.forEach(function(d) { @@ -123,21 +123,23 @@ export function presetIndex() { var d = data.presets; all.collection = []; - recent.collection = []; - fields = {}; - universal = []; - index = { point: {}, vertex: {}, line: {}, area: {}, relation: {} }; + _recent.collection = []; + _fields = {}; + _universal = []; + _index = { point: {}, vertex: {}, line: {}, area: {}, relation: {} }; if (d.fields) { _forEach(d.fields, function(d, id) { - fields[id] = presetField(id, d); - if (d.universal) universal.push(fields[id]); + _fields[id] = presetField(id, d); + if (d.universal) { + _universal.push(_fields[id]); + } }); } if (d.presets) { _forEach(d.presets, function(d, id) { - all.collection.push(presetPreset(id, d, fields)); + all.collection.push(presetPreset(id, d, _fields)); }); } @@ -149,7 +151,7 @@ export function presetIndex() { if (d.defaults) { var getItem = _bind(all.item, all); - defaults = { + _defaults = { area: presetCollection(d.defaults.area.map(getItem)), line: presetCollection(d.defaults.line.map(getItem)), point: presetCollection(d.defaults.point.map(getItem)), @@ -159,11 +161,11 @@ export function presetIndex() { } for (var i = 0; i < all.collection.length; i++) { - var preset = all.collection[i], - geometry = preset.geometry; + var preset = all.collection[i]; + var geometry = preset.geometry; for (var j = 0; j < geometry.length; j++) { - var g = index[geometry[j]]; + var g = _index[geometry[j]]; for (var k in preset.tags) { (g[k] = g[k] || []).push(preset); } @@ -174,23 +176,21 @@ export function presetIndex() { }; all.field = function(id) { - return fields[id]; + return _fields[id]; }; all.universal = function() { - return universal; + return _universal; }; all.defaults = function(geometry, n) { - var rec = recent.matchGeometry(geometry).collection.slice(0, 4), - def = _uniq(rec.concat(defaults[geometry].collection)).slice(0, n - 1); + var rec = _recent.matchGeometry(geometry).collection.slice(0, 4); + var def = _uniq(rec.concat(_defaults[geometry].collection)).slice(0, n - 1); return presetCollection(_uniq(rec.concat(def).concat(all.item(geometry)))); }; all.choose = function(preset) { - if (!preset.isFallback()) { - recent = presetCollection(_uniq([preset].concat(recent.collection))); - } + _recent = presetCollection(_uniq([preset].concat(_recent.collection))); return all; };