daleharvey/pouchdb — pull request #522 by jlaxson (2013-03-02 02:04:50+00:00)
Title: Fix race condition in the changes notifier

The Pouch.utils.Changes module has an issue if more than one listener is set up for the same database. The ```var opts``` line gets reassigned in the loop, so when the callback is made to the onChange handler, it ends up calling the callback of the last listener in the array (provided the IDB or other adapter calls don't execute synchronously). I just moved the vulnerable code to a separate function, so the ```opts``` variable gets captured and doesn't change.