All this dispatcher stuff just strikes me as throwing good code after bad, and failing to leverage the obvious answer: OBJECTS.

It's not helping that your if/else/if/else is a card stacked example of how and when NOT to use if/else. It's all checking the same value. That's switch's job. Don't know if that was intentional, but it unfairly skews things in your favor.

Though the extra code "code for nothing" and "so where the blazes are these even defined" nature of said dispatcher stuff

Rather than that enumerated junk, make an object "userUpdateHandlers" of each of the various methods, as well as a default method. Have "reason" then simply be the string name instead of that extra "typing for nothing" junk, and simply:

userUpdateHandlers[reason in userUpdateHandlers ? reason : 'default'](user);

... and be done with it. And if you really want it enumerated too, use that enumerated reason as the indexes and make the handlers an array of function instead of an object of methods.

Far simpler, far less code.

Written by

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store