{"action":"created","issue":{"url":"https://api.github.com/repos/facebook/react-native/issues/1896","labels_url":"https://api.github.com/repos/facebook/react-native/issues/1896/labels{/name}","comments_url":"https://api.github.com/repos/facebook/react-native/issues/1896/comments","events_url":"https://api.github.com/repos/facebook/react-native/issues/1896/events","html_url":"https://github.com/facebook/react-native/issues/1896","id":93541574,"number":1896,"title":"[Code Style] automatic listener setup for componentWillMount & componentWillUnmount","user":{"login":"kostiakoval","id":1086260,"avatar_url":"https://avatars.githubusercontent.com/u/1086260?v=3","gravatar_id":"","url":"https://api.github.com/users/kostiakoval","html_url":"https://github.com/kostiakoval","followers_url":"https://api.github.com/users/kostiakoval/followers","following_url":"https://api.github.com/users/kostiakoval/following{/other_user}","gists_url":"https://api.github.com/users/kostiakoval/gists{/gist_id}","starred_url":"https://api.github.com/users/kostiakoval/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kostiakoval/subscriptions","organizations_url":"https://api.github.com/users/kostiakoval/orgs","repos_url":"https://api.github.com/users/kostiakoval/repos","events_url":"https://api.github.com/users/kostiakoval/events{/privacy}","received_events_url":"https://api.github.com/users/kostiakoval/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-07-07T14:15:54Z","updated_at":"2015-07-07T17:31:56Z","closed_at":null,"body":"If I want to handle some events, I need to register and unregister manually now\r\n```js\r\n componentWillMount() {\r\n    SomeComponent.addEventListener('event', this._event);\r\n  }\r\n  componentWillUnmount() {\r\n     SomeComponent.removeEventListener('event', this._event);\r\n  }\r\n  _event() {\r\n     ...\r\n  }\r\n```\r\n\r\nVery often we forgot to unregister from events listening (a notification on iOS) and it could lead to dangerous result.\r\nThe component could automatically unregister from events when its become inactive (gets unmounted) \r\nSwift implementation - https://gist.github.com/jverkoey/dfa473635a810ab436d3\r\n\r\nSome ideas for implementation, not perfect :)\r\n\r\n```js\r\ncomponentLifeBindings() {\r\n   return [ {SomeComponent, 'event', this._event},\r\n            {View, 'move', this._hadleMovement}]\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/facebook/react-native/issues/comments/119276907","html_url":"https://github.com/facebook/react-native/issues/1896#issuecomment-119276907","issue_url":"https://api.github.com/repos/facebook/react-native/issues/1896","id":119276907,"user":{"login":"christopherdro","id":3741055,"avatar_url":"https://avatars.githubusercontent.com/u/3741055?v=3","gravatar_id":"","url":"https://api.github.com/users/christopherdro","html_url":"https://github.com/christopherdro","followers_url":"https://api.github.com/users/christopherdro/followers","following_url":"https://api.github.com/users/christopherdro/following{/other_user}","gists_url":"https://api.github.com/users/christopherdro/gists{/gist_id}","starred_url":"https://api.github.com/users/christopherdro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/christopherdro/subscriptions","organizations_url":"https://api.github.com/users/christopherdro/orgs","repos_url":"https://api.github.com/users/christopherdro/repos","events_url":"https://api.github.com/users/christopherdro/events{/privacy}","received_events_url":"https://api.github.com/users/christopherdro/received_events","type":"User","site_admin":false},"created_at":"2015-07-07T17:31:56Z","updated_at":"2015-07-07T17:31:56Z","body":"This might help. https://github.com/facebook/react-native/blob/8b93b99d4a769f86fffc95d65434f2f6a3fd827d/Libraries/Components/Subscribable.js\r\n\r\nAccording to @ericvicenti from a previous issue...\r\n\r\n\"Subscribable.Mixin is something we use internally to make sure nobody forgets to unsubscribe to an emitter from a component on unmount. The mixin will automatically remove subscriptions added with this.addListenerOn\""}}