From 3795b1d1516071dac535f391f5bb797c74c2bbcc Mon Sep 17 00:00:00 2001 From: Matteo Pagliazzi Date: Wed, 11 Nov 2015 10:32:49 +0100 Subject: [PATCH] wip: starts upgrading lodash to v3 --- common/script/count.js | 6 ++--- common/script/src/content/helpers.js | 4 +--- package.json | 4 +--- tasks/gulp-transifex-test.js | 6 ++--- test/api-legacy/coupons.coffee | 22 ++++++++++++++----- test/common/user.fns.buy.test.js | 4 ++-- .../public/js/controllers/challengesCtrl.js | 2 +- website/public/js/services/guideServices.js | 2 +- website/public/js/services/statServices.js | 2 +- website/public/js/services/taskServices.js | 2 +- website/src/controllers/payments/index.js | 2 +- website/src/libs/analytics.js | 4 ++-- website/views/options/profile.jade | 2 +- 13 files changed, 35 insertions(+), 27 deletions(-) diff --git a/common/script/count.js b/common/script/count.js index de2bbf1227..bc32f4623f 100644 --- a/common/script/count.js +++ b/common/script/count.js @@ -11,7 +11,7 @@ function beastMasterProgress(pets) { _(DROP_ANIMALS).each(function(animal) { if(pets[animal] > 0 || pets[animal] == -1) count++ - }); + }).value(); return count; } @@ -22,7 +22,7 @@ function dropPetsCurrentlyOwned(pets) { _(DROP_ANIMALS).each(function(animal) { if(pets[animal] > 0) count++ - }); + }).value(); return count; } @@ -32,7 +32,7 @@ function mountMasterProgress(mounts) { _(DROP_ANIMALS).each(function(animal) { if (mounts[animal]) count++ - }); + }).value(); return count; } diff --git a/common/script/src/content/helpers.js b/common/script/src/content/helpers.js index 7413ac84d6..793884e42c 100644 --- a/common/script/src/content/helpers.js +++ b/common/script/src/content/helpers.js @@ -1,6 +1,4 @@ -import {each, defaults, assign} from 'lodash'; -import capitalize from 'lodash.capitalize'; -import camelCase from 'lodash.camelcase'; +import {each, defaults, assign, capitalize, camelCase} from 'lodash'; import i18n from '../i18n'; diff --git a/package.json b/package.json index 283ba5852d..3db0384304 100644 --- a/package.json +++ b/package.json @@ -51,9 +51,7 @@ "in-app-purchase": "^0.2.0", "jade": "~1.11.0", "js2xmlparser": "~0.1.2", - "lodash": "~2.4.1", - "lodash.camelcase": "^3.0.1", - "lodash.capitalize": "^3.0.0", + "lodash": "^3.10.1", "loggly": "~1.0.8", "marked": "^0.3.5", "merge-stream": "^1.0.0", diff --git a/tasks/gulp-transifex-test.js b/tasks/gulp-transifex-test.js index d4e6cdc3c3..6326069815 100644 --- a/tasks/gulp-transifex-test.js +++ b/tasks/gulp-transifex-test.js @@ -89,7 +89,7 @@ gulp.task('transifex:malformedStrings', () => { } }); }); - }); + }).value(); if (!_.isEmpty(stringsWithMalformedInterpolations)) { let message = 'The following strings have malformed or missing interpolations'; @@ -128,7 +128,7 @@ function eachTranslationFile(languages, cb) { cb(null, lang, filename, parsedEnglishFile, parsedTranslationFile) }); - }); + }).value(); } function eachTranslationString(languages, cb) { @@ -162,7 +162,7 @@ function getStringsWith(json, interpolationRegex) { var match = value.match(interpolationRegex); if(match) strings[file_name][key] = match; }); - }); + }).value(); return strings; } diff --git a/test/api-legacy/coupons.coffee b/test/api-legacy/coupons.coffee index e0fd380bf5..87c2c94a96 100644 --- a/test/api-legacy/coupons.coffee +++ b/test/api-legacy/coupons.coffee @@ -41,6 +41,7 @@ describe "Coupons", -> expect(coupons.length).to.equal 10 _(coupons).each (c)-> expect(c.event).to.equal 'wondercon' + .value() done() context "while regular user", -> @@ -73,7 +74,9 @@ describe "Coupons", -> codes = res.text expect(codes).to.contain('code') # Expect each coupon code _id to exist in response - _(coupons).each (c) -> expect(codes).to.contain(c._id) + _(coupons).each (c) -> + expect(codes).to.contain(c._id) + .value() done() @@ -89,9 +92,13 @@ describe "Coupons", -> secondHalf = sortedCoupons[5..9] # First five coupons should be present in codes - _(firstHalf).each (c) -> expect(codes).to.contain(c._id) + _(firstHalf).each (c) -> + expect(codes).to.contain(c._id) + .value() # Second five coupons should not be present in codes - _(secondHalf).each (c) -> expect(codes).to.not.contain(c._id) + _(secondHalf).each (c) -> + expect(codes).to.not.contain(c._id) + .value() done() it "gets last 5 coupons out of 10 when a limit of 5 is set", (done) -> @@ -106,9 +113,13 @@ describe "Coupons", -> secondHalf = sortedCoupons[5..9] # First five coupons should not be present in codes - _(firstHalf).each (c) -> expect(codes).to.not.contain(c._id) + _(firstHalf).each (c) -> + expect(codes).to.not.contain(c._id) + .value() # Second five coupons should be present in codes - _(secondHalf).each (c) -> expect(codes).to.contain(c._id) + _(secondHalf).each (c) -> + expect(codes).to.contain(c._id) + .value() done() context "while regular user", -> @@ -142,6 +153,7 @@ describe "Coupons", -> expect(gear[i]).to.exist else expect(gear[i]).to.not.exist + .value() beforeEach (done) -> registerNewUser -> diff --git a/test/common/user.fns.buy.test.js b/test/common/user.fns.buy.test.js index 677941a3d7..3eb91dcf0b 100644 --- a/test/common/user.fns.buy.test.js +++ b/test/common/user.fns.buy.test.js @@ -134,8 +134,8 @@ describe('user.fns.buy', function() { _(shared.content.gear.tree[type].armoire).each(function(gearObject, gearName) { var armoireKey = gearObject.key; fullArmoire[armoireKey] = true; - }); - }); + }).value(); + }).value(); beforeEach(function() { user.achievements.ultimateGearSets = { rogue: true }; diff --git a/website/public/js/controllers/challengesCtrl.js b/website/public/js/controllers/challengesCtrl.js index d60c15bd00..f6e09731fa 100644 --- a/website/public/js/controllers/challengesCtrl.js +++ b/website/public/js/controllers/challengesCtrl.js @@ -81,7 +81,7 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User', _(clonedTasks).each(function(val, type) { challenge[type + 's'].forEach(_cloneTaskAndPush); - }); + }).value(); $scope.obj = $scope.newChallenge = new Challenges.Challenge({ name: challenge.name, diff --git a/website/public/js/services/guideServices.js b/website/public/js/services/guideServices.js index 86c2c36cc7..e442be6199 100644 --- a/website/public/js/services/guideServices.js +++ b/website/public/js/services/guideServices.js @@ -209,7 +209,7 @@ function($rootScope, User, $timeout, $state, Analytics) { } User.set(ups); } - }) + }).value(); }); var tour = {}; diff --git a/website/public/js/services/statServices.js b/website/public/js/services/statServices.js index e836b39fb2..f2db805fb6 100644 --- a/website/public/js/services/statServices.js +++ b/website/public/js/services/statServices.js @@ -48,7 +48,7 @@ total += equipmentStat; } - }); + }).value(); return total; } diff --git a/website/public/js/services/taskServices.js b/website/public/js/services/taskServices.js index 3f968dfa6e..bbe7f6f689 100644 --- a/website/public/js/services/taskServices.js +++ b/website/public/js/services/taskServices.js @@ -36,7 +36,7 @@ _(cleansedTask.checklist).forEach(function(item) { item.completed = false; item.id = Shared.uuid(); - }); + }).value(); if (cleansedTask.type !== 'reward') { delete cleansedTask.value; diff --git a/website/src/controllers/payments/index.js b/website/src/controllers/payments/index.js index fd7f98a9c2..cf6d0dae90 100644 --- a/website/src/controllers/payments/index.js +++ b/website/src/controllers/payments/index.js @@ -60,7 +60,7 @@ exports.createSubscription = function(data, cb) { }).defaults({ // allow non-override if a plan was previously used dateCreated: new Date(), mysteryItems: [] - }); + }).value(); } // Block sub perks diff --git a/website/src/libs/analytics.js b/website/src/libs/analytics.js index 769a5cf8e1..315dc4b618 100644 --- a/website/src/libs/analytics.js +++ b/website/src/libs/analytics.js @@ -60,7 +60,7 @@ function _generateLabelForGoogleAnalytics(data) { label = data[key]; return false; // exit _.each early } - }); + }).value(); return label; } @@ -74,7 +74,7 @@ function _generateValueForGoogleAnalytics(data) { value = data[key]; return false; // exit _.each early } - }); + }).value(); return value; } diff --git a/website/views/options/profile.jade b/website/views/options/profile.jade index 8c4b437df8..68b78c5a12 100644 --- a/website/views/options/profile.jade +++ b/website/views/options/profile.jade @@ -4,7 +4,7 @@ mixin gemCost(cost) = ' ' + env.t('locked') block --var gearGroup = function(grouping) { return env._(env.Content.gear.flat).where({gearSet:grouping}).pluck('key') } +-var gearGroup = function(grouping) { return env._(env.Content.gear.flat).where({gearSet:grouping}).pluck('key').value() } -var showPath = function(path, items, joiner) { return path+'["'+items.join('"] '+joiner+' '+path+'["')+'"]'; } -var unlockPath = function(path, items) { return 'unlock("'+path+'.'+items.join(','+path+'.')+'")'; }