Sha256: 27478dd9bdbd364f019cad5568ee98af0003ed0f0cadf0f3ea1444843dc2a8bd

Contents?: true

Size: 1.26 KB

Versions: 153

Compression:

Stored size: 1.26 KB

Contents

/** Used as the `TypeError` message for "Functions" methods. */
var FUNC_ERROR_TEXT = 'Expected a function';

/* Native method references for those with the same name as other `lodash` methods. */
var nativeIsFinite = global.isFinite;

/**
 * The opposite of `_.before`; this method creates a function that invokes
 * `func` once it's called `n` or more times.
 *
 * @static
 * @memberOf _
 * @category Function
 * @param {number} n The number of calls before `func` is invoked.
 * @param {Function} func The function to restrict.
 * @returns {Function} Returns the new restricted function.
 * @example
 *
 * var saves = ['profile', 'settings'];
 *
 * var done = _.after(saves.length, function() {
 *   console.log('done saving!');
 * });
 *
 * _.forEach(saves, function(type) {
 *   asyncSave({ 'type': type, 'complete': done });
 * });
 * // => logs 'done saving!' after the two async saves have completed
 */
function after(n, func) {
  if (typeof func != 'function') {
    if (typeof n == 'function') {
      var temp = n;
      n = func;
      func = temp;
    } else {
      throw new TypeError(FUNC_ERROR_TEXT);
    }
  }
  n = nativeIsFinite(n = +n) ? n : 0;
  return function() {
    if (--n < 1) {
      return func.apply(this, arguments);
    }
  };
}

module.exports = after;

Version data entries

153 entries across 80 versions & 8 rubygems

Version Path
ilog-0.4.1 node_modules/contents/node_modules/lodash/function/after.js
ilog-0.4.1 node_modules/babel-plugin-proto-to-assign/node_modules/lodash/function/after.js
ilog-0.4.1 node_modules/babel/node_modules/lodash/function/after.js
ilog-0.4.0 node_modules/babel/node_modules/lodash/function/after.js
ilog-0.4.0 node_modules/contents/node_modules/lodash/function/after.js
ilog-0.4.0 node_modules/babel-plugin-proto-to-assign/node_modules/lodash/function/after.js
ilog-0.3.3 node_modules/babel/node_modules/lodash/function/after.js
ilog-0.3.3 node_modules/contents/node_modules/lodash/function/after.js
ilog-0.3.3 node_modules/babel-plugin-proto-to-assign/node_modules/lodash/function/after.js
trusty-festivity-extension-2.6.3 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/function/after.js
trusty-festivity-extension-2.6.3 node_modules/bower/node_modules/inquirer/node_modules/lodash/function/after.js
trusty-festivity-extension-2.6.2 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/function/after.js
trusty-festivity-extension-2.6.2 node_modules/bower/node_modules/inquirer/node_modules/lodash/function/after.js
trusty-festivity-extension-2.6.1 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/function/after.js
trusty-festivity-extension-2.6.1 node_modules/bower/node_modules/inquirer/node_modules/lodash/function/after.js
xcodebuild-helper-1.2.5 externals/ios-sim-master/node_modules/lodash/function/after.js
trusty-festivity-extension-2.6 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/function/after.js
trusty-festivity-extension-2.6 node_modules/bower/node_modules/inquirer/node_modules/lodash/function/after.js
trusty-festivity-extension-2.5.19 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/function/after.js
trusty-festivity-extension-2.5.19 node_modules/bower/node_modules/inquirer/node_modules/lodash/function/after.js