{"action":"opened","issue":{"url":"https://api.github.com/repos/pouchdb/pouchdb/issues/4068","labels_url":"https://api.github.com/repos/pouchdb/pouchdb/issues/4068/labels{/name}","comments_url":"https://api.github.com/repos/pouchdb/pouchdb/issues/4068/comments","events_url":"https://api.github.com/repos/pouchdb/pouchdb/issues/4068/events","html_url":"https://github.com/pouchdb/pouchdb/issues/4068","id":96915123,"number":4068,"title":"Trigger 'change' events before resolving from `.put`","user":{"login":"gr2m","id":39992,"avatar_url":"https://avatars.githubusercontent.com/u/39992?v=3","gravatar_id":"","url":"https://api.github.com/users/gr2m","html_url":"https://github.com/gr2m","followers_url":"https://api.github.com/users/gr2m/followers","following_url":"https://api.github.com/users/gr2m/following{/other_user}","gists_url":"https://api.github.com/users/gr2m/gists{/gist_id}","starred_url":"https://api.github.com/users/gr2m/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gr2m/subscriptions","organizations_url":"https://api.github.com/users/gr2m/orgs","repos_url":"https://api.github.com/users/gr2m/repos","events_url":"https://api.github.com/users/gr2m/events{/privacy}","received_events_url":"https://api.github.com/users/gr2m/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-07-23T22:07:38Z","updated_at":"2015-07-23T22:07:38Z","closed_at":null,"body":"When I run this test code\r\n\r\n```js\r\ndb = new PouchDB('test')\r\ndb.changes({live: true, since: 'now'}).on('change', console.log.bind(console, 'change')); ''\r\ndb.put({_id: 'test'}).then(console.log.bind(console, 'put')); ''\r\n```\r\n\r\nI see the `put` log first, then the `change`. But I'd expect that the `change` event gets triggered before the Promise from the `.put` gets resolved. Any thoughts?\r\n\r\nContext is that we want to add a `.hasLocalChanges()` method to https://github.com/hoodiehq/pouchdb-hoodie-store. And with the current behavior, I get this\r\n\r\n```js\r\nstore = new Store('test')\r\nstore.add({id: 'test'}).then(function(obj) {\r\n  store.hasLocalChanges(obj) // false, should be true.\r\n})\r\n```\r\n\r\n`store.hasLocalChanges(obj)` is false above, because we listen to the changes feed and mark the object id as changed, but that code gets run after `store.add({id: 'test'})` resolves. See https://github.com/hoodiehq/pouchdb-hoodie-store/pull/21/files#r35374887"}}