Sha256: 22851e1eb10e731a812bdf627957cabc535cc320e00e44170b692fc210c0aaad

Contents?: true

Size: 941 Bytes

Versions: 264

Compression:

Stored size: 941 Bytes

Contents

/** Used to detect hot functions by number of calls within a span of milliseconds. */
var HOT_COUNT = 800,
    HOT_SPAN = 16;

/* Built-in method references for those with the same name as other `lodash` methods. */
var nativeNow = Date.now;

/**
 * Creates a function that'll short out and invoke `identity` instead
 * of `func` when it's called `HOT_COUNT` or more times in `HOT_SPAN`
 * milliseconds.
 *
 * @private
 * @param {Function} func The function to restrict.
 * @returns {Function} Returns the new shortable function.
 */
function shortOut(func) {
  var count = 0,
      lastCalled = 0;

  return function() {
    var stamp = nativeNow(),
        remaining = HOT_SPAN - (stamp - lastCalled);

    lastCalled = stamp;
    if (remaining > 0) {
      if (++count >= HOT_COUNT) {
        return arguments[0];
      }
    } else {
      count = 0;
    }
    return func.apply(undefined, arguments);
  };
}

module.exports = shortOut;

Version data entries

264 entries across 262 versions & 29 rubygems

Version Path
trusty-cms-6.3.1 node_modules/lodash/_shortOut.js
immosquare-cleaner-0.1.51 node_modules/lodash/_shortOut.js
boring_generators-0.15.0 tmp/templates/app_template/node_modules/lodash/_shortOut.js
clapton-0.0.26 lib/clapton/javascripts/node_modules/lodash/_shortOut.js
clapton-0.0.25 lib/clapton/javascripts/node_modules/lodash/_shortOut.js
immosquare-cleaner-0.1.50 node_modules/lodash/_shortOut.js
clapton-0.0.24 lib/clapton/javascripts/node_modules/lodash/_shortOut.js
clapton-0.0.23 lib/clapton/javascripts/node_modules/lodash/_shortOut.js
clapton-0.0.22 lib/clapton/javascripts/node_modules/lodash/_shortOut.js
clapton-0.0.21 lib/clapton/javascripts/node_modules/lodash/_shortOut.js
clapton-0.0.20 lib/clapton/javascripts/node_modules/lodash/_shortOut.js
clapton-0.0.19 lib/clapton/javascripts/node_modules/lodash/_shortOut.js
clapton-0.0.18 lib/clapton/javascripts/node_modules/lodash/_shortOut.js
clapton-0.0.17 lib/clapton/javascripts/node_modules/lodash/_shortOut.js
clapton-0.0.16 lib/clapton/javascripts/node_modules/lodash/_shortOut.js
clapton-0.0.15 lib/clapton/javascripts/node_modules/lodash/_shortOut.js
immosquare-cleaner-0.1.49 node_modules/lodash/_shortOut.js
clapton-0.0.14 lib/clapton/javascripts/node_modules/lodash/_shortOut.js
immosquare-cleaner-0.1.48 node_modules/lodash/_shortOut.js
clapton-0.0.13 lib/clapton/javascripts/node_modules/lodash/_shortOut.js