angular-pouchdb
angular-pouchdb copied to clipboard
adapt pouchdb.changes() to pouchdb 3 event handler
PouchDB 3 introduced a new API for changes() which now returns an event emitter. The wrapped changes function now also makes use of angular's $q and uses the notify callback if more than one change is expected (e.g., with live: true). Furthermore, the promise is called with an object containing both the change (containing the data) and the changes object (which may be useful for cancelling the subscription).
The new version can, e.g., be used as follows:
var db = pouchdb.create('mydb');
db.changes({live: true}).then(null, null, function (res) {
// access res.change or res.changes
// e.g., cancel via res.changes.cancel()
});
:+1: I experienced an issue using changes() with a newer version of pouchdb and angular-pouchdb today.
The library is expecting onChange() to be passed as an option and appears to fail if it's not passed. It appears this method is deprecated and may be removed in pouchdb 3.0
@wspringer: is there any reason for not merging the PR?
@andrenarchy
@wspringer isn't actively maintaining the project currently so hopefully someone else can help you out here. :)
@andrenarchy - You might consider looking at https://github.com/jrhicks/ngPouch - It simplifies working with pouchdb in an Angular app by publishing replication status, managing progressive reconnections, and assisting 3 way binding.