Skip to content

Commit

Permalink
Fix optional callbacks being actually optional (fixes #1223)
Browse files Browse the repository at this point in the history
  • Loading branch information
megawac committed Jul 10, 2016
1 parent f4acefd commit b77396c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/internal/filter.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions lib/mapValuesLimit.js
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions lib/reduce.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/sortBy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
3 changes: 3 additions & 0 deletions lib/transform.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit b77396c

Please sign in to comment.