The Wayback Machine - https://web.archive.org/web/20170626172317/https://github.com/lodash/lodash/blob/master/after.js
Skip to content
Permalink
bb7c959 Mar 13, 2017
30 lines (28 sloc) 848 Bytes
/**
* The opposite of `before`his method creates a function that invokes
* `func` once it's called `n` or more times.
*
* @since 0.1.0
* @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
*
* const saves = ['profile', 'settings']
* const done = after(saves.length, () => console.log('done saving!'))
*
* forEach(saves, type => asyncSave({ 'type': type, 'complete': done }))
* // => Logs 'done saving!' after the two async saves have completed.
*/
function after(n, func) {
if (typeof func != 'function') {
throw new TypeError('Expected a function')
}
return function(...args) {
if (--n < 1) {
return func.apply(this, args)
}
}
}
export default after
You can't perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Morty Proxy This is a proxified and sanitized view of the page, visit original site.