Navigation Menu

Skip to content

Commit

Permalink
Add context.none() & group('none')
Browse files Browse the repository at this point in the history
  • Loading branch information
CrabBot committed Feb 8, 2013
1 parent 29c2651 commit a2e2acc
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
23 changes: 20 additions & 3 deletions lib/stepdown.js
Expand Up @@ -82,7 +82,7 @@ function alloc(type, hookFn) {
index += adj.amount;
}
});

if (self[index] !== NO_RESULT) {
throw new Error('Callbacks cannot be reused.');
}
Expand Down Expand Up @@ -114,6 +114,17 @@ function alloc(type, hookFn) {
index: index,
amount: arguments.length - 2
});
} else if (type === 'none') {
self.splice(index, 1);
self.spreads.forEach(function (adj) {
if (adj.index > index) {
adj.index -= 1;
}
});
self.spreads.push({
index: index,
amount: -1
});
}

self.expectedLength--;
Expand Down Expand Up @@ -276,6 +287,12 @@ function _defineProps() {
value: function bindError(ee) {
return stepdown.bindError(ee, self);
}
},
none: {
value: function none(hookFn) {
self._outOfSync();
return self.results.alloc('none', hookFn);
}
}
});
}
Expand Down Expand Up @@ -366,7 +383,7 @@ function _group(count, type) {
}

var self = this,
callback = this.results.alloc('group'),
callback = this.results.alloc( type === 'none' ? 'none' : 'group'),
groupResults = createResultSet(callback),
group;

Expand All @@ -381,7 +398,7 @@ function _group(count, type) {

process.nextTick(function () {
if (!self.sync && !groupResults.length) {
callback(null, []);
callback(null, type === 'none' ? null : []);
}
});

Expand Down
22 changes: 17 additions & 5 deletions test/stepdown.js
Expand Up @@ -219,6 +219,9 @@ describe('Stepdown', function () {
context.push('event')(hits.concat([4]));
}, function stepSix(context, hits) {
expect(hits.slice()).to.deep.equal([1, 2, 3, 4]);
context.push('none')(null, hits.concat([5]));
}, function stepSeven(context, hits) {
expect(arguments).to.have.length(1);
done();
}]);
});
Expand All @@ -233,9 +236,10 @@ describe('Stepdown', function () {
}, function stepFour(context, hits, otherArray) {
context.collapse()(null, hits[0], hits[1], otherArray[0]);
}, function stepFive(context, hits) {
context.event()(hits.concat([4]));
}, function stepSix(context, hits) {
expect(hits.slice()).to.deep.equal([1, 2, 3, 4]);
context.none()(null, hits.concat([4]));
context.event()(hits.concat([5]));
}, function stepSeven(context, hits) {
expect(hits.slice()).to.deep.equal([1, 2, 3, 5]);
done();
}]);
});
Expand All @@ -250,10 +254,11 @@ describe('Stepdown', function () {
}, function stepFour(context, hits, otherArray) {
context.push('collapse')(null, hits[0], hits[1], otherArray[0]);
}, function stepFive(context, hits) {
context.push('event')(hits.concat([4]));
context.push('none')(null, hits.concat([4]));
context.push('event')(hits.concat([5]));
}], function finished(err, hits) {
expect(err).to.not.exist;
expect(hits.slice()).to.deep.equal([1, 2, 3, 4]);
expect(hits.slice()).to.deep.equal([1, 2, 3, 5]);
expect(arguments).to.have.length(2);
done();
});
Expand Down Expand Up @@ -372,6 +377,13 @@ describe('Stepdown', function () {
callbacks[1](2);
}, function stepSix(context, hits) {
expect(hits.slice()).to.deep.equal([1, 2]);

var callbacks = context.group(2, 'none');

callbacks[0](null, 1);
callbacks[1](null, 2, 3);
}, function stepSeven(context) {
expect(arguments.length).to.equal(1);
}], done);
});

Expand Down

0 comments on commit a2e2acc

Please sign in to comment.