pouchdb-adapter-idb: fix "possible EventEmitter memory leak detected"

Problem
-------

With the idb adapter (default in Chrome), calling `.changes()` or
`.replicate()` with `{live: true}` multiple times results in this error,
even when the handler is nicely terminated with `.cancel()`.

    (node) warning: possible EventEmitter memory leak detected. 11
    listeners added. Use emitter.setMaxListeners() to increase limit.

Related to #4176, #4141, #4093, #3848, #2667, #2311, #2205, and maybe
others.

How to reproduce the bug?
-------------------------

Run this plunkr: http://plnkr.co/edit/JKCbQ6vwlYClAp6ZSAf4?p=preview

Alternatively, you can create + cancel a `.changes()` feed a few times:

    changesHandler = db.changes({live: true});
    changesHandler.cancel();
    repeat

About this fix
--------------

The bug comes from the `_change()` API call from the idb adapter [1]
returning `undefined` instead of the `{cancel: function() {...}}` object
it should return [2]. Because of that, the cleanup function in the core
module doesn't call the adapter's `cancel()` function [3], letting a
listener into the wild.

This commit fixes that and adds a test to check for the presence of the
error log line.

[1]: https://github.com/pouchdb/pouchdb/blob/49e4945/packages/node_modules/pouchdb-adapter-idb/src/index.js#L420-L422
[2]: https://github.com/pouchdb/pouchdb/blob/49e4945/packages/node_modules/pouchdb-adapter-idb/src/changes.js#L29-L33
[3]: https://github.com/pouchdb/pouchdb/blob/49e4945/packages/node_modules/pouchdb-core/src/changes.js#L201-L209
2 files changed
tree: 4a7cdfa727650fce03aef7ae3ef09376213c4edb
  1. bin/
  2. docs/
  3. packages/
  4. scripts/
  5. tests/
  6. .eslintignore
  7. .eslintrc.json
  8. .gitattributes
  9. .gitignore
  10. .travis.yml
  11. CODE_OF_CONDUCT.md
  12. CONTRIBUTING.md
  13. ISSUE_TEMPLATE.md
  14. LICENSE
  15. package.json
  16. README.md
  17. TESTING.md
README.md

PouchDB – The Database that Syncs!

Build Status Coverage Status Greenkeeper badge npm version

PouchDB is an open-source JavaScript database inspired by Apache CouchDB that is designed to run well within the browser.

PouchDB was created to help web developers build applications that work as well offline as they do online.

Using PouchDB

To get started using PouchDB, check out the web site and API documentation.

Getting Help

The PouchDB community is active on Freenode IRC, Slack,in the Google Groups mailing list, and on StackOverflow. Or you can tweet @pouchdb!

If you think you've found a bug in PouchDB, please write a reproducible test case and file a Github issue. We recommend bl.ocks.org for code snippets, because some iframe-based services like JSFiddle and JSBin do not support IndexedDB in all browsers. You can start with this template.

Prerelease builds

If you like to live on the bleeding edge, you can build PouchDB from source using these steps:

git clone https://github.com/pouchdb/pouchdb.git
cd pouchdb
npm install

After running these steps, the browser build can be found in packages/node_modules/pouchdb/dist/pouchdb.js.

Changelog

PouchDB follows semantic versioning. To see a changelog with all PouchDB releases, check out the Github releases page.

For a concise list of breaking changes, there's the wiki list of breaking changes.

Keep in mind that PouchDB is auto-migrating, so a database created in 1.0.0 will still work if you open it in 4.0.0+. Any release containing a migration is clearly marked in the release notes.

Contributing

We‘re always looking for new contributors! If you’d like to try your hand at writing code, writing documentation, designing the website, writing a blog post, or answering questions on StackOverflow, then we'd love to have your input.

If you have a pull request that you‘d like to submit, please read the contributing guide for info on style, commit message format, and other (slightly!) nitpicky things like that. PouchDB is heavily tested, so you’ll also want to check out the testing guide.