summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGraeme Yeates <yeatesgraeme@gmail.com>2016-07-09 20:13:49 -0400
committerGraeme Yeates <yeatesgraeme@gmail.com>2016-07-09 20:15:35 -0400
commitb77396c5e96ce6e2a88b4bd2fa685e956a1c86ba (patch)
treed521b0b84eff65708b801a706368e025142a2bd2
parentf4acefdbbe7ea4e7271a4c97da4f3e28b3404987 (diff)
downloadasync-b77396c5e96ce6e2a88b4bd2fa685e956a1c86ba.tar.gz
Fix optional callbacks being actually optional (fixes #1223)
-rw-r--r--lib/internal/filter.js3
-rw-r--r--lib/mapValuesLimit.js4
-rw-r--r--lib/reduce.js3
-rw-r--r--lib/sortBy.js2
-rw-r--r--lib/transform.js3
5 files changed, 14 insertions, 1 deletions
diff --git a/lib/internal/filter.js b/lib/internal/filter.js
index aa5580c..35527e2 100644
--- a/lib/internal/filter.js
+++ b/lib/internal/filter.js
@@ -1,7 +1,10 @@
import arrayMap from 'lodash/_arrayMap';
import property from 'lodash/_baseProperty';
+import noop from 'lodash/noop';
+import once from './once';
export default function _filter(eachfn, arr, iteratee, callback) {
+ callback = once(callback || noop);
var results = [];
eachfn(arr, function (x, index, callback) {
iteratee(x, function (err, v) {
diff --git a/lib/mapValuesLimit.js b/lib/mapValuesLimit.js
index bced034..f6e72ff 100644
--- a/lib/mapValuesLimit.js
+++ b/lib/mapValuesLimit.js
@@ -1,5 +1,8 @@
import eachOfLimit from './eachOfLimit';
+import noop from 'lodash/noop';
+import once from './internal/once';
+
/**
* The same as [`mapValues`]{@link module:Collections.mapValues} but runs a maximum of `limit` async operations at a
* time.
@@ -21,6 +24,7 @@ import eachOfLimit from './eachOfLimit';
* transformed values from the `obj`. Invoked with (err, result).
*/
export default function mapValuesLimit(obj, limit, iteratee, callback) {
+ callback = once(callback || noop);
var newObj = {};
eachOfLimit(obj, limit, function(val, key, next) {
iteratee(val, key, function (err, result) {
diff --git a/lib/reduce.js b/lib/reduce.js
index 8145db7..4718631 100644
--- a/lib/reduce.js
+++ b/lib/reduce.js
@@ -1,4 +1,6 @@
import eachOfSeries from './eachOfSeries';
+import noop from 'lodash/noop';
+import once from './internal/once';
/**
* Reduces `coll` into a single value using an async `iteratee` to return each
@@ -41,6 +43,7 @@ import eachOfSeries from './eachOfSeries';
* });
*/
export default function reduce(coll, memo, iteratee, callback) {
+ callback = once(callback || noop);
eachOfSeries(coll, function(x, i, callback) {
iteratee(memo, x, function(err, v) {
memo = v;
diff --git a/lib/sortBy.js b/lib/sortBy.js
index ab6c420..9b8ffe6 100644
--- a/lib/sortBy.js
+++ b/lib/sortBy.js
@@ -17,7 +17,7 @@ import map from './map';
* The iteratee is passed a `callback(err, sortValue)` which must be called once
* it has completed with an error (which can be `null`) and a value to use as
* the sort criteria. Invoked with (item, callback).
- * @param {Function} [callback] - A callback which is called after all the
+ * @param {Function} callback - A callback which is called after all the
* `iteratee` functions have finished, or an error occurs. Results is the items
* from the original `coll` sorted by the values returned by the `iteratee`
* calls. Invoked with (err, results).
diff --git a/lib/transform.js b/lib/transform.js
index 6098522..175ad85 100644
--- a/lib/transform.js
+++ b/lib/transform.js
@@ -1,6 +1,8 @@
import isArray from 'lodash/isArray';
+import noop from 'lodash/noop';
import eachOf from './eachOf';
+import once from './internal/once';
/**
* A relative of `reduce`. Takes an Object or Array, and iterates over each
@@ -53,6 +55,7 @@ export default function transform (coll, accumulator, iteratee, callback) {
iteratee = accumulator;
accumulator = isArray(coll) ? [] : {};
}
+ callback = once(callback || noop);
eachOf(coll, function(v, k, cb) {
iteratee(accumulator, v, k, cb);