From 779981e0c25f54a57b75b07333ada368900c9b41 Mon Sep 17 00:00:00 2001 From: Omri Bernstein Date: Tue, 26 Jan 2016 12:14:52 -0500 Subject: [PATCH 1/2] Add debounce class method --- lib/extend.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/extend.js b/lib/extend.js index eea88da..ef5ee52 100644 --- a/lib/extend.js +++ b/lib/extend.js @@ -6,9 +6,24 @@ module.exports = function (Potential, $Promise) { //----- promise methods ----- + $Promise.debounce = function (sourceFn) { + 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); + return this.then(null, onRejected); }; }; From 8e44924856d54fe871df91d506ccbaaceb9622f0 Mon Sep 17 00:00:00 2001 From: Omri Bernstein Date: Tue, 26 Jan 2016 12:15:35 -0500 Subject: [PATCH 2/2] Fix indenting --- lib/extend.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/extend.js b/lib/extend.js index ef5ee52..1203780 100644 --- a/lib/extend.js +++ b/lib/extend.js @@ -23,7 +23,7 @@ module.exports = function (Potential, $Promise) { // syntactic sugar for adding error handlers $Promise.prototype.catch = function (onRejected) { - return this.then(null, onRejected); + return this.then(null, onRejected); }; };