Skip to content
Browse files

Adding support for running dep-graph in the browser

  • Loading branch information...
1 parent 4367f67 commit 178352dc5c343cf8ef1ec6e5440a734ef1cca14d @TrevorBurnham committed Sep 19, 2011
Showing with 19 additions and 5 deletions.
  1. +5 −2 docs/dep-graph.html
  2. +6 −1 lib/dep-graph.js
  3. +8 −2 src/dep-graph.coffee
View
7 docs/dep-graph.html
@@ -1,4 +1,4 @@
-<!DOCTYPE html> <html> <head> <title>dep-graph.coffee</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> dep-graph.coffee </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p><a href="http://github.com/TrevorBurnham/dep-graph">dep-graph</a></p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">module.exports = </span><span class="k">class</span> <span class="nx">DepGraph</span>
+<!DOCTYPE html> <html> <head> <title>dep-graph.coffee</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> dep-graph.coffee </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p><a href="http://github.com/TrevorBurnham/dep-graph">dep-graph</a></p> </td> <td class="code"> <div class="highlight"><pre><span class="k">class</span> <span class="nx">DepGraph</span>
<span class="nv">constructor: </span><span class="o">-&gt;</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>The internal representation of the dependency graph in the format
<code>id: [ids]</code>, indicating only <em>direct</em> dependencies.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="vi">@map = </span><span class="p">{}</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>Add a direct dependency. Returns <code>false</code> if that dependency is a duplicate.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">add: </span><span class="nf">(id, depId) -&gt;</span>
<span class="nx">@map</span><span class="p">[</span><span class="nx">id</span><span class="p">]</span> <span class="o">?=</span> <span class="p">[]</span>
@@ -16,6 +16,9 @@
<span class="nx">traversedBranch</span><span class="p">.</span><span class="nx">unshift</span> <span class="nx">depId</span>
<span class="nx">@getChain</span> <span class="nx">depId</span><span class="p">,</span> <span class="nx">traversedPaths</span><span class="p">,</span> <span class="nx">traversedBranch</span><span class="p">.</span><span class="nx">slice</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
- <span class="nx">traversedPaths</span>
+ <span class="nx">traversedPaths</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div> <p>Export the class in Node, make it global in the browser.</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">if</span> <span class="nx">module</span><span class="o">?</span><span class="p">.</span><span class="nx">exports</span><span class="o">?</span>
+ <span class="nv">module.exports = </span><span class="nx">DepGraph</span>
+<span class="k">else</span>
+ <span class="vi">@DepGraph = </span><span class="nx">DepGraph</span>
</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
View
7 lib/dep-graph.js
@@ -6,7 +6,7 @@
}
return -1;
};
- module.exports = DepGraph = (function() {
+ DepGraph = (function() {
function DepGraph() {
this.map = {};
}
@@ -49,4 +49,9 @@
};
return DepGraph;
})();
+ if ((typeof module !== "undefined" && module !== null ? module.exports : void 0) != null) {
+ module.exports = DepGraph;
+ } else {
+ this.DepGraph = DepGraph;
+ }
}).call(this);
View
10 src/dep-graph.coffee
@@ -1,6 +1,6 @@
# [dep-graph](http://github.com/TrevorBurnham/dep-graph)
-module.exports = class DepGraph
+class DepGraph
constructor: ->
# The internal representation of the dependency graph in the format
# `id: [ids]`, indicating only *direct* dependencies.
@@ -26,4 +26,10 @@ module.exports = class DepGraph
traversedBranch.unshift depId
@getChain depId, traversedPaths, traversedBranch.slice(0)
- traversedPaths
+ traversedPaths
+
+# Export the class in Node, make it global in the browser.
+if module?.exports?
+ module.exports = DepGraph
+else
+ @DepGraph = DepGraph

0 comments on commit 178352d

Please sign in to comment.
Something went wrong with that request. Please try again.