From 0e949662efd555c35a05f90916c2158c0cefdea6 Mon Sep 17 00:00:00 2001 From: Kris Reeves Date: Fri, 1 May 2015 12:25:52 -0400 Subject: [PATCH] Remove underscore dependency --- lib/dep_graph.js | 16 ++++++++-------- package.json | 4 +--- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/lib/dep_graph.js b/lib/dep_graph.js index 5eb521b..daabad3 100644 --- a/lib/dep_graph.js +++ b/lib/dep_graph.js @@ -1,7 +1,6 @@ /** * A simple dependency graph */ -var _ = require('underscore'); /** * Helper for creating a Depth-First-Search on @@ -51,12 +50,12 @@ DepGraph.prototype = { delete this.nodes[name]; delete this.outgoingEdges[name]; delete this.incomingEdges[name]; - _.each(this.incomingEdges, function (edges) { - var idx = edges.indexOf(name); + Object.keys(this.incomingEdges).forEach(function (key) { + var idx = this.incomingEdges[key].indexOf(name); if (idx >= 0) { edges.splice(idx, 1); } - }); + }, this); }, hasNode:function (name) { return !!this.nodes[name]; @@ -117,15 +116,16 @@ DepGraph.prototype = { var self = this; var result = []; var DFS = createDFS(this.outgoingEdges, leavesOnly, result); - _.each(_.filter(_.keys(this.nodes), function (node) { + var keys = Object.keys(this.nodes); + keys.filter(function (node) { return self.incomingEdges[node].length === 0; - }), function (n) { + }).forEach(function (n) { DFS(n); }); - if (_.size(this.nodes) > 0 && result.length === 0) { + if (keys.length > 0 && result.length === 0) { // Special case when there are no nodes with no dependants throw new Error('Dependency Cycle Found'); } return result; } -}; \ No newline at end of file +}; diff --git a/package.json b/package.json index 0dd84f7..b60f71d 100644 --- a/package.json +++ b/package.json @@ -22,9 +22,7 @@ "scripts": { "test": "jasmine-node specs" }, - "dependencies": { - "underscore": "1.4.4" - }, + "dependencies": {}, "optionalDependencies": {}, "devDependencies": { "jasmine-node": "1.7.1"