Although the library uses a function called then
, do not confuse with Promises.
The then
, in this context, executes the last executed function. See source code:
Consign.prototype.then = function(entity) {
this[this._lastOperation].call(this, entity);
return this;
};
In your example, you call include
first and then a call trail then
. In that case, you’re, behind the scenes, calling include
.
The then
makes sense when you use functions other than include
. Take this example:
consign()
.include('./config/passport.js') // muda o _lastOperation para include
.then('./config/middlewares.js') // chama o include
.then('./api') // chama o include
.then('./config/routes.js') // chama o include
.exclude('./config/test.js') // muda o _lastOperation para exclude
.then('./config/test.js') // chama o exclude
.then('./config/test2.js') // chama o exclude
.into(app)
At the end of the day, it’s just a syntactic sugar.
I’m not familiar with this library. Have you tried looking at the documentation?
– Luiz Felipe
Just look at the source code. You will notice that the
then
is nothing more than calling the last executed function again only with another meter. Despite the name, the function does not seem to work with Promises.– Cmte Cardeal
Here the code:
Consign.prototype.then = function(entity) {
 this[this._lastOperation].call(this, entity);
 return this;
};
– Cmte Cardeal
So basically in this code I posted, where I’m using just include, use . then and . include is the same thing??? Why did they create that . then???
– Bruno Nobre