A switch is really for matching exact matches. There are some bad practices where you can use true in the switch for the match. If you are looking to clean up the code. You can easily use variables to pull out common stuff, still will be a lot of code.
var target = event.target
var cList = target.classList
if(cList.contains("follow-user")){
sendFollowRequest(target, 'subscribedUsers');
} else if(cList.contains("follow-hashtag")){
sendFollowRequest(target, 'subscribedHashtags');
} else if(cList.contains("follow-cat")){
sendFollowRequest(target, 'subscribedCategories');
}
Other option is using an object and loop
var subscribedOptions = {
'follow-user': 'subscribedUsers',
'follow-hashtag': 'subscribedHashtags',
'follow-cat': 'subscribedCategories',
}
function clicky(event) {
var target = event.target;
var cList = target.classList;
Object.entries(subscribedOptions).forEach(function(req) {
if (cList.contains(req[0])){
sendFollowRequest(target, req[1]);
}
})
}
function sendFollowRequest(target, action) {
console.log(target, action);
}
document.querySelectorAll(".bar").forEach(b => b.addEventListener("click", clicky))
<button class="foo bar follow-hashtag">foo bar follow-hashtag</button>
<button class="foo bar follow-user">foo bar follow-user</button>
<button class="foo bar follow-cat">foo bar follow-cat</button>