I am reading this textbook about the Bookshelf . A bookshelf uses the Bluebird promises. Here are 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 still don't like promises, but from what I have learned so far, it seems strange. My question is that the above function is exactly the same as returning fetch()directly and rejecting the final then():
var getEvents = function(participantId) {
return new models.Participant()
.query({where: {id: participantId}})
.fetch({withRelated: ['events'], require: true});
};
That is, he still does the same thing, returns the same promise, can it be called in the same way, etc.?
From what I understand, the parameter of the function passed in thengets the return value of the previous promise in the chain. So, it seems to me that .then(function (a) { return a; })in general it’s just non-op. Correctly?
, ? ?