{"action":"created","issue":{"url":"https://api.github.com/repos/realm/realm-js/issues/1597","repository_url":"https://api.github.com/repos/realm/realm-js","labels_url":"https://api.github.com/repos/realm/realm-js/issues/1597/labels{/name}","comments_url":"https://api.github.com/repos/realm/realm-js/issues/1597/comments","events_url":"https://api.github.com/repos/realm/realm-js/issues/1597/events","html_url":"https://github.com/realm/realm-js/issues/1597","id":286336997,"node_id":"MDU6SXNzdWUyODYzMzY5OTc=","number":1597,"title":"Cannot remove a result object's listener","user":{"login":"andrew-wagner89","id":18293215,"node_id":"MDQ6VXNlcjE4MjkzMjE1","avatar_url":"https://avatars3.githubusercontent.com/u/18293215?v=4","gravatar_id":"","url":"https://api.github.com/users/andrew-wagner89","html_url":"https://github.com/andrew-wagner89","followers_url":"https://api.github.com/users/andrew-wagner89/followers","following_url":"https://api.github.com/users/andrew-wagner89/following{/other_user}","gists_url":"https://api.github.com/users/andrew-wagner89/gists{/gist_id}","starred_url":"https://api.github.com/users/andrew-wagner89/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrew-wagner89/subscriptions","organizations_url":"https://api.github.com/users/andrew-wagner89/orgs","repos_url":"https://api.github.com/users/andrew-wagner89/repos","events_url":"https://api.github.com/users/andrew-wagner89/events{/privacy}","received_events_url":"https://api.github.com/users/andrew-wagner89/received_events","type":"User","site_admin":false},"labels":[{"id":320460156,"node_id":"MDU6TGFiZWwzMjA0NjAxNTY=","url":"https://api.github.com/repos/realm/realm-js/labels/T:Doc","name":"T:Doc","color":"bfe5bf","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":26,"created_at":"2018-01-05T16:27:55Z","updated_at":"2018-06-15T09:15:59Z","closed_at":"2018-05-17T08:42:35Z","author_association":"NONE","body":"<!---\r\n\r\nQuestions: If you have questions about HOW TO use Realm, please ask on\r\nStackOverflow: http://stackoverflow.com/questions/ask?tags=realm\r\nWe monitor the `realm` tag.\r\n\r\nFeature Request: Just fill in the first two sections below.\r\n\r\nBugs: To help you as fast as possible with an issue please describe your issue\r\nand the steps you have taken to reproduce it in as much detail as possible.\r\n\r\n-->\r\n\r\n## Goals\r\n\r\nI'm trying to update my UI based on changes in to a realm object, so I added a listener to the result that calls forceUpdate. This solution, while a little ugly since I don't like calling forceUpdate, works correctly, but when I call removeListener on the collection, it still continues to call forceUpdate. I've also tried calling removeListener on the entire realm, as well as removeAllListeners on the result object and entire realm with no success.\r\n\r\nI know its a no - op so it doesn't affect the app, but it is a nuisance and I feel like there should be a correct way I haven't found\r\n\r\n## Expected Results\r\n\r\nthe listener is removed correctly\r\n\r\n## Actual Results\r\n\r\nit isn't and a No-Op react native warning is thrown due to react trying to update an unmounted component\r\n\r\n## Steps to Reproduce\r\n\r\nadd a listener to a result object in componentWillMount and remove it in componentWillUnmount\r\n\r\n## Code Sample\r\n\r\nIn the file where i define my realm instance I have the following: \r\n```JSX\r\nconst listeners = [];\r\n\r\nexport function addFineGrainListener(objectName, filter, callback) {\r\n  const collection = realm.objects(objectName).filtered(filter);\r\n  collection.addListener(callback);\r\n  listeners.push({ objectName, filter, collection, callback });\r\n}\r\n\r\nexport function removeFineGrainListener(objectName, filter) {\r\n  const listenerObject = listeners.find(\r\n    listener => listener.objectName === objectName && listener.filter === filter,\r\n  );\r\n\r\n  listenerObject.collection.removeListener(listenerObject.callback);\r\n}\r\n```\r\n\r\nand my component has the following:\r\n\r\n```JSX\r\n  componentWillMount() {\r\n    addFineGrainListener(\r\n      'JournalEntry',\r\n      \\`id ==[c] \"${this.props.screenProps.noteId}\"\\`,\r\n      this.updateUIDueToRealmChange,\r\n    );\r\n  }\r\n  componentWillUnmount() {\r\n    removeFineGrainListener(\r\n      'JournalEntry',\r\n      \\`id ==[c] \"${this.props.screenProps.noteId}\"\\`,\r\n    );\r\n  }\r\n\r\n  updateUIDueToRealmChange = () => {\r\n    this.forceUpdate();\r\n  };\r\n```\r\n\r\n## Version of Realm and Tooling\r\n\r\n- Realm JS SDK Version: 2.1.1\r\n- Node or React Native: RN 51.0\r\n- Client OS & Version: IOS 11.2\r\n- Which debugger for React Native: Default Chrome Debugger\r\n\r\n  "},"comment":{"url":"https://api.github.com/repos/realm/realm-js/issues/comments/397563329","html_url":"https://github.com/realm/realm-js/issues/1597#issuecomment-397563329","issue_url":"https://api.github.com/repos/realm/realm-js/issues/1597","id":397563329,"node_id":"MDEyOklzc3VlQ29tbWVudDM5NzU2MzMyOQ==","user":{"login":"jfr3000","id":9396227,"node_id":"MDQ6VXNlcjkzOTYyMjc=","avatar_url":"https://avatars3.githubusercontent.com/u/9396227?v=4","gravatar_id":"","url":"https://api.github.com/users/jfr3000","html_url":"https://github.com/jfr3000","followers_url":"https://api.github.com/users/jfr3000/followers","following_url":"https://api.github.com/users/jfr3000/following{/other_user}","gists_url":"https://api.github.com/users/jfr3000/gists{/gist_id}","starred_url":"https://api.github.com/users/jfr3000/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jfr3000/subscriptions","organizations_url":"https://api.github.com/users/jfr3000/orgs","repos_url":"https://api.github.com/users/jfr3000/repos","events_url":"https://api.github.com/users/jfr3000/events{/privacy}","received_events_url":"https://api.github.com/users/jfr3000/received_events","type":"User","site_admin":false},"created_at":"2018-06-15T09:15:59Z","updated_at":"2018-06-15T09:15:59Z","author_association":"NONE","body":"I guess I had realized that the two exist, but sometimes wasn't sure that the API docs were up to date and also didn't realize that the realm docs actually aren't complete. Not sure if a link a the end of each section `For full reference check the API docs on this` would be overkill?\r\nIn any case, I think\r\n```\r\n// OR Unregister this listener\r\ncollectionListenerRetainer.removeAllListeners();\r\n``` \r\nis not super accurate, because it doesn't just unregister this listener but all of them. It led me to believe that the only listener removal method for collections is `removeAllListeners`. Just my 2 cents, thanks for clarifying this!"}}
{"actor":{"display_login":"jfr3000"}}