moving around

This commit is contained in:
Peter Cottle 2013-01-02 11:14:46 -08:00
parent a180426cfb
commit 4046916432
8 changed files with 317 additions and 209 deletions

View file

@ -63,24 +63,33 @@ var CommandBuffer = Backbone.Model.extend({
popAndProcess: function() {
var popped = this.buffer.shift(0);
var callback = _.bind(function() {
this.setTimeout();
}, this);
// find a command with no error (aka unprocessed)
while (popped.get('error') && this.buffer.length) {
popped = this.buffer.pop();
}
if (!popped.get('error')) {
// pass in a callback, so when this command is "done" we will process the next.
var Main = require('../app');
Main.getEvents().trigger('processCommand', popped, callback);
this.processCommand(popped);
} else {
// no more commands to process
this.clear();
}
},
processCommand: function(command) {
var callback = _.bind(function() {
this.setTimeout();
}, this);
var eventName = command.get('eventName');
if (!eventName) {
throw new Error('I need an event to trigger when this guy is parsed and ready');
}
var Main = require('../app');
Main.getEvents().trigger(eventName, command, callback);
},
clear: function() {
clearTimeout(this.timeout);
this.timeout = null;