From 1669dcee762fa3d78545de47f4c162234fbdf1ca Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Sat, 29 Aug 2015 15:32:25 -0400 Subject: [PATCH] (#4224) - remove CRUD events --- docs/_includes/api/changes.html | 2 +- lib/changes.js | 8 --- tests/integration/test.changes.js | 82 ------------------------------- 3 files changed, 1 insertion(+), 91 deletions(-) diff --git a/docs/_includes/api/changes.html b/docs/_includes/api/changes.html index e073f0e2a6..9bfb55bcd8 100644 --- a/docs/_includes/api/changes.html +++ b/docs/_includes/api/changes.html @@ -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 diff --git a/lib/changes.js b/lib/changes.js index 82b03b1983..b9adbfd6b6 100644 --- a/lib/changes.js +++ b/lib/changes.js @@ -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) { diff --git a/tests/integration/test.changes.js b/tests/integration/test.changes.js index a3ede14228..952a1e422f 100644 --- a/tests/integration/test.changes.js +++ b/tests/integration/test.changes.js @@ -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);