Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "events.next() is placed in the wrong scope" #117

Merged
merged 1 commit into from
Nov 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions lib/eventstore.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,16 @@ _.extend(Eventstore.prototype, {
getEvents: function (query, skip, limit, callback) {
var self = this;

function nextFn(callback) {
if (limit < 0) {
var resEvts = [];
resEvts.next = nextFn;
return process.nextTick(function () { callback(null, resEvts) });
}
skip += limit;
_getEvents(query, skip, limit, callback);
}

function _getEvents(query, skip, limit, callback) {
if (typeof query === 'function') {
callback = query;
Expand Down Expand Up @@ -151,16 +161,6 @@ _.extend(Eventstore.prototype, {
query = { aggregateId: query };
}

function nextFn(callback) {
if (limit < 0) {
var resEvts = [];
resEvts.next = nextFn;
return process.nextTick(function () { callback(null, resEvts) });
}
skip += limit;
_getEvents(query, skip, limit, callback);
}

self.store.getEvents(query, skip, limit, function (err, evts) {
if (err) return callback(err);
evts.next = nextFn;
Expand Down
39 changes: 0 additions & 39 deletions test/eventstoreTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1170,45 +1170,6 @@ describe('eventstore', function () {

});

describe('requesting all existing events, without query argument and using next function', function () {

describe('and committing some new events', function () {

it('it should work as expected', function (done) {

es.getEvents(0, 3, function (err, evts) {
expect(err).not.to.be.ok();

expect(evts.length).to.eql(3);

expect(evts.next).to.be.a('function');

evts.next(function (err, nextEvts) {
expect(err).not.to.be.ok();

expect(nextEvts.length).to.eql(3);

expect(nextEvts.next).to.be.a('function');

nextEvts.next(function (err, nextNextEvts) {
expect(err).not.to.be.ok();

expect(nextNextEvts.length).to.eql(2);

expect(nextNextEvts.next).to.be.a('function');

done();
});
});

});

});

});

});

describe('requesting existing events since a date and using next function', function () {

describe('and committing some new events', function () {
Expand Down