diff --git a/src/tree.js b/src/tree.js index 7b4817ca..fc8bc25d 100644 --- a/src/tree.js +++ b/src/tree.js @@ -52,8 +52,14 @@ var VisBranch = VisBase.extend({ initialize: function() { this.validateAtInit(); - // shorthand notation + + // shorthand notation for the main objects this.gitVisuals = this.get('gitVisuals'); + this.gitEngine = this.get('gitEngine'); + if (!this.gitEngine) { + console.log('throw damnit'); + throw new Error('asd'); + } this.get('branch').set('visBranch', this); var id = this.get('branch').get('id'); @@ -71,7 +77,7 @@ var VisBranch = VisBase.extend({ }, getCommitPosition: function() { - var commit = gitEngine.getCommitFromRef(this.get('branch')); + var commit = this.gitEngine.getCommitFromRef(this.get('branch')); var visNode = commit.get('visNode'); return visNode.getScreenCoords(); }, @@ -240,7 +246,7 @@ var VisBranch = VisBase.extend({ getName: function() { var name = this.get('branch').get('id'); - var selected = gitEngine.HEAD.get('target').get('id'); + var selected = this.gitEngine.HEAD.get('target').get('id'); var add = (selected == name) ? '*' : ''; return name + add; @@ -316,14 +322,14 @@ var VisBranch = VisBase.extend({ getNonTextOpacity: function() { if (this.get('isHead')) { - return gitEngine.getDetachedHead() ? 1 : 0; + return this.gitEngine.getDetachedHead() ? 1 : 0; } return this.getBranchStackIndex() == 0 ? 1 : 0.0; }, getTextOpacity: function() { if (this.get('isHead')) { - return gitEngine.getDetachedHead() ? 1 : 0; + return this.gitEngine.getDetachedHead() ? 1 : 0; } return 1; }, @@ -438,8 +444,9 @@ var VisNode = VisBase.extend({ initialize: function() { this.validateAtInit(); - // shorthand + // shorthand for the main objects this.gitVisuals = this.get('gitVisuals'); + this.gitEngine = this.get('gitEngine'); this.set('outgoingEdges', []); }, @@ -785,8 +792,10 @@ var VisEdge = VisBase.extend({ initialize: function() { this.validateAtInit(); - // shorthand + + // shorthand for the main objects this.gitVisuals = this.get('gitVisuals'); + this.gitEngine = this.get('gitEngine'); this.get('tail').get('outgoingEdges').push(this); }, diff --git a/src/visuals.js b/src/visuals.js index 7d4670b5..ba005ca6 100644 --- a/src/visuals.js +++ b/src/visuals.js @@ -70,16 +70,26 @@ function GitVisuals(options) { this.paperWidth = null; this.paperHeight = null; - this.commitCollection.on('change', this.collectionChanged, this); - this.branchCollection.on('add', this.addBranchFromEvent, this); this.branchCollection.on('remove', this.removeBranch, this); + this.deferred = []; events.on('refreshTree', _.bind( this.refreshTree, this )); } +GitVisuals.prototype.defer = function(action) { + this.deferred.push(action); +}; + +GitVisuals.prototype.deferFlush = function() { + _.each(this.deferred, function(action) { + action(); + }, this); + this.deferred = []; +}; + GitVisuals.prototype.resetAll = function() { this.visEdgeCollection.each(function(visEdge) { visEdge.remove(); @@ -102,6 +112,7 @@ GitVisuals.prototype.resetAll = function() { GitVisuals.prototype.assignGitEngine = function(gitEngine) { this.gitEngine = gitEngine; this.initHeadBranch(); + this.deferFlush(); }; GitVisuals.prototype.initHeadBranch = function() { @@ -113,7 +124,8 @@ GitVisuals.prototype.initHeadBranch = function() { // seed this with the HEAD pseudo-branch var headBranch = new VisBranch({ branch: this.gitEngine.HEAD, - gitVisuals: this + gitVisuals: this, + gitEngine: this.gitEngine }); this.visBranchCollection.add(headBranch); @@ -429,13 +441,23 @@ GitVisuals.prototype.turnOffPaper = function() { }; GitVisuals.prototype.addBranchFromEvent = function(branch, collection, index) { - this.addBranch(branch); + var action = _.bind(function() { + this.addBranch(branch); + }, this); + + if (!this.gitEngine) { + this.defer(action); + } else { + action(); + } }; GitVisuals.prototype.addBranch = function(branch, paperOverride) { + // TODO var visBranch = new VisBranch({ branch: branch, - gitVisuals: this + gitVisuals: this, + gitEngine: this.gitEngine }); this.visBranchCollection.add(visBranch); @@ -510,7 +532,8 @@ GitVisuals.prototype.addNode = function(id, commit) { var visNode = new VisNode({ id: id, commit: commit, - gitVisuals: this + gitVisuals: this, + gitEngine: this.gitEngine }); this.visNodeMap[id] = visNode; @@ -533,7 +556,8 @@ GitVisuals.prototype.addEdge = function(idTail, idHead) { var edge = new VisEdge({ tail: visNodeTail, head: visNodeHead, - gitVisuals: this + gitVisuals: this, + gitEngine: this.gitEngine }); this.visEdgeCollection.add(edge);