Is. Then (function (a) {return a;}) "a no-op for promises?

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?

, ? ?

+4
2

, .then(function (a) { return a; }) - -op. ?

. 1

.

?

. promises.

1: , ?

, . . , ( ):
a) , , . .then() . ) a . , . , .

+9

, , , no-op, , no-op:

o = {};
Promise.resolve(o).then(o => o.then = () => {}); // make thenable
Promise.resolve(o).then(console.log); // logs the object
Promise.resolve(o).then(x => x).then(console.log); // doesn't log the object

, then(function(a) { return a; })

+4

Source: https://habr.com/ru/post/1663459/


All Articles