From 810ce0bf5dab22fcd4191f45a251912fc04df619 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Fri, 19 Sep 2014 15:26:57 -0300 Subject: [PATCH] small refactor --- js/models/Storage.js | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/js/models/Storage.js b/js/models/Storage.js index 8ccd4cda5..35cf1f976 100644 --- a/js/models/Storage.js +++ b/js/models/Storage.js @@ -223,23 +223,19 @@ Storage.prototype.getWallets = function(cb) { if (!l) return cb([]); - for (var ii in ids) { - // Create a closure for async calls. - (function() { - var id = ids[ii]; - self.getName(id, function(name) { - wallets.push({ - id: id, - name: name, - }); - if (++i == l) { - self.wListCache.data = wallets; - self.wListCache.ts = Date.now() + CACHE_DURATION; - return cb(wallets); - } + _.each(ids, function(id) { + self.getName(id, function(name) { + wallets.push({ + id: id, + name: name, }); - })(); - } + if (++i == l) { + self.wListCache.data = wallets; + self.wListCache.ts = Date.now() + CACHE_DURATION; + return cb(wallets); + } + }); + }); }); };