Mholloway has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/316005

Change subject: Hygiene: Make adjustMemberKeys and fillInMemberKeys variadic
......................................................................

Hygiene: Make adjustMemberKeys and fillInMemberKeys variadic

Enables them to accept an arbitrary number of arguments (which is in line
with their intent).  Removes the need to wrap the desired changes in an
enclosing array, even if it's only a single change.  Makes calling them a
little cleaner.

Change-Id: I5d3ef6395342f67b5b88e284d1fe07fb2b235664
---
M lib/feed/most-read.js
M lib/mobile-util.js
M test/lib/mobile-util/mobile-util-test.js
3 files changed, 25 insertions(+), 24 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/mobileapps 
refs/changes/05/316005/1

diff --git a/lib/feed/most-read.js b/lib/feed/most-read.js
index 3fcd4fd..4eaea14 100644
--- a/lib/feed/most-read.js
+++ b/lib/feed/most-read.js
@@ -77,11 +77,10 @@
         var mainPageTitle = query && query.general && query.general.mainpage;
 
         if (normalizations) {
-            mUtil.adjustMemberKeys(normalizations, [['article', 'from'],
-                                                    ['title', 'to']]);
+            mUtil.adjustMemberKeys(normalizations, ['article', 'from'], 
['title', 'to']);
             mUtil.mergeByProp(goodTitles, normalizations, 'article');
         }
-        mUtil.fillInMemberKeys(goodTitles, [['title', 'article']]);
+        mUtil.fillInMemberKeys(goodTitles, ['title', 'article']);
         mUtil.mergeByProp(goodTitles, pages, 'title', true);
         goodTitles = blacklist.filterSpecialPages(goodTitles, mainPageTitle);
 
diff --git a/lib/mobile-util.js b/lib/mobile-util.js
index a32a7e6..ca85513 100644
--- a/lib/mobile-util.js
+++ b/lib/mobile-util.js
@@ -143,17 +143,18 @@
 /**
  * Takes an array of objects and makes the specified changes to the keys of 
each
  * member object.
- * @param {Array}  arr      an array of objects
- * @param {Array[]}  changes  an array of two-member arrays containing the 
desired
- *                          key changes, of the following form:
- *                          [['to', 'from'], ['to', 'from'], ...]
+ *
+ * E.g., adjustMemberKeys(arr, ['to', 'from'], ['to', 'from'], ...)
+ *
+ * @param {Array}  arr      an array of objects that will receive the change
+ * pairs passed in as additional params
  */
-mUtil.adjustMemberKeys = function(arr, changes) {
+mUtil.adjustMemberKeys = function(arr) {
     for (var i = 0, n = arr.length; i < n; i++) {
-        for (var j = 0, m = changes.length; j < m; j++) {
-            if (arr[i][changes[j][1]]) {
-                arr[i][changes[j][0]] = arr[i][changes[j][1]];
-                delete arr[i][changes[j][1]];
+        for (var j = 1, m = arguments.length; j < m; j++) {
+            if (arr[i][arguments[j][1]]) {
+                arr[i][arguments[j][0]] = arr[i][arguments[j][1]];
+                delete arr[i][arguments[j][1]];
             }
         }
     }
@@ -162,17 +163,18 @@
 /**
  * Takes an array of objects and, for each object, creates the specified key 
(if
  * not already present) with the same value as the specified source key for 
each
- * change pair.
- * @param {Array}  arr      an array of objects
- * @param {Array[]}  changes  an array of two-member arrays containing the 
desired
- *                          key changes, of the following form:
- *                          [['to', 'from'], ['to', 'from'], ...]
+ * change pair passed in as an additional parameter.
+ *
+ * E.g., fillInMemberKeys(arr, ['to', 'from'], ['to', 'from'], ...)
+ *
+ * @param {Array}  arr      an array of objects that will receive the change
+ * pairs passed in as additional params
  */
-mUtil.fillInMemberKeys = function(arr, changes) {
+mUtil.fillInMemberKeys = function(arr) {
     for (var i = 0, n = arr.length; i < n; i++) {
-        for (var j = 0, m = changes.length; j < m; j++) {
-            if (!arr[i][changes[j][0]]) {
-                arr[i][changes[j][0]] = arr[i][changes[j][1]];
+        for (var j = 1, m = arguments.length; j < m; j++) {
+            if (!arr[i][arguments[j][0]]) {
+                arr[i][arguments[j][0]] = arr[i][arguments[j][1]];
             }
         }
     }
diff --git a/test/lib/mobile-util/mobile-util-test.js 
b/test/lib/mobile-util/mobile-util-test.js
index 93bb986..58e9bf8 100644
--- a/test/lib/mobile-util/mobile-util-test.js
+++ b/test/lib/mobile-util/mobile-util-test.js
@@ -32,15 +32,15 @@
     });
 
     it('adjustMemberKeys should make the specified adjustments', function() {
-        mUtil.adjustMemberKeys(arr6, [['goodbye', 'hello'], ['sea', 'world']]);
+        mUtil.adjustMemberKeys(arr6, ['goodbye', 'hello'], ['sea', 'world']);
         assert.deepEqual(arr6, arr7);
 
-        mUtil.adjustMemberKeys(arr3, [['goodbye', 'hello'], ['sea', 'world']]);
+        mUtil.adjustMemberKeys(arr3, ['goodbye', 'hello'], ['sea', 'world']);
         assert.deepEqual(arr3, arr2);
     });
 
     it('fillInMemberKeys should make the specified adjustments', function() {
-        mUtil.fillInMemberKeys(arr3, [['world', 'goodbye'], ['again', 'sea']]);
+        mUtil.fillInMemberKeys(arr3, ['world', 'goodbye'], ['again', 'sea']);
         assert.deepEqual(arr3, arr4);
     });
 });

-- 
To view, visit https://gerrit.wikimedia.org/r/316005
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5d3ef6395342f67b5b88e284d1fe07fb2b235664
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/mobileapps
Gerrit-Branch: master
Gerrit-Owner: Mholloway <mhollo...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to