I\'m reading this tutorial about Bookshelf. Bookshelf uses Bluebird promises. There\'s quite a few examples that look something like this:
var getEvents = function(participantId) {
return new models.Participant()
.query({where: {id: participantId}})
.fetch({withRelated: [\'events\'], require: true})
.then(function(model) {
return model;
});
};
I\'m still not comfortable with promises, but from what I\'ve learned so far this seems odd. My question is, is the above function exactly the same as returning fetch()
directly and leaving off the final then()
:
var getEvents = function(participantId) {
return new models.Participant()
.query({where: {id: participantId}})
.fetch({withRelated: [\'events\'], require: true});
};
That is, it still does the same thing, returns the same promise, can be called in the same way, etc?
From what I understand, the parameter to the function passed to then
gets the return value of the previous promise in the chain. So, it seems to me like .then(function (a) { return a; })
in general is just a no-op. Right?
If they aren\'t the same, what\'s the difference? What\'s going on and why did the author write it that way?