Why are Callbacks from Promise `.then` Methods an Anti-Pattern

You should change it to

var getTokens = function() {
      return $http.get('/api/tokens');
    };

And, then in other module use

yourModule.getTokens()
  .then(function(response) {
    // handle it
  });

As to why it’s an anti-pattern, I’d say that, first, it doesn’t allow you to further chain your success/fail handler methods. Second, it handles the control of processing the response from caller-module to called module (which might not be super-important here, but it still imposes same inversion of control). And finally, you add the concept of promises to your codebase, which might not be so easy to understand for some of the teammates, but then use promises as callbacks, so this really makes no sense.

Leave a Comment