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

BREAKING, merge after 4.0.1 - (#4224) - remove CRUD events #4224

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/_includes/api/changes.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
A list of changes made to documents in the database, in the order they were made.
It returns an object with the method `cancel()`, which you call if you don't want to listen to new changes anymore.

It is an [event emitter][event emitter] and will emit a `'change'` event on each document change, a `'complete'` event when all the changes have been processed, and an `'error'` event when an error occurs. In addition to the `'change'` event, any change will also emit a `'create'`, `'update'`, or `'delete'` event.
It is an [event emitter][event emitter] and will emit a `'change'` event on each document change, a `'complete'` event when all the changes have been processed, and an `'error'` event when an error occurs.

### Options

Expand Down
8 changes: 0 additions & 8 deletions lib/changes.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,6 @@ function Changes(db, opts, callback) {
if (self.startSeq && self.startSeq <= change.seq) {
self.startSeq = false;
}
if (change.deleted) {
self.emit('delete', change);
} else if (change.changes.length === 1 &&
change.changes[0].rev.slice(0, 2) === '1-') {
self.emit('create', change);
} else {
self.emit('update', change);
}
};

var promise = new utils.Promise(function (fulfill, reject) {
Expand Down
82 changes: 0 additions & 82 deletions tests/integration/test.changes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2291,88 +2291,6 @@ adapters.forEach(function (adapter) {
});
db.post({key: 'value'});
});
function waitASec(fun, time) {
return new PouchDB.utils.Promise(function (fulfill) {
setTimeout(function () {
fulfill(fun());
}, time);
});
}
it('CRUD events are handled correclty', function (done) {
var db = new PouchDB(dbs.name);
var changes = db.changes({
live: true,
style: 'all_docs'
});
var deleted = 0;
var updated = 0;
var created = 0;
function chuckDone() {
if ((deleted + updated + created) === 6) {
changes.cancel();
}
}
changes.on('cancel', function () {
setTimeout(function () {
deleted.should.equal(1, 'correct number of deleted');
created.should.equal(2, 'create number of created');
updated.should.equal(3, 'correct number of updates');
done();
}, 100);
}).on('delete', function (change) {
deleted++;
chuckDone();
}).on('create', function (change) {
created++;
chuckDone();
}).on('update', function (change) {
updated++;
chuckDone();
}).on('error', function (err) {
done(err);
});
var rev1, rev2;
db.put({
title: 'Holding On For Life'
}, 'currentSong').then(function (resp) {
rev1 = resp.rev;
return waitASec(function () {
return db.put({
title: 'Sushi'
}, 'nextSong');
}, 100);
}).then(function (resp) {
rev2 = resp.rev;
return waitASec(function () {
return db.put({
title: 'Holding On For Life',
artist: 'Broken Bells'
}, 'currentSong', rev1);
}, 100);
}).then(function (resp) {
rev1 = resp.rev;
return waitASec(function () {
return db.put({
title: 'Sushi',
artist: 'Kyle Andrews'
}, 'nextSong', rev2);
}, 100);
}).then(function (resp) {
rev2 = resp.rev;
return waitASec(function () {
return db.remove({
_id: 'currentSong',
_rev: rev1
});
}, 100);
}).then(function (resp) {
return db.put({
title: 'Sushi',
artist: 'Kyle Andrews',
album: 'Real Blasty'
}, 'nextSong', rev2);
});
});

it('supports returnDocs=false', function (done) {
var db = new PouchDB(dbs.name);
Expand Down