Echo JS 0.11.0

<~>
olalonde 4144 days ago. link 1 point
My favorite pattern are plain callbacks (plus Async library). It is also probably the most common pattern in Node.js land (although promises and events are also quite common). 

One reason I'm not personally a big fan of promises is that it makes it more verbose to pass around callbacks in some cases. For example:

Promise style:

    async.series([
      function (cb) {
        user.save()
          .success(function (user) { 
            cb(null, user); 
          }
          .error(cb);
      }
      // ...
    ], function (err) {
      // ...
    });


vs plain callback style:

    async.series([
      user.save.bind(user)
    ], function (err) {
      // ...
    });

Some other benefits of plain callback style: 

- Decoupling: how you handle the asynchronous code flow is up to you, not the library you are using. I personally like to use the "Async" library but it could easily be replaced by another library.

- Consistency: you don't have to worry about how the library you are using implements promises (some libraries have weird syntax/behavior).

edit: is there any way to format code snippets on EchoJS?

Replies