mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-28 00:40:07 +02:00
boom! wrestled backbone into supporting animations
This commit is contained in:
parent
b7f6bfff5a
commit
dbd7913803
6 changed files with 86 additions and 20 deletions
|
@ -20,7 +20,7 @@ var CommandBuffer = Backbone.Model.extend({
|
||||||
|
|
||||||
this.buffer = [];
|
this.buffer = [];
|
||||||
this.timeout = null;
|
this.timeout = null;
|
||||||
this.delay = 300;
|
this.delay = TIME.betweenCommandsDelay;
|
||||||
},
|
},
|
||||||
|
|
||||||
addCommand: function(command) {
|
addCommand: function(command) {
|
||||||
|
@ -47,19 +47,22 @@ var CommandBuffer = Backbone.Model.extend({
|
||||||
setTimeout: function() {
|
setTimeout: function() {
|
||||||
this.timeout = setTimeout(_.bind(function() {
|
this.timeout = setTimeout(_.bind(function() {
|
||||||
this.sipFromBuffer();
|
this.sipFromBuffer();
|
||||||
}, this), 300);
|
}, this), this.delay);
|
||||||
},
|
},
|
||||||
|
|
||||||
popAndProcess: function() {
|
popAndProcess: function() {
|
||||||
var popped = this.buffer.pop();
|
var popped = this.buffer.pop();
|
||||||
|
var callback = _.bind(function() {
|
||||||
|
this.setTimeout();
|
||||||
|
}, this);
|
||||||
|
|
||||||
// find a command with no error
|
// find a command with no error
|
||||||
while (popped.get('error') && this.buffer.length) {
|
while (popped.get('error') && this.buffer.length) {
|
||||||
popped = buffer.pop();
|
popped = buffer.pop();
|
||||||
}
|
}
|
||||||
// process it if theres no error
|
|
||||||
if (!popped.get('error')) {
|
if (!popped.get('error')) {
|
||||||
events.trigger('processCommand', popped);
|
// pass in a callback, so when this command is "done" we will process the next.
|
||||||
|
events.trigger('processCommand', popped, callback);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -75,9 +78,7 @@ var CommandBuffer = Backbone.Model.extend({
|
||||||
}
|
}
|
||||||
|
|
||||||
this.popAndProcess();
|
this.popAndProcess();
|
||||||
if (this.buffer.length) {
|
if (!this.buffer.length) {
|
||||||
this.setTimeout();
|
|
||||||
} else {
|
|
||||||
this.clear();
|
this.clear();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -7,9 +7,10 @@ var constants = {
|
||||||
baseMass: 1,
|
baseMass: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
var time = {
|
var TIME = {
|
||||||
edgeAddInterval: 200,
|
betweenCommandsDelay: 400,
|
||||||
breathePeriod: 0.3
|
commandShow: 300,
|
||||||
|
reflowGuess: 100
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
11
src/git.js
11
src/git.js
|
@ -675,14 +675,23 @@ GitEngine.prototype.deleteBranch = function(name) {
|
||||||
this.branches.splice(toDelete, 1);
|
this.branches.splice(toDelete, 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
GitEngine.prototype.dispatch = function(command) {
|
GitEngine.prototype.dispatch = function(command, callback) {
|
||||||
// current command, options, and args are stored in the gitEngine
|
// current command, options, and args are stored in the gitEngine
|
||||||
// for easy reference during processing.
|
// for easy reference during processing.
|
||||||
this.command = command;
|
this.command = command;
|
||||||
this.commandOptions = command.get('supportedMap');
|
this.commandOptions = command.get('supportedMap');
|
||||||
this.generalArgs = command.get('generalArgs');
|
this.generalArgs = command.get('generalArgs');
|
||||||
|
|
||||||
|
command.set('status', 'processing');
|
||||||
this[command.get('method') + 'Starter']();
|
this[command.get('method') + 'Starter']();
|
||||||
|
|
||||||
|
// TODO: move into animation thing
|
||||||
|
var whenDone = _.bind(function() {
|
||||||
|
command.set('status', 'finished');
|
||||||
|
callback();
|
||||||
|
}, this);
|
||||||
|
whenDone();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GitEngine.prototype.addStarter = function() {
|
GitEngine.prototype.addStarter = function() {
|
||||||
|
|
|
@ -44,14 +44,16 @@
|
||||||
|
|
||||||
<!-- Templates -->
|
<!-- Templates -->
|
||||||
<script type="text/html" id="command-template">
|
<script type="text/html" id="command-template">
|
||||||
<p class="commandLine <%= status %>">
|
<div class="wrapper" style="display:none">
|
||||||
|
<p class="commandLine transitionBackground <%= status %>">
|
||||||
<span class="arrows">> > ></span>
|
<span class="arrows">> > ></span>
|
||||||
<%= rawStr %>
|
<%= rawStr %>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p class="commandLine <%= resultType %>">
|
<p class="commandLineResult <%= resultType %>">
|
||||||
<%= result %>
|
<%= result %>
|
||||||
</p>
|
</p>
|
||||||
|
</div>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- My files! -->
|
<!-- My files! -->
|
||||||
|
|
|
@ -16,6 +16,15 @@ html, body {
|
||||||
color: #eee;
|
color: #eee;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Transition */
|
||||||
|
.transitionBackground {
|
||||||
|
-webkit-transition: background 700ms cubic-bezier(0.260, 0.860, 0.440, 0.985);
|
||||||
|
-moz-transition: background 700ms cubic-bezier(0.260, 0.860, 0.440, 0.985);
|
||||||
|
-ms-transition: background 700ms cubic-bezier(0.260, 0.860, 0.440, 0.985);
|
||||||
|
-o-transition: background 700ms cubic-bezier(0.260, 0.860, 0.440, 0.985);
|
||||||
|
transition: background 700ms cubic-bezier(0.260, 0.860, 0.440, 0.985);
|
||||||
|
}
|
||||||
|
|
||||||
#controls {
|
#controls {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0px;
|
top: 0px;
|
||||||
|
@ -29,10 +38,21 @@ html, body {
|
||||||
width: 90%;
|
width: 90%;
|
||||||
}
|
}
|
||||||
|
|
||||||
p.commandLine {
|
p.commandLine, p.commandLineResult {
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
font-size: 18px;
|
font-size: 18px;
|
||||||
margin: 2px;
|
margin: 2px;
|
||||||
|
background-color: black;
|
||||||
|
}
|
||||||
|
|
||||||
|
p.commandLine.inqueue {
|
||||||
|
background-color: yellow;
|
||||||
|
color: black;
|
||||||
|
}
|
||||||
|
|
||||||
|
p.commandLine.finished {
|
||||||
|
background-color: #0066cc;
|
||||||
|
color: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
p.commandResult {
|
p.commandResult {
|
||||||
|
|
35
src/views.js
35
src/views.js
|
@ -103,10 +103,37 @@ var CommandView = Backbone.View.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
initialize: function() {
|
initialize: function() {
|
||||||
this.model.bind('change', this.render, this);
|
this.model.bind('change', this.wasChanged, this);
|
||||||
this.model.bind('destroy', this.remove, this);
|
this.model.bind('destroy', this.remove, this);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
wasChanged: function(model, changeEvent) {
|
||||||
|
// for changes that are just comestic, we actually only want to toggle classes
|
||||||
|
// with jquery rather than brutally delete a html of HTML
|
||||||
|
var changes = changeEvent.changes;
|
||||||
|
var changeKeys = _.keys(changes);
|
||||||
|
if (_.difference(changeKeys, ['status']) == 0) {
|
||||||
|
this.updateStatus();
|
||||||
|
} else {
|
||||||
|
this.render();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
updateStatus: function() {
|
||||||
|
var statuses = ['inqueue', 'processing', 'finished'];
|
||||||
|
var toggleMap = {};
|
||||||
|
_.each(statuses, function(status) {
|
||||||
|
toggleMap[status] = false;
|
||||||
|
});
|
||||||
|
toggleMap[this.model.get('status')] = true;
|
||||||
|
|
||||||
|
var query = this.$('p.commandLine');
|
||||||
|
|
||||||
|
_.each(toggleMap, function(value, key) {
|
||||||
|
query.toggleClass(key, value);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
var json = _.extend(
|
var json = _.extend(
|
||||||
{
|
{
|
||||||
|
@ -115,7 +142,13 @@ var CommandView = Backbone.View.extend({
|
||||||
},
|
},
|
||||||
this.model.toJSON()
|
this.model.toJSON()
|
||||||
);
|
);
|
||||||
|
|
||||||
this.$el.html(this.template(json));
|
this.$el.html(this.template(json));
|
||||||
|
|
||||||
|
// we need to show ourselves after a reflow
|
||||||
|
setTimeout(_.bind(function() {
|
||||||
|
this.$('.wrapper').slideDown(TIME.commandShow);
|
||||||
|
}, this), TIME.reflowGuess);
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue