Sha256: fc2980293cc00ebee226d60b8592bc585d2abc814a58b849a678cdaf4858935a

Contents?: true

Size: 896 Bytes

Versions: 98

Compression:

Stored size: 896 Bytes

Contents

//
//  Debounce (from underscore.js)
//
exports.debounce = function(func, wait, immediate) {
  var timeout, args, context, timestamp, result;

  // get time helper
  var getTime = (Date.now || function() {
    return new Date().getTime();
  });

  // debounce
  return function() {
    context = this;
    args = arguments;
    timestamp = getTime();
    var later = function() {
      var last = getTime() - timestamp;
      if (last < wait) {
        timeout = setTimeout(later, wait - last);
      } else {
        timeout = null;
        if (!immediate) {
          result = func.apply(context, args);
          context = args = null;
        }
      }
    };
    var callNow = immediate && !timeout;
    if (!timeout) {
      timeout = setTimeout(later, wait);
    }
    if (callNow) {
      result = func.apply(context, args);
      context = args = null;
    }

    return result;
  };
};

Version data entries

98 entries across 98 versions & 1 rubygems

Version Path
lalala-4.1.0.dev.425 app/assets/javascripts/lalala/modules/helpers.module.js
lalala-4.1.0.dev.420 app/assets/javascripts/lalala/modules/helpers.module.js
lalala-4.1.0.dev.419 app/assets/javascripts/lalala/modules/helpers.module.js
lalala-4.1.0.dev.418 app/assets/javascripts/lalala/modules/helpers.module.js
lalala-4.1.0.dev.417 app/assets/javascripts/lalala/modules/helpers.module.js
lalala-4.0.0.dev.416 app/assets/javascripts/lalala/modules/helpers.module.js
lalala-4.1.0.dev.415 app/assets/javascripts/lalala/modules/helpers.module.js
lalala-4.1.0.dev.414 app/assets/javascripts/lalala/modules/helpers.module.js
lalala-4.1.0.dev.413 app/assets/javascripts/lalala/modules/helpers.module.js
lalala-4.1.0.dev.412 app/assets/javascripts/lalala/modules/helpers.module.js
lalala-4.1.0.dev.411 app/assets/javascripts/lalala/modules/helpers.module.js
lalala-4.1.0.dev.410 app/assets/javascripts/lalala/modules/helpers.module.js
lalala-4.1.0.dev.409 app/assets/javascripts/lalala/modules/helpers.module.js
lalala-4.0.0.dev.407 app/assets/javascripts/lalala/modules/helpers.module.js
lalala-4.1.0.dev.408 app/assets/javascripts/lalala/modules/helpers.module.js
lalala-4.1.0.dev.398 app/assets/javascripts/lalala/modules/helpers.module.js
lalala-4.1.0.dev.397 app/assets/javascripts/lalala/modules/helpers.module.js
lalala-4.0.0.dev.396 app/assets/javascripts/lalala/modules/helpers.module.js
lalala-4.0.0.dev.395 app/assets/javascripts/lalala/modules/helpers.module.js
lalala-4.1.0.dev.394 app/assets/javascripts/lalala/modules/helpers.module.js