refactor(client): extract find pet logic into function

This commit is contained in:
Blade Barringer
2016-09-15 22:02:11 -05:00
parent 4ad50b9d30
commit 9c0998c29a

View File

@@ -378,18 +378,22 @@ habitrpg.controller("InventoryCtrl",
}; };
$scope.shouldShowPremiumMountSection = function () { $scope.shouldShowPremiumMountSection = function () {
var pets = Object.keys(user.items.pets); return findPet(function (pet) {
return pets.find(function (petKey) {
var pet = Content.petInfo[petKey];
return pet.type === 'premium'; return pet.type === 'premium';
}); });
}; };
$scope.hasAPetOfPotion = function (potion) { $scope.hasAPetOfPotion = function (potion) {
return findPet(function (pet) {
return pet.potion === potion;
});
};
function findPet (fn) {
var pets = Object.keys(user.items.pets); var pets = Object.keys(user.items.pets);
return pets.find(function (petKey) { return pets.find(function (petKey) {
var pet = Content.petInfo[petKey]; var pet = Content.petInfo[petKey];
return pet.potion === potion; return fn(pet);
}); });
} }