From 587860844d32d6c6de21e43e9a120767d1e1aa6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Malbr=C3=A1n?= Date: Sun, 10 Mar 2013 04:46:25 -0300 Subject: [PATCH] Replacing $.each with Array.forEach or CollectionUtils.forEach --- src/editor/CodeHintList.js | 2 +- src/editor/CodeHintManager.js | 2 +- src/editor/InlineTextEditor.js | 4 ++-- src/preferences/PreferenceStorage.js | 9 +++++---- src/project/FileIndexManager.js | 5 +++-- src/project/ProjectManager.js | 2 +- src/strings.js | 11 ++++++----- src/utils/PerfUtils.js | 5 +++-- src/utils/StringMatch.js | 4 +++- 9 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/editor/CodeHintList.js b/src/editor/CodeHintList.js index 67683d33289..30f0238d9e4 100644 --- a/src/editor/CodeHintList.js +++ b/src/editor/CodeHintList.js @@ -191,7 +191,7 @@ define(function (require, exports, module) { this.handleClose(); } } else { - $.each(this.hints, function (index, item) { + this.hints.forEach(function (item, index) { if (index > self.maxResults) { return false; } diff --git a/src/editor/CodeHintManager.js b/src/editor/CodeHintManager.js index a6ca81cca90..0535aaeb1ca 100644 --- a/src/editor/CodeHintManager.js +++ b/src/editor/CodeHintManager.js @@ -398,7 +398,7 @@ define(function (require, exports, module) { var mode = editor.getModeForSelection(), enabledProviders = _getProvidersForMode(mode); - $.each(enabledProviders, function (index, item) { + enabledProviders.forEach(function (item, index) { if (item.provider.hasHints(editor, lastChar)) { sessionProvider = item.provider; return false; diff --git a/src/editor/InlineTextEditor.js b/src/editor/InlineTextEditor.js index f8da11e477a..372e2c5192e 100644 --- a/src/editor/InlineTextEditor.js +++ b/src/editor/InlineTextEditor.js @@ -64,8 +64,8 @@ define(function (require, exports, module) { var $dirtyIndicators = $(".inlineEditorHolder .dirty-indicator"), $indicator; - $.each($dirtyIndicators, function (index, indicator) { - $indicator = $(indicator); + $dirtyIndicators.each(function (index, indicator) { + $indicator = $(this); if ($indicator.data("fullPath") === doc.file.fullPath) { _showDirtyIndicator($indicator, doc.isDirty); } diff --git a/src/preferences/PreferenceStorage.js b/src/preferences/PreferenceStorage.js index 27f3f1d4ac2..6f780eace39 100644 --- a/src/preferences/PreferenceStorage.js +++ b/src/preferences/PreferenceStorage.js @@ -31,7 +31,8 @@ define(function (require, exports, module) { "use strict"; - var PreferencesManager = require("preferences/PreferencesManager"); + var PreferencesManager = require("preferences/PreferencesManager"), + CollectionUtils = require("utils/CollectionUtils"); /** * @private @@ -144,7 +145,7 @@ define(function (require, exports, module) { error = null; // validate all name/value pairs before committing - $.each(obj, function (key, value) { + CollectionUtils.forEach(obj, function (value, key) { try { _validateJSONPair(key, value); } catch (err) { @@ -162,13 +163,13 @@ define(function (require, exports, module) { // delete all exiting properties if not appending if (!append) { - $.each(this._json, function (key, value) { + CollectionUtils.forEach(this._json, function (value, key) { delete self._json[key]; }); } // copy properties from incoming JSON object - $.each(obj, function (key, value) { + CollectionUtils.forEach(obj, function (value, key) { self._json[key] = value; }); diff --git a/src/project/FileIndexManager.js b/src/project/FileIndexManager.js index 1b08620dc5e..b345b0e9736 100644 --- a/src/project/FileIndexManager.js +++ b/src/project/FileIndexManager.js @@ -42,6 +42,7 @@ define(function (require, exports, module) { var PerfUtils = require("utils/PerfUtils"), ProjectManager = require("project/ProjectManager"), Dialogs = require("widgets/Dialogs"), + CollectionUtils = require("utils/CollectionUtils"), Strings = require("strings"); /** @@ -134,7 +135,7 @@ define(function (require, exports, module) { var fileInfo = new FileInfo(entry); //console.log(entry.name); - $.each(_indexList, function (indexName, index) { + CollectionUtils.forEach(_indexList, function (index, indexName) { if (index.filterFunction(entry)) { index.fileInfos.push(fileInfo); } @@ -264,7 +265,7 @@ define(function (require, exports, module) { * @private */ function _clearIndexes() { - $.each(_indexList, function (indexName, index) { + CollectionUtils.forEach(_indexList, function (index, indexName) { index.fileInfos = []; }); } diff --git a/src/project/ProjectManager.js b/src/project/ProjectManager.js index dbb19537e24..30d62ab4ae1 100644 --- a/src/project/ProjectManager.js +++ b/src/project/ProjectManager.js @@ -465,7 +465,7 @@ define(function (require, exports, module) { node = null; // use path to lookup ID - $.each(toOpenPaths, function (index, value) { + toOpenPaths.forEach(function (value, index) { node = _projectInitialLoad.fullPathToIdMap[value]; if (node) { diff --git a/src/strings.js b/src/strings.js index 9beb8b68431..a87e062a67a 100644 --- a/src/strings.js +++ b/src/strings.js @@ -33,9 +33,10 @@ define(function (require, exports, module) { "use strict"; - var strings = require("i18n!nls/strings"), - Global = require("utils/Global"), - StringUtils = require("utils/StringUtils"); + var strings = require("i18n!nls/strings"), + Global = require("utils/Global"), + CollectionUtils = require("utils/CollectionUtils"), + StringUtils = require("utils/StringUtils"); var additionalGlobals = {}, parsedVersion = /([0-9]+)\.([0-9]+)\.([0-9]+)/.exec(brackets.metadata.version); @@ -52,8 +53,8 @@ define(function (require, exports, module) { additionalGlobals.BUILD_TYPE = (isDevBuild ? strings.DEVELOPMENT_BUILD : strings.EXPERIMENTAL_BUILD); // Insert application strings - Object.keys(strings).forEach(function (key) { - Object.keys(additionalGlobals).forEach(function (name) { + CollectionUtils.forEach(strings, function (value, key) { + CollectionUtils.forEach(additionalGlobals, function (item, name) { strings[key] = strings[key].replace(new RegExp("{" + name + "}", "g"), additionalGlobals[name]); }); }); diff --git a/src/utils/PerfUtils.js b/src/utils/PerfUtils.js index dd76063ab46..de5b01f3cbd 100644 --- a/src/utils/PerfUtils.js +++ b/src/utils/PerfUtils.js @@ -30,7 +30,8 @@ define(function (require, exports, module) { "use strict"; - var Global = require("utils/Global"); + var Global = require("utils/Global"), + CollectionUtils = require("utils/CollectionUtils"); /** * Flag to enable/disable performance data gathering. Default is true (enabled) @@ -299,7 +300,7 @@ define(function (require, exports, module) { var testName, index, result = ""; - $.each(perfData, function (testName, entry) { + CollectionUtils.forEach(perfData, function (entry, testName) { result += getValue(entry) + "\t" + testName + "\n"; }); diff --git a/src/utils/StringMatch.js b/src/utils/StringMatch.js index d02aa2ef889..760dbdd382f 100644 --- a/src/utils/StringMatch.js +++ b/src/utils/StringMatch.js @@ -28,6 +28,8 @@ define(function (require, exports, module) { "use strict"; + var CollectionUtils = require("utils/CollectionUtils"); + /* * Performs matching that is useful for QuickOpen and similar searches. */ @@ -715,7 +717,7 @@ define(function (require, exports, module) { function multiFieldSort(searchResults, fields) { // Move field names into an array, with primary field first var fieldNames = []; - $.each(fields, function (key, priority) { + CollectionUtils.forEach(fields, function (priority, key) { fieldNames[priority] = key; });