diff options
author | Alexander Early <alexander.early@gmail.com> | 2017-04-03 01:17:11 -0700 |
---|---|---|
committer | Alexander Early <alexander.early@gmail.com> | 2017-04-03 01:21:22 -0700 |
commit | 67e76ea150f30561e9ce7624459031197c45a68a (patch) | |
tree | 8a789dd8af5efbb133a75e3e04626f493fe1662b /lib | |
parent | 2ae34926f070cdeec38f4bcd0ad173fa6a963904 (diff) | |
download | async-67e76ea150f30561e9ce7624459031197c45a68a.tar.gz |
remove rest completely
Diffstat (limited to 'lib')
-rw-r--r-- | lib/apply.js | 15 | ||||
-rw-r--r-- | lib/compose.js | 8 | ||||
-rw-r--r-- | lib/constant.js | 13 | ||||
-rw-r--r-- | lib/internal/applyEach.js | 7 | ||||
-rw-r--r-- | lib/internal/consoleFunc.js | 12 | ||||
-rw-r--r-- | lib/internal/initialParams.js | 7 | ||||
-rw-r--r-- | lib/internal/queue.js | 11 | ||||
-rw-r--r-- | lib/internal/rest.js | 8 | ||||
-rw-r--r-- | lib/internal/setImmediate.js | 7 | ||||
-rw-r--r-- | lib/memoize.js | 7 | ||||
-rw-r--r-- | lib/reduceRight.js | 5 | ||||
-rw-r--r-- | lib/seq.js | 14 |
12 files changed, 57 insertions, 57 deletions
diff --git a/lib/apply.js b/lib/apply.js index d3fc18b..b1ca55a 100644 --- a/lib/apply.js +++ b/lib/apply.js @@ -1,4 +1,4 @@ -import rest from './internal/rest'; +import slice from './internal/slice'; /** * Creates a continuation function with some arguments already applied. @@ -12,10 +12,11 @@ import rest from './internal/rest'; * @memberOf module:Utils * @method * @category Util - * @param {Function} function - The function you want to eventually apply all + * @param {Function} fn - The function you want to eventually apply all * arguments to. Invokes with (arguments...). * @param {...*} arguments... - Any number of arguments to automatically apply * when the continuation is called. + * @returns {Function} the partially-applied function * @example * * // using apply @@ -44,8 +45,10 @@ import rest from './internal/rest'; * two * three */ -export default rest(function(fn, args) { - return rest(function(callArgs) { +export default function(fn/*, args*/) { + var args = slice(arguments, 1); + return function(/*callArgs*/) { + var callArgs = slice(arguments); return fn.apply(null, args.concat(callArgs)); - }); -}); + }; +}; diff --git a/lib/compose.js b/lib/compose.js index 96632c0..d9fa760 100644 --- a/lib/compose.js +++ b/lib/compose.js @@ -1,5 +1,5 @@ import seq from './seq'; -import rest from './internal/rest'; +import slice from './internal/slice'; /** * Creates a function which is a composition of the passed asynchronous @@ -36,6 +36,6 @@ import rest from './internal/rest'; * // result now equals 15 * }); */ -export default rest(function(args) { - return seq.apply(null, args.reverse()); -}); +export default function(/*...args*/) { + return seq.apply(null, slice(arguments).reverse()); +}; diff --git a/lib/constant.js b/lib/constant.js index ae6ffd0..238ef61 100644 --- a/lib/constant.js +++ b/lib/constant.js @@ -1,5 +1,4 @@ -import rest from './internal/rest'; -import initialParams from './internal/initialParams'; +import slice from './internal/slice'; /** * Returns a function that when called, calls-back with the values provided. @@ -43,9 +42,11 @@ import initialParams from './internal/initialParams'; * //... * }, callback); */ -export default rest(function(values) { +export default function(/*...values*/) { + var values = slice(arguments); var args = [null].concat(values); - return initialParams(function (ignoredArgs, callback) { + return function (/*...ignoredArgs, callback*/) { + var callback = arguments[arguments.length - 1]; return callback.apply(this, args); - }); -}); + }; +}; diff --git a/lib/internal/applyEach.js b/lib/internal/applyEach.js index 285a6a2..c0ed402 100644 --- a/lib/internal/applyEach.js +++ b/lib/internal/applyEach.js @@ -1,9 +1,10 @@ -import rest from './rest'; +import slice from './slice'; import initialParams from './initialParams'; import wrapAsync from './wrapAsync'; export default function applyEach(eachfn) { - return rest(function(fns, args) { + return function(fns/*, ...args*/) { + var args = slice(arguments, 1); var go = initialParams(function(args, callback) { var that = this; return eachfn(fns, function (fn, cb) { @@ -16,5 +17,5 @@ export default function applyEach(eachfn) { else { return go; } - }); + }; } diff --git a/lib/internal/consoleFunc.js b/lib/internal/consoleFunc.js index 35374d7..92f7e86 100644 --- a/lib/internal/consoleFunc.js +++ b/lib/internal/consoleFunc.js @@ -1,10 +1,12 @@ import arrayEach from 'lodash/_arrayEach'; -import rest from './rest'; +import slice from './slice'; import wrapAsync from './wrapAsync'; export default function consoleFunc(name) { - return rest(function (fn, args) { - wrapAsync(fn).apply(null, args.concat(rest(function (err, args) { + return function (fn/*, ...args*/) { + var args = slice(arguments, 1); + wrapAsync(fn).apply(null, args.concat(function (err/*, ...args*/) { + var args = slice(arguments, 1); if (typeof console === 'object') { if (err) { if (console.error) { @@ -17,6 +19,6 @@ export default function consoleFunc(name) { }); } } - }))); - }); + })); + }; } diff --git a/lib/internal/initialParams.js b/lib/internal/initialParams.js index cf30386..2079703 100644 --- a/lib/internal/initialParams.js +++ b/lib/internal/initialParams.js @@ -1,8 +1,9 @@ -import rest from './rest'; +import slice from './slice'; export default function (fn) { - return rest(function (args/*..., callback*/) { + return function (/*...args, callback*/) { + var args = slice(arguments); var callback = args.pop(); fn.call(this, args, callback); - }); + }; } diff --git a/lib/internal/queue.js b/lib/internal/queue.js index 479eaf8..2eb523a 100644 --- a/lib/internal/queue.js +++ b/lib/internal/queue.js @@ -1,7 +1,6 @@ import indexOf from 'lodash/_baseIndexOf'; import isArray from 'lodash/isArray'; import noop from 'lodash/noop'; -import rest from './rest'; import onlyOnce from './onlyOnce'; import setImmediate from './setImmediate'; @@ -51,7 +50,7 @@ export default function queue(worker, concurrency, payload) { } function _next(tasks) { - return rest(function(args){ + return function(err){ numRunning -= 1; for (var i = 0, l = tasks.length; i < l; i++) { @@ -61,10 +60,10 @@ export default function queue(worker, concurrency, payload) { workersList.splice(index) } - task.callback.apply(task, args); + task.callback.apply(task, arguments); - if (args[0] != null) { - q.error(args[0], task.data); + if (err != null) { + q.error(err, task.data); } } @@ -76,7 +75,7 @@ export default function queue(worker, concurrency, payload) { q.drain(); } q.process(); - }); + }; } var isProcessing = false; diff --git a/lib/internal/rest.js b/lib/internal/rest.js deleted file mode 100644 index ee70cc6..0000000 --- a/lib/internal/rest.js +++ /dev/null @@ -1,8 +0,0 @@ -import _overRest from 'lodash/_overRest'; -import identity from 'lodash/identity'; - -// Lodash rest function without function.toString() -// remappings -export default function rest(func, start) { - return _overRest(func, start, identity); -} diff --git a/lib/internal/setImmediate.js b/lib/internal/setImmediate.js index c8824c7..95191f9 100644 --- a/lib/internal/setImmediate.js +++ b/lib/internal/setImmediate.js @@ -1,6 +1,6 @@ 'use strict'; -import rest from './rest'; +import slice from './slice'; export var hasSetImmediate = typeof setImmediate === 'function' && setImmediate; export var hasNextTick = typeof process === 'object' && typeof process.nextTick === 'function'; @@ -10,11 +10,12 @@ export function fallback(fn) { } export function wrap(defer) { - return rest(function (fn, args) { + return function (fn/*, ...args*/) { + var args = slice(arguments, 1); defer(function () { fn.apply(null, args); }); - }); + }; } var _defer; diff --git a/lib/memoize.js b/lib/memoize.js index de71c33..27c08bc 100644 --- a/lib/memoize.js +++ b/lib/memoize.js @@ -1,5 +1,5 @@ import identity from 'lodash/identity'; -import rest from './internal/rest'; +import slice from './internal/slice'; import setImmediate from './internal/setImmediate'; import initialParams from './internal/initialParams'; @@ -61,14 +61,15 @@ export default function memoize(fn, hasher) { queues[key].push(callback); } else { queues[key] = [callback]; - _fn.apply(null, args.concat(rest(function(args) { + _fn.apply(null, args.concat(function(/*args*/) { + var args = slice(arguments); memo[key] = args; var q = queues[key]; delete queues[key]; for (var i = 0, l = q.length; i < l; i++) { q[i].apply(null, args); } - }))); + })); } }); memoized.memo = memo; diff --git a/lib/reduceRight.js b/lib/reduceRight.js index ca5aa7f..1d203c9 100644 --- a/lib/reduceRight.js +++ b/lib/reduceRight.js @@ -1,6 +1,5 @@ import reduce from './reduce'; - -var slice = Array.prototype.slice; +import slice from './internal/slice'; /** * Same as [`reduce`]{@link module:Collections.reduce}, only operates on `array` in reverse order. @@ -25,6 +24,6 @@ var slice = Array.prototype.slice; * (err, result). */ export default function reduceRight (array, memo, iteratee, callback) { - var reversed = slice.call(array).reverse(); + var reversed = slice(array).reverse(); reduce(reversed, memo, iteratee, callback); } @@ -1,5 +1,4 @@ import noop from 'lodash/noop'; -import rest from './internal/rest'; import slice from 'lodash/slice'; import reduce from './reduce'; import wrapAsync from './internal/wrapAsync'; @@ -43,9 +42,10 @@ import arrayMap from 'lodash/_arrayMap'; * }); * }); */ -export default rest(function seq(functions) { - var _functions = arrayMap(functions, wrapAsync); - return rest(function(args) { +export default function seq(/*...functions*/) { + var _functions = arrayMap(arguments, wrapAsync); + return function(/*...args*/) { + var args = slice(arguments); var that = this; var cb = args[args.length - 1]; @@ -56,7 +56,7 @@ export default rest(function seq(functions) { } reduce(_functions, args, function(newargs, fn, cb) { - fn.apply(that, newargs.concat(function(err/*, nextargs...*/) { + fn.apply(that, newargs.concat(function(err/*, ...nextargs*/) { var nextargs = slice(arguments, 1); cb(err, nextargs); })); @@ -64,5 +64,5 @@ export default rest(function seq(functions) { function(err, results) { cb.apply(that, [err].concat(results)); }); - }); -}) + }; +} |