Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions lib/extend.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@ module.exports = function (Potential, $Promise) {

//----- promise methods -----

$Promise.debounce = function (sourceFn) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$Promise is the internal promise class and is not exposed to the user — this can be placed on Potential, which is the library / public API namespace.

var pending;
function resetPending () {
pending = null;
}
resetPending();
return function () {
if (!pending) {
pending = Promise.resolve(sourceFn.apply(this, arguments));
pending.then(resetPending, resetPending);
}
return pending;
};
};

// syntactic sugar for adding error handlers
$Promise.prototype.catch = function (onRejected) {
return this.then(null, onRejected);
Expand Down