Sha256: b133cc76b5a966f19f6ff734b86a7a0c11fc731327b7af3e9e116120d6db621a

Contents?: true

Size: 964 Bytes

Versions: 39

Compression:

Stored size: 964 Bytes

Contents

//= require thredded/core/thredded

/**
 * 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 `wait` milliseconds. If `immediate` is passed, trigger the
 * function on the leading edge, instead of the trailing.
 * Based on https://john-dugan.com/javascript-debounce/.
 *
 * @param {Function} func
 * @param {Number} wait in milliseconds
 * @param {Boolean} immediate
 * @returns {Function}
 */
window.Thredded.debounce = function(func, wait, immediate) {
  let timeoutId = null;
  return function() {
    const context = this, args = arguments;
    const later = function() {
      timeoutId = null;
      if (!immediate) {
        func.apply(context, args);
      }
    };
    const callNow = immediate && !timeoutId;
    clearTimeout(timeoutId);
    timeoutId = setTimeout(later, wait || 200);
    if (callNow) {
      func.apply(context, args);
    }
  };
};

Version data entries

39 entries across 39 versions & 2 rubygems

Version Path
thredded-1.1.0 app/assets/javascripts/thredded/core/debounce.es6
thredded-1.0.1 app/assets/javascripts/thredded/core/debounce.es6
thredded-1.0.0 app/assets/javascripts/thredded/core/debounce.es6
thredded-0.16.16 app/assets/javascripts/thredded/core/debounce.es6
thredded-0.16.15 app/assets/javascripts/thredded/core/debounce.es6
thredded-0.16.14 app/assets/javascripts/thredded/core/debounce.es6
thredded-0.16.13 app/assets/javascripts/thredded/core/debounce.es6
thredded-0.16.12 app/assets/javascripts/thredded/core/debounce.es6
thredded-0.16.11 app/assets/javascripts/thredded/core/debounce.es6
thredded-0.16.10 app/assets/javascripts/thredded/core/debounce.es6
thredded-0.16.9 app/assets/javascripts/thredded/core/debounce.es6
thredded-0.16.8 app/assets/javascripts/thredded/core/debounce.es6
thredded-0.16.7 app/assets/javascripts/thredded/core/debounce.es6
thredded-0.16.6 app/assets/javascripts/thredded/core/debounce.es6
thredded-0.16.5 app/assets/javascripts/thredded/core/debounce.es6
thredded-0.16.4 app/assets/javascripts/thredded/core/debounce.es6
thredded-0.16.3 app/assets/javascripts/thredded/core/debounce.es6
thredded-0.16.1 app/assets/javascripts/thredded/core/debounce.es6
thredded-0.16.0 app/assets/javascripts/thredded/core/debounce.es6
thredded-0.15.5 app/assets/javascripts/thredded/core/debounce.es6