Queue/Spec refactor

This commit is contained in:
ragaskar
2009-08-01 15:28:39 -07:00
parent b6a41c85e1
commit 9475de28b3
16 changed files with 340 additions and 174 deletions

View File

@@ -1,5 +1,9 @@
jasmine.Queue = function() {
jasmine.Queue = function(onComplete) {
this.blocks = [];
this.onComplete = function () {
onComplete();
};
this.index = 0;
};
jasmine.Queue.prototype.add = function(block) {
@@ -7,11 +11,18 @@ jasmine.Queue.prototype.add = function(block) {
this.blocks.push(block);
};
jasmine.Queue.prototype.start = function(onComplete) {
jasmine.Queue.prototype.start = function() {
if (this.blocks[0]) {
this.blocks[0].execute();
} else {
onComplete();
this.onComplete();
}
};
jasmine.Queue.prototype._next = function () {
this.index++;
if (this.index < this.blocks.length) {
this.blocks[this.index].execute();
}
};
@@ -19,11 +30,28 @@ jasmine.Queue.prototype.start = function(onComplete) {
* @private
*/
jasmine.Queue.prototype.setNextOnLastInQueue = function (block) {
if (this.blocks.length > 0) {
var previousBlock = this.blocks[this.blocks.length - 1];
previousBlock.next = function() {
var self = this;
block._next = function () {
self.onComplete();
};
if (self.blocks.length > 0) {
var previousBlock = self.blocks[self.blocks.length - 1];
previousBlock._next = function() {
block.execute();
};
}
};
jasmine.Queue.prototype.isComplete = function () {
return this.index >= (this.blocks.length - 1);
};
jasmine.Queue.prototype.getResults = function () {
var results = [];
for (var i = 0; i < this.blocks.length; i++) {
results.push(this.blocks[i].getResults());
}
return results;
};