I have a method that is emitted from a child. The method is as follows to enable a single notification:
handleOne(name, enabled) {
if (!this.hasPerms()) {
return;
}
if (!!this.loggedInUser) {
this.toggleNotif({
notifName: name,
newAnalytics: {
type: 'brand',
true,
},
});
} else {
login.redir('new');
}
},
I want to create a new method that handles enabling all notifications. They require separate actions internally (toggleNotif
and toggleAllNotif
) but I also had these handlers separated. Here was the new method I created:
handleAll() {
if (!this.hasPerms()) {
return;
}
if (!!this.loggedInUser) {
this.toggleAllNotif({
newAnalytics: {
type: 'allBrand',
true,
},
});
} else {
login.redir('new');
}
},
they are sort of similar except the new one does not take arguments and the internal method calling the action is different. Would it make sense to refactor the handler into one method and made the params conditional or is that just messy and overthinking things? Kind of like this:
handleAll(turnOnAll=false, name=false, enabled=false) {
if (!this.hasPerms()) {
return;
}
if (!!this.loggedInUser) {
if (turnOnAll) {
this.toggleAllNotif({
newAnalytics: {
type: 'allBrand',
true,
},
});
} else {
this.toggleNotif({
notifName: name,
newAnalytics: {
type: 'brand',
true,
},
});
}
} else {
login.redir('new');
}
},