There is a method that handles enabling a single notification, emitted from a child component:
handleOne(name, enabled) {
if (!this.hasPerms()) {
return;
}
if (!!this.loggedInUser) {
this.toggleNotif({
notifName: name,
newAnalytics: {
type: 'brand',
true,
},
});
} else {
login.redir('new');
}
},
A new method was created to handle enabling all notifications, which internally requires separate actions (toggleNotif
and toggleAllNotif
):
handleAll() {
if (!this.hasPerms()) {
return;
}
if (!!this.loggedInUser) {
this.toggleAllNotif({
newAnalytics: {
type: 'allBrand',
true,
},
});
} else {
login.redir('new');
}
},
The two methods are somewhat similar but differ in arguments and internal method calls. The question is whether it would be better to refactor the handler into one method with conditional parameters or if that would overcomplicate things:
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');
}
},