Skip to content

Commit

Permalink
(#4224) - remove CRUD events
Browse files Browse the repository at this point in the history
  • Loading branch information
nolanlawson authored and daleharvey committed Sep 3, 2015
1 parent ef75880 commit 83a4a0b
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 91 deletions.
2 changes: 1 addition & 1 deletion docs/_includes/api/changes.html
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
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
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

0 comments on commit 83a4a0b

Please sign in to comment.