[Vuejs]-Vue: refactoring 2 methods into 1 method with optional params?

0👍

The only thing that changes is the name, the toggleNotif, and the type, so use arguments to handle those cases:

handle(method, type, name) {
   if (!this.hasPerms()) {
      return;
   }
   if (!!this.loggedInUser) {
      this[method]({
         notifName: name,
         newAnalytics: {
            type,
            true,
         },
      });
   } else {
      login.redir('new');
   }
},

Then call, eg, handle('toggleNotif', 'brand', someName) or handle('toggleAllNotif', 'allBrand').

Leave a comment