aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Spiers <git@adamspiers.org>2015-01-12 19:12:32 +0000
committerAdam Spiers <git@adamspiers.org>2015-01-12 19:12:32 +0000
commitc54e84ad6aaed332b3538bbc3712b092e8241242 (patch)
treeba38e59603ece23ccb46f938d5a0b46cdaed2f42
parentd7672603ec993786a1304919739f848fa416ba19 (diff)
downloadgit-deps-c54e84ad6aaed332b3538bbc3712b092e8241242.tar.gz
ditch externs hack
It was based on flawed thinking. If the variable being exported gets reassigned a fresh object, having it wrapped in an externs object doesn't help. And if you always have to repoint the export at the newly initialised object, having an extra externs wrapper doesn't win anything. And it loses by requiring an extra level of indirection.
-rw-r--r--html/js/git-deps-data.coffee3
-rw-r--r--html/js/git-deps-graph.coffee2
-rw-r--r--html/js/git-deps-layout.coffee20
3 files changed, 9 insertions, 16 deletions
diff --git a/html/js/git-deps-data.coffee b/html/js/git-deps-data.coffee
index e71185c..ae3816f 100644
--- a/html/js/git-deps-data.coffee
+++ b/html/js/git-deps-data.coffee
@@ -76,7 +76,8 @@ node = (sha1) ->
return nodes[i]
module.exports =
- # Variables
+ # Variables (N.B. if these variables are reinitialised at any
+ # point, the values here will become stale and require updating)
nodes: nodes
links: links
node_index: node_index
diff --git a/html/js/git-deps-graph.coffee b/html/js/git-deps-graph.coffee
index b8ea182..aba5eca 100644
--- a/html/js/git-deps-graph.coffee
+++ b/html/js/git-deps-graph.coffee
@@ -474,7 +474,7 @@ tip_html = (d) ->
# top.append("<br />Dependencies: " + sha1s.join(", "));
index = gdd.node_index[d.sha1]
debug = "<br />node index: " + index
- dagre_node = gdl.g.graph.node(d.sha1)
+ dagre_node = gdl.graph.node(d.sha1)
debug += "<br />dagre: (#{dagre_node.x}, #{dagre_node.y})"
top.append debug
diff --git a/html/js/git-deps-layout.coffee b/html/js/git-deps-layout.coffee
index 3024e4d..b3ea092 100644
--- a/html/js/git-deps-layout.coffee
+++ b/html/js/git-deps-layout.coffee
@@ -10,16 +10,9 @@ constraints = []
# within that row.
row_groups = {}
-# Expose a container for externally accessible objects. We can't
-# directly expose the objects themselves because the references
-# change each time they're constructed. However we don't need this
-# trick for the constraints arrays since we can easily empty that by
-# setting length to 0.
-externs = {}
-
dagre_layout = ->
g = new dagre.graphlib.Graph()
- externs.graph = g
+ exports.graph = g
# Set an object for the graph label
g.setGraph {}
@@ -43,7 +36,7 @@ dagre_layout = ->
dagre_row_groups = ->
g = dagre_layout()
row_groups = {}
- externs.row_groups = row_groups
+ exports.row_groups = row_groups
for sha1 in g.nodes()
x = g.node(sha1).x
y = g.node(sha1).y
@@ -105,12 +98,11 @@ build_alignment_constraint = (row_nodes) ->
return constraint
node = (sha1) ->
- externs.graph.node sha1
+ exports.graph.node sha1
-module.exports =
- # Variables
- constraints: constraints
- g: externs
+module.exports = exports =
+ # Variables have to be exported every time they're assigned,
+ # since assignment creates a new object and associated reference
# Functions
build_constraints: build_constraints