Catrope has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/208328

Change subject: Add OO.ui.debounce() utility
......................................................................

Add OO.ui.debounce() utility

Moved from ve.debounce(); originally ported from underscore.js

Change-Id: Iefcba48819cc71436e785cf98c7b74d8c7d1fbaf
---
M src/core.js
1 file changed, 32 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/oojs/ui refs/changes/28/208328/1

diff --git a/src/core.js b/src/core.js
index 0aba95b..423c376 100644
--- a/src/core.js
+++ b/src/core.js
@@ -137,6 +137,38 @@
 };
 
 /**
+ * Return a function, that, as long as it continues to be invoked, will not
+ * be triggered. The function will be called after it stops being called for
+ * N milliseconds. If `immediate` is passed, trigger the function on the
+ * leading edge, instead of the trailing.
+ *
+ * Ported from: http://underscorejs.org/underscore.js
+ *
+ * @param {Function} func
+ * @param {number} wait
+ * @param {boolean} immediate
+ * @returns {Function}
+ */
+OO.ui.debounce = function ( func, wait, immediate ) {
+       var timeout;
+       return function () {
+               var context = this,
+                       args = arguments,
+                       later = function () {
+                               timeout = null;
+                               if ( !immediate ) {
+                                       func.apply( context, args );
+                               }
+                       };
+               if ( immediate && !timeout ) {
+                       func.apply( context, args );
+               }
+               clearTimeout( timeout );
+               timeout = setTimeout( later, wait );
+       };
+};
+
+/**
  * Reconstitute a JavaScript object corresponding to a widget created by
  * the PHP implementation.
  *

-- 
To view, visit https://gerrit.wikimedia.org/r/208328
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iefcba48819cc71436e785cf98c7b74d8c7d1fbaf
Gerrit-PatchSet: 1
Gerrit-Project: oojs/ui
Gerrit-Branch: master
Gerrit-Owner: Catrope <roan.katt...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to