Skip to content

Commit

Permalink
Merge pull request #1 from myndzi/master
Browse files Browse the repository at this point in the history
Remove underscore dependency
  • Loading branch information
jriecken committed May 2, 2015
2 parents 1fdaf69 + 0e94966 commit 68d3910
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
16 changes: 8 additions & 8 deletions lib/dep_graph.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* A simple dependency graph
*/
var _ = require('underscore');

/**
* Helper for creating a Depth-First-Search on
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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;
}
};
};
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
"scripts": {
"test": "jasmine-node specs"
},
"dependencies": {
"underscore": "1.4.4"
},
"dependencies": {},
"optionalDependencies": {},
"devDependencies": {
"jasmine-node": "1.7.1"
Expand Down

0 comments on commit 68d3910

Please sign in to comment.