Skip to content

Commit

Permalink
Merge pull request #1528 from bfred-it/drop-lodash
Browse files Browse the repository at this point in the history
Drop lodash
  • Loading branch information
aearly committed Jun 3, 2018
2 parents ca85923 + ec8d30c commit 0d4f736
Show file tree
Hide file tree
Showing 44 changed files with 103 additions and 102 deletions.
5 changes: 2 additions & 3 deletions Makefile
Expand Up @@ -9,7 +9,6 @@ PACKAGE = asyncjs
REQUIRE_NAME = async
UGLIFY = uglifyjs
XYZ = support/xyz.sh --repo git@github.com:caolan/async.git
COPY_ES = sed -E "s/(import.+)lodash/\1lodash-es/g"

BUILDDIR = build
BUILD_ES = build-es
Expand Down Expand Up @@ -95,12 +94,12 @@ build-es: $(ES_MODULES)

$(BUILD_ES)/%.js: lib/%.js
mkdir -p "$(@D)"
$(COPY_ES) $< > $@
cat $< > $@

define COPY_ES_ALIAS
$A: $(shell node $(SCRIPTS)/get-alias.js $A)
mkdir -p "$$(@D)"
$(COPY_ES) $$< > $$@
cat $$< > $$@
endef
$(foreach A,$(ALIAS_ES),$(eval $(COPY_ES_ALIAS)))

Expand Down
3 changes: 1 addition & 2 deletions lib/asyncify.js
@@ -1,4 +1,3 @@
import isObject from 'lodash/isObject';
import initialParams from './internal/initialParams';
import setImmediate from './internal/setImmediate';

Expand Down Expand Up @@ -67,7 +66,7 @@ export default function asyncify(func) {
return callback(e);
}
// if result is Promise object
if (isObject(result) && typeof result.then === 'function') {
if (result && typeof result.then === 'function') {
result.then(function(value) {
invokeCallback(callback, null, value);
}, function(err) {
Expand Down
21 changes: 8 additions & 13 deletions lib/auto.js
@@ -1,10 +1,6 @@
import arrayEach from 'lodash/_arrayEach';
import forOwn from 'lodash/_baseForOwn';
import indexOf from 'lodash/_baseIndexOf';
import isArray from 'lodash/isArray';
import okeys from 'lodash/keys';
import noop from 'lodash/noop';
import noop from './internal/noop';

import forOwn from './internal/forOwn';
import slice from './internal/slice';
import once from './internal/once';
import onlyOnce from './internal/onlyOnce';
Expand Down Expand Up @@ -96,8 +92,7 @@ export default function (tasks, concurrency, callback) {
concurrency = null;
}
callback = once(callback || noop);
var keys = okeys(tasks);
var numTasks = keys.length;
var numTasks = Object.keys(tasks).length;
if (!numTasks) {
return callback(null);
}
Expand All @@ -119,7 +114,7 @@ export default function (tasks, concurrency, callback) {
var uncheckedDependencies = {};

forOwn(tasks, function (task, key) {
if (!isArray(task)) {
if (!Array.isArray(task)) {
// no dependencies
enqueueTask(key, [task]);
readyToCheck.push(key);
Expand All @@ -135,7 +130,7 @@ export default function (tasks, concurrency, callback) {
}
uncheckedDependencies[key] = remainingDependencies;

arrayEach(dependencies, function (dependencyName) {
dependencies.forEach(function (dependencyName) {
if (!tasks[dependencyName]) {
throw new Error('async.auto task `' + key +
'` has a non-existent dependency `' +
Expand Down Expand Up @@ -182,7 +177,7 @@ export default function (tasks, concurrency, callback) {

function taskComplete(taskName) {
var taskListeners = listeners[taskName] || [];
arrayEach(taskListeners, function (fn) {
taskListeners.forEach(function (fn) {
fn();
});
processQueue();
Expand Down Expand Up @@ -231,7 +226,7 @@ export default function (tasks, concurrency, callback) {
while (readyToCheck.length) {
currentTask = readyToCheck.pop();
counter++;
arrayEach(getDependents(currentTask), function (dependent) {
getDependents(currentTask).forEach(function (dependent) {
if (--uncheckedDependencies[dependent] === 0) {
readyToCheck.push(dependent);
}
Expand All @@ -248,7 +243,7 @@ export default function (tasks, concurrency, callback) {
function getDependents(taskName) {
var result = [];
forOwn(tasks, function (task, key) {
if (isArray(task) && indexOf(task, taskName, 0) >= 0) {
if (Array.isArray(task) && task.indexOf(taskName) >= 0) {
result.push(key);
}
});
Expand Down
11 changes: 4 additions & 7 deletions lib/autoInject.js
@@ -1,8 +1,5 @@
import auto from './auto';
import forOwn from 'lodash/_baseForOwn';
import arrayMap from 'lodash/_arrayMap';
import isArray from 'lodash/isArray';
import trim from 'lodash/trim';
import forOwn from './internal/forOwn';
import wrapAsync from './internal/wrapAsync';
import { isAsync } from './internal/wrapAsync';

Expand All @@ -16,7 +13,7 @@ function parseParams(func) {
func = func.match(FN_ARGS)[2].replace(' ', '');
func = func ? func.split(FN_ARG_SPLIT) : [];
func = func.map(function (arg){
return trim(arg.replace(FN_ARG, ''));
return arg.replace(FN_ARG, '').trim();
});
return func;
}
Expand Down Expand Up @@ -113,7 +110,7 @@ export default function autoInject(tasks, callback) {
(!fnIsAsync && taskFn.length === 1) ||
(fnIsAsync && taskFn.length === 0);

if (isArray(taskFn)) {
if (Array.isArray(taskFn)) {
params = taskFn.slice(0, -1);
taskFn = taskFn[taskFn.length - 1];

Expand All @@ -134,7 +131,7 @@ export default function autoInject(tasks, callback) {
}

function newTask(results, taskCb) {
var newArgs = arrayMap(params, function (name) {
var newArgs = params.map(function (name) {
return results[name];
});
newArgs.push(taskCb);
Expand Down
2 changes: 1 addition & 1 deletion lib/concatLimit.js
@@ -1,4 +1,4 @@
import noop from 'lodash/noop';
import noop from './internal/noop';
import wrapAsync from './internal/wrapAsync';
import slice from './internal/slice';
import mapLimit from './mapLimit';
Expand Down
3 changes: 1 addition & 2 deletions lib/detect.js
@@ -1,5 +1,4 @@
import identity from 'lodash/identity';

import identity from './internal/identity';
import createTester from './internal/createTester';
import doParallel from './internal/doParallel';
import findGetResult from './internal/findGetResult';
Expand Down
3 changes: 1 addition & 2 deletions lib/detectLimit.js
@@ -1,5 +1,4 @@
import identity from 'lodash/identity';

import identity from './internal/identity';
import createTester from './internal/createTester';
import doParallelLimit from './internal/doParallelLimit';
import findGetResult from './internal/findGetResult';
Expand Down
2 changes: 1 addition & 1 deletion lib/doDuring.js
@@ -1,4 +1,4 @@
import noop from 'lodash/noop';
import noop from './internal/noop';
import slice from './internal/slice';
import onlyOnce from './internal/onlyOnce';
import wrapAsync from './internal/wrapAsync';
Expand Down
2 changes: 1 addition & 1 deletion lib/doWhilst.js
@@ -1,4 +1,4 @@
import noop from 'lodash/noop';
import noop from './internal/noop';
import slice from './internal/slice';

import onlyOnce from './internal/onlyOnce';
Expand Down
2 changes: 1 addition & 1 deletion lib/during.js
@@ -1,4 +1,4 @@
import noop from 'lodash/noop';
import noop from './internal/noop';
import onlyOnce from './internal/onlyOnce';
import wrapAsync from './internal/wrapAsync';

Expand Down
5 changes: 2 additions & 3 deletions lib/eachOf.js
@@ -1,9 +1,8 @@
import isArrayLike from 'lodash/isArrayLike';

import isArrayLike from './internal/isArrayLike';
import breakLoop from './internal/breakLoop';
import eachOfLimit from './eachOfLimit';
import doLimit from './internal/doLimit';
import noop from 'lodash/noop';
import noop from './internal/noop';
import once from './internal/once';
import onlyOnce from './internal/onlyOnce';
import wrapAsync from './internal/wrapAsync';
Expand Down
3 changes: 1 addition & 2 deletions lib/forever.js
@@ -1,5 +1,4 @@
import noop from 'lodash/noop';

import noop from './internal/noop';
import onlyOnce from './internal/onlyOnce';
import ensureAsync from './ensureAsync';
import wrapAsync from './internal/wrapAsync';
Expand Down
2 changes: 1 addition & 1 deletion lib/groupByLimit.js
@@ -1,4 +1,4 @@
import noop from 'lodash/noop';
import noop from './internal/noop';
import mapLimit from './mapLimit';
import wrapAsync from './internal/wrapAsync';
/**
Expand Down
3 changes: 1 addition & 2 deletions lib/internal/consoleFunc.js
@@ -1,4 +1,3 @@
import arrayEach from 'lodash/_arrayEach';
import slice from './slice';
import wrapAsync from './wrapAsync';

Expand All @@ -13,7 +12,7 @@ export default function consoleFunc(name) {
console.error(err);
}
} else if (console[name]) {
arrayEach(args, function (x) {
args.forEach(function (x) {
console[name](x);
});
}
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/createTester.js
@@ -1,4 +1,4 @@
import noop from 'lodash/noop';
import noop from './noop';
import breakLoop from './breakLoop';

export default function _createTester(check, getResult) {
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/eachOfLimit.js
@@ -1,4 +1,4 @@
import noop from 'lodash/noop';
import noop from './noop';
import once from './once';

import iterator from './iterator';
Expand Down
11 changes: 5 additions & 6 deletions lib/internal/filter.js
@@ -1,7 +1,6 @@
import arrayMap from 'lodash/_arrayMap';
import isArrayLike from 'lodash/isArrayLike';
import property from 'lodash/_baseProperty';
import noop from 'lodash/noop';
import isArrayLike from './isArrayLike';
import property from './property';
import noop from './noop';

import wrapAsync from './wrapAsync';

Expand Down Expand Up @@ -39,9 +38,9 @@ function filterGeneric(eachfn, coll, iteratee, callback) {
if (err) {
callback(err);
} else {
callback(null, arrayMap(results.sort(function (a, b) {
callback(null, results.sort(function (a, b) {
return a.index - b.index;
}), property('value')));
}).map(property('value')));
}
});
}
Expand Down
8 changes: 8 additions & 0 deletions lib/internal/forOwn.js
@@ -0,0 +1,8 @@
export default function forOwn(object, callback) {
if (!object) {
return;
}
Object.keys(object).forEach(function (key) {
callback(object[key], key);
});
}
3 changes: 3 additions & 0 deletions lib/internal/identity.js
@@ -0,0 +1,3 @@
export default function identity(value) {
return value;
}
6 changes: 6 additions & 0 deletions lib/internal/isArrayLike.js
@@ -0,0 +1,6 @@
export default function isArrayLike(value) {
return value &&
typeof value.length === 'number' &&
value.length >= 0 &&
value.length % 1 === 0;
}
5 changes: 2 additions & 3 deletions lib/internal/iterator.js
@@ -1,6 +1,5 @@
import isArrayLike from 'lodash/isArrayLike';
import isArrayLike from './isArrayLike';
import getIterator from './getIterator';
import keys from 'lodash/keys';

function createArrayIterator(coll) {
var i = -1;
Expand All @@ -22,7 +21,7 @@ function createES2015Iterator(iterator) {
}

function createObjectIterator(obj) {
var okeys = keys(obj);
var okeys = obj ? Object.keys(obj) : [];
var i = -1;
var len = okeys.length;
return function next() {
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/map.js
@@ -1,4 +1,4 @@
import noop from 'lodash/noop';
import noop from './noop';
import wrapAsync from './wrapAsync';

export default function _asyncMap(eachfn, arr, iteratee, callback) {
Expand Down
1 change: 1 addition & 0 deletions lib/internal/noop.js
@@ -0,0 +1 @@
export default function noop() {}
4 changes: 2 additions & 2 deletions lib/internal/parallel.js
@@ -1,5 +1,5 @@
import noop from 'lodash/noop';
import isArrayLike from 'lodash/isArrayLike';
import isArrayLike from './isArrayLike';
import noop from './noop';
import slice from './slice';
import wrapAsync from './wrapAsync';

Expand Down
5 changes: 5 additions & 0 deletions lib/internal/property.js
@@ -0,0 +1,5 @@
export default function property(property) {
return function (object) {
return object[property];
}
}
9 changes: 3 additions & 6 deletions lib/internal/queue.js
@@ -1,7 +1,4 @@
import indexOf from 'lodash/_baseIndexOf';
import isArray from 'lodash/isArray';
import noop from 'lodash/noop';

import noop from './noop';
import onlyOnce from './onlyOnce';
import setImmediate from './setImmediate';
import DLL from './DoublyLinkedList';
Expand All @@ -25,7 +22,7 @@ export default function queue(worker, concurrency, payload) {
throw new Error('task callback must be a function');
}
q.started = true;
if (!isArray(data)) {
if (!Array.isArray(data)) {
data = [data];
}
if (data.length === 0 && q.idle()) {
Expand Down Expand Up @@ -64,7 +61,7 @@ export default function queue(worker, concurrency, payload) {
for (var i = 0, l = tasks.length; i < l; i++) {
var task = tasks[i];

var index = indexOf(workersList, task, 0);
var index = workersList.indexOf(task);
if (index === 0) {
workersList.shift();
} else if (index > 0) {
Expand Down
7 changes: 7 additions & 0 deletions lib/internal/range.js
@@ -0,0 +1,7 @@
export default function range(size) {
var result = Array(size);
while (size--) {
result[size] = size;
}
return result;
}
2 changes: 1 addition & 1 deletion lib/mapValuesLimit.js
@@ -1,6 +1,6 @@
import eachOfLimit from './eachOfLimit';

import noop from 'lodash/noop';
import noop from './internal/noop';
import once from './internal/once';
import wrapAsync from './internal/wrapAsync';

Expand Down
3 changes: 1 addition & 2 deletions lib/memoize.js
@@ -1,6 +1,5 @@
import identity from 'lodash/identity';
import identity from './internal/identity';
import slice from './internal/slice';

import setImmediate from './internal/setImmediate';
import initialParams from './internal/initialParams';
import wrapAsync from './internal/wrapAsync';
Expand Down
5 changes: 2 additions & 3 deletions lib/priorityQueue.js
@@ -1,5 +1,4 @@
import isArray from 'lodash/isArray';
import noop from 'lodash/noop';
import noop from './internal/noop';

import setImmediate from './setImmediate';

Expand Down Expand Up @@ -39,7 +38,7 @@ export default function(worker, concurrency) {
throw new Error('task callback must be a function');
}
q.started = true;
if (!isArray(data)) {
if (!Array.isArray(data)) {
data = [data];
}
if (data.length === 0) {
Expand Down
5 changes: 2 additions & 3 deletions lib/race.js
@@ -1,5 +1,4 @@
import isArray from 'lodash/isArray';
import noop from 'lodash/noop';
import noop from './internal/noop';
import once from './internal/once';
import wrapAsync from './internal/wrapAsync';

Expand Down Expand Up @@ -41,7 +40,7 @@ import wrapAsync from './internal/wrapAsync';
*/
export default function race(tasks, callback) {
callback = once(callback || noop);
if (!isArray(tasks)) return callback(new TypeError('First argument to race must be an array of functions'));
if (!Array.isArray(tasks)) return callback(new TypeError('First argument to race must be an array of functions'));
if (!tasks.length) return callback();
for (var i = 0, l = tasks.length; i < l; i++) {
wrapAsync(tasks[i])(callback);
Expand Down

0 comments on commit 0d4f736

Please sign in to comment.