Skip to content

Commit

Permalink
Add support for calling promise.done with no arguments. Closes sequel…
Browse files Browse the repository at this point in the history
  • Loading branch information
janmeier committed Sep 13, 2014
1 parent 0b9ddfa commit 481d507
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Next
- [BUG] Fixed an issue with foreign key object syntax for hasOne and belongsTo
- [FEATURE] Added `field` and `name` to the object form of foreign key definitions
- [FEATURE] Added support for calling `Promise.done`, thus explicitly ending the promise chain by calling done with no arguments. Done with a function argument still continues the promise chain, to maintain BC.

#### Backwards compatability changes
- The `fieldName` property, used in associations with a foreign key object `(A.hasMany(B, { foreignKey: { ... }})`, has been renamed to `name` to avoid confusion with `field`.
Expand Down
6 changes: 6 additions & 0 deletions lib/promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,14 @@ SequelizePromise.prototype.error = function(fct) {
* @alias complete
* @return this
*/
var bluebirdDone = Promise.prototype.done;
SequelizePromise.prototype.done =
SequelizePromise.prototype.complete = function(fct) {
if (!fct) {
// If no callback is provided, map to the promise.done function, which explicitly ends a promise chain
return bluebirdDone.call(this);
}

if (fct.length > 2) {
return this.spread(function() {
fct.apply(null, [null].concat(Array.prototype.slice.call(arguments)));
Expand Down

0 comments on commit 481d507

Please sign in to comment.