{"action":"created","issue":{"url":"https://api.github.com/repos/pouchdb/pouchdb/issues/3918","labels_url":"https://api.github.com/repos/pouchdb/pouchdb/issues/3918/labels{/name}","comments_url":"https://api.github.com/repos/pouchdb/pouchdb/issues/3918/comments","events_url":"https://api.github.com/repos/pouchdb/pouchdb/issues/3918/events","html_url":"https://github.com/pouchdb/pouchdb/issues/3918","id":83990100,"number":3918,"title":"Question: Detect cause of a given 'update' event","user":{"login":"jacargentina","id":517228,"avatar_url":"https://avatars.githubusercontent.com/u/517228?v=3","gravatar_id":"","url":"https://api.github.com/users/jacargentina","html_url":"https://github.com/jacargentina","followers_url":"https://api.github.com/users/jacargentina/followers","following_url":"https://api.github.com/users/jacargentina/following{/other_user}","gists_url":"https://api.github.com/users/jacargentina/gists{/gist_id}","starred_url":"https://api.github.com/users/jacargentina/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jacargentina/subscriptions","organizations_url":"https://api.github.com/users/jacargentina/orgs","repos_url":"https://api.github.com/users/jacargentina/repos","events_url":"https://api.github.com/users/jacargentina/events{/privacy}","received_events_url":"https://api.github.com/users/jacargentina/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-06-02T11:59:30Z","updated_at":"2015-06-30T07:09:34Z","closed_at":null,"body":"I've setup a changes listener for changes on my pouchdb like this:\r\n\r\n````javascript\r\n_localChanges = pouch_instance.changes({\r\n  since: 'now',\r\n  live: true,\r\n  include_docs: true\r\n})\r\n.on('create', function(create) {\r\n   // my custom code\r\n})\r\n.on('update', function(update) {\r\n   // my custom code\r\n\r\n   // How to detect when 'update' is coming from a local put(), or from a current replication processing\r\n\r\n});\r\n````\r\n\r\nMy question that from the on('update'): there is some way to differentiate between a local put() and one coming from a replication processing taking place? i mean, if there is some indication on the update event arguments, or in the pouch_instance object, etc ?\r\n"},"comment":{"url":"https://api.github.com/repos/pouchdb/pouchdb/issues/comments/117028563","html_url":"https://github.com/pouchdb/pouchdb/issues/3918#issuecomment-117028563","issue_url":"https://api.github.com/repos/pouchdb/pouchdb/issues/3918","id":117028563,"user":{"login":"daleharvey","id":37787,"avatar_url":"https://avatars.githubusercontent.com/u/37787?v=3","gravatar_id":"","url":"https://api.github.com/users/daleharvey","html_url":"https://github.com/daleharvey","followers_url":"https://api.github.com/users/daleharvey/followers","following_url":"https://api.github.com/users/daleharvey/following{/other_user}","gists_url":"https://api.github.com/users/daleharvey/gists{/gist_id}","starred_url":"https://api.github.com/users/daleharvey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daleharvey/subscriptions","organizations_url":"https://api.github.com/users/daleharvey/orgs","repos_url":"https://api.github.com/users/daleharvey/repos","events_url":"https://api.github.com/users/daleharvey/events{/privacy}","received_events_url":"https://api.github.com/users/daleharvey/received_events","type":"User","site_admin":false},"created_at":"2015-06-30T07:09:34Z","updated_at":"2015-06-30T07:09:34Z","body":"So the replication change events have a direction, you could possibly use the `.sync().on('change`, ...`\r\n\r\nAlternatively you can keep a list of documents you are about to `.put`, any documents that hit changes and arent in that list are coming in remotely\r\n\r\n```\r\nvar localChanges = {};\r\nfunction myPut(doc) { \r\n  localChanges[doc.id] = true;\r\n  return db.put(doc);\r\n}\r\n\r\ndb.change().on('change', function(change) { \r\n  if (!(change.id in localChanges)) { \r\n    ... remote change, do your thing\r\n  }\r\n  delete localChanges[change.id];\r\n});\r\n```\r\nThis I think should work for the basic case, although can likely be broken, its a fairly commonly requested feature so we should think about how to provide it to users\r\n\r\n"}}