BOOM and with all globals removed from tree

This commit is contained in:
Peter Cottle 2012-11-03 15:45:14 -07:00
parent b914c9887f
commit 38b0512bca
2 changed files with 47 additions and 14 deletions

View file

@ -52,8 +52,14 @@ var VisBranch = VisBase.extend({
initialize: function() { initialize: function() {
this.validateAtInit(); this.validateAtInit();
// shorthand notation
// shorthand notation for the main objects
this.gitVisuals = this.get('gitVisuals'); 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); this.get('branch').set('visBranch', this);
var id = this.get('branch').get('id'); var id = this.get('branch').get('id');
@ -71,7 +77,7 @@ var VisBranch = VisBase.extend({
}, },
getCommitPosition: function() { getCommitPosition: function() {
var commit = gitEngine.getCommitFromRef(this.get('branch')); var commit = this.gitEngine.getCommitFromRef(this.get('branch'));
var visNode = commit.get('visNode'); var visNode = commit.get('visNode');
return visNode.getScreenCoords(); return visNode.getScreenCoords();
}, },
@ -240,7 +246,7 @@ var VisBranch = VisBase.extend({
getName: function() { getName: function() {
var name = this.get('branch').get('id'); 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) ? '*' : ''; var add = (selected == name) ? '*' : '';
return name + add; return name + add;
@ -316,14 +322,14 @@ var VisBranch = VisBase.extend({
getNonTextOpacity: function() { getNonTextOpacity: function() {
if (this.get('isHead')) { if (this.get('isHead')) {
return gitEngine.getDetachedHead() ? 1 : 0; return this.gitEngine.getDetachedHead() ? 1 : 0;
} }
return this.getBranchStackIndex() == 0 ? 1 : 0.0; return this.getBranchStackIndex() == 0 ? 1 : 0.0;
}, },
getTextOpacity: function() { getTextOpacity: function() {
if (this.get('isHead')) { if (this.get('isHead')) {
return gitEngine.getDetachedHead() ? 1 : 0; return this.gitEngine.getDetachedHead() ? 1 : 0;
} }
return 1; return 1;
}, },
@ -438,8 +444,9 @@ var VisNode = VisBase.extend({
initialize: function() { initialize: function() {
this.validateAtInit(); this.validateAtInit();
// shorthand // shorthand for the main objects
this.gitVisuals = this.get('gitVisuals'); this.gitVisuals = this.get('gitVisuals');
this.gitEngine = this.get('gitEngine');
this.set('outgoingEdges', []); this.set('outgoingEdges', []);
}, },
@ -785,8 +792,10 @@ var VisEdge = VisBase.extend({
initialize: function() { initialize: function() {
this.validateAtInit(); this.validateAtInit();
// shorthand
// shorthand for the main objects
this.gitVisuals = this.get('gitVisuals'); this.gitVisuals = this.get('gitVisuals');
this.gitEngine = this.get('gitEngine');
this.get('tail').get('outgoingEdges').push(this); this.get('tail').get('outgoingEdges').push(this);
}, },

View file

@ -70,16 +70,26 @@ function GitVisuals(options) {
this.paperWidth = null; this.paperWidth = null;
this.paperHeight = null; this.paperHeight = null;
this.commitCollection.on('change', this.collectionChanged, this);
this.branchCollection.on('add', this.addBranchFromEvent, this); this.branchCollection.on('add', this.addBranchFromEvent, this);
this.branchCollection.on('remove', this.removeBranch, this); this.branchCollection.on('remove', this.removeBranch, this);
this.deferred = [];
events.on('refreshTree', _.bind( events.on('refreshTree', _.bind(
this.refreshTree, this 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() { GitVisuals.prototype.resetAll = function() {
this.visEdgeCollection.each(function(visEdge) { this.visEdgeCollection.each(function(visEdge) {
visEdge.remove(); visEdge.remove();
@ -102,6 +112,7 @@ GitVisuals.prototype.resetAll = function() {
GitVisuals.prototype.assignGitEngine = function(gitEngine) { GitVisuals.prototype.assignGitEngine = function(gitEngine) {
this.gitEngine = gitEngine; this.gitEngine = gitEngine;
this.initHeadBranch(); this.initHeadBranch();
this.deferFlush();
}; };
GitVisuals.prototype.initHeadBranch = function() { GitVisuals.prototype.initHeadBranch = function() {
@ -113,7 +124,8 @@ GitVisuals.prototype.initHeadBranch = function() {
// seed this with the HEAD pseudo-branch // seed this with the HEAD pseudo-branch
var headBranch = new VisBranch({ var headBranch = new VisBranch({
branch: this.gitEngine.HEAD, branch: this.gitEngine.HEAD,
gitVisuals: this gitVisuals: this,
gitEngine: this.gitEngine
}); });
this.visBranchCollection.add(headBranch); this.visBranchCollection.add(headBranch);
@ -429,13 +441,23 @@ GitVisuals.prototype.turnOffPaper = function() {
}; };
GitVisuals.prototype.addBranchFromEvent = function(branch, collection, index) { 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) { GitVisuals.prototype.addBranch = function(branch, paperOverride) {
// TODO
var visBranch = new VisBranch({ var visBranch = new VisBranch({
branch: branch, branch: branch,
gitVisuals: this gitVisuals: this,
gitEngine: this.gitEngine
}); });
this.visBranchCollection.add(visBranch); this.visBranchCollection.add(visBranch);
@ -510,7 +532,8 @@ GitVisuals.prototype.addNode = function(id, commit) {
var visNode = new VisNode({ var visNode = new VisNode({
id: id, id: id,
commit: commit, commit: commit,
gitVisuals: this gitVisuals: this,
gitEngine: this.gitEngine
}); });
this.visNodeMap[id] = visNode; this.visNodeMap[id] = visNode;
@ -533,7 +556,8 @@ GitVisuals.prototype.addEdge = function(idTail, idHead) {
var edge = new VisEdge({ var edge = new VisEdge({
tail: visNodeTail, tail: visNodeTail,
head: visNodeHead, head: visNodeHead,
gitVisuals: this gitVisuals: this,
gitEngine: this.gitEngine
}); });
this.visEdgeCollection.add(edge); this.visEdgeCollection.add(edge);