You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2013/01/10 15:33:53 UTC

js commit: [all] Refactor copy&paste in Contact.clone() into a helper function.

Updated Branches:
  refs/heads/master ea4e98bbd -> cc5327d58


[all] Refactor copy&paste in Contact.clone() into a helper function.


Project: http://git-wip-us.apache.org/repos/asf/cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-js/commit/cc5327d5
Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/cc5327d5
Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/cc5327d5

Branch: refs/heads/master
Commit: cc5327d586868f233021f722a1e1497d5d20e0db
Parents: ea4e98b
Author: Andrew Grieve <ag...@chromium.org>
Authored: Fri Jan 4 13:48:11 2013 -0500
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Thu Jan 10 09:33:49 2013 -0500

----------------------------------------------------------------------
 lib/common/plugin/Contact.js |   56 ++++++++++--------------------------
 1 files changed, 16 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-js/blob/cc5327d5/lib/common/plugin/Contact.js
----------------------------------------------------------------------
diff --git a/lib/common/plugin/Contact.js b/lib/common/plugin/Contact.js
index 1bd4078..70dac7a 100644
--- a/lib/common/plugin/Contact.js
+++ b/lib/common/plugin/Contact.js
@@ -122,50 +122,26 @@ Contact.prototype.remove = function(successCB, errorCB) {
 */
 Contact.prototype.clone = function() {
     var clonedContact = utils.clone(this);
-    var i;
     clonedContact.id = null;
     clonedContact.rawId = null;
-    // Loop through and clear out any id's in phones, emails, etc.
-    if (clonedContact.phoneNumbers) {
-        for (i = 0; i < clonedContact.phoneNumbers.length; i++) {
-            clonedContact.phoneNumbers[i].id = null;
-        }
-    }
-    if (clonedContact.emails) {
-        for (i = 0; i < clonedContact.emails.length; i++) {
-            clonedContact.emails[i].id = null;
-        }
-    }
-    if (clonedContact.addresses) {
-        for (i = 0; i < clonedContact.addresses.length; i++) {
-            clonedContact.addresses[i].id = null;
-        }
-    }
-    if (clonedContact.ims) {
-        for (i = 0; i < clonedContact.ims.length; i++) {
-            clonedContact.ims[i].id = null;
-        }
-    }
-    if (clonedContact.organizations) {
-        for (i = 0; i < clonedContact.organizations.length; i++) {
-            clonedContact.organizations[i].id = null;
-        }
-    }
-    if (clonedContact.categories) {
-        for (i = 0; i < clonedContact.categories.length; i++) {
-            clonedContact.categories[i].id = null;
-        }
-    }
-    if (clonedContact.photos) {
-        for (i = 0; i < clonedContact.photos.length; i++) {
-            clonedContact.photos[i].id = null;
-        }
-    }
-    if (clonedContact.urls) {
-        for (i = 0; i < clonedContact.urls.length; i++) {
-            clonedContact.urls[i].id = null;
+
+    function nullIds(arr) {
+        if (arr) {
+            for (var i = 0; i < arr.length; ++i) {
+                arr[i].id = null;
+            }
         }
     }
+
+    // Loop through and clear out any id's in phones, emails, etc.
+    nullIds(clonedContact.phoneNumbers);
+    nullIds(clonedContact.emails);
+    nullIds(clonedContact.addresses);
+    nullIds(clonedContact.ims);
+    nullIds(clonedContact.organizations);
+    nullIds(clonedContact.categories);
+    nullIds(clonedContact.photos);
+    nullIds(clonedContact.urls);
     return clonedContact;
 };