{"action":"opened","issue":{"url":"https://api.github.com/repos/reduxjs/reselect/issues/364","repository_url":"https://api.github.com/repos/reduxjs/reselect","labels_url":"https://api.github.com/repos/reduxjs/reselect/issues/364/labels{/name}","comments_url":"https://api.github.com/repos/reduxjs/reselect/issues/364/comments","events_url":"https://api.github.com/repos/reduxjs/reselect/issues/364/events","html_url":"https://github.com/reduxjs/reselect/issues/364","id":350905698,"node_id":"MDU6SXNzdWUzNTA5MDU2OTg=","number":364,"title":"Sharing Selectors with Props Across Multiple Component Instances and out of the lifecycle","user":{"login":"enmanuel-duran-olx","id":40175170,"node_id":"MDQ6VXNlcjQwMTc1MTcw","avatar_url":"https://avatars0.githubusercontent.com/u/40175170?v=4","gravatar_id":"","url":"https://api.github.com/users/enmanuel-duran-olx","html_url":"https://github.com/enmanuel-duran-olx","followers_url":"https://api.github.com/users/enmanuel-duran-olx/followers","following_url":"https://api.github.com/users/enmanuel-duran-olx/following{/other_user}","gists_url":"https://api.github.com/users/enmanuel-duran-olx/gists{/gist_id}","starred_url":"https://api.github.com/users/enmanuel-duran-olx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/enmanuel-duran-olx/subscriptions","organizations_url":"https://api.github.com/users/enmanuel-duran-olx/orgs","repos_url":"https://api.github.com/users/enmanuel-duran-olx/repos","events_url":"https://api.github.com/users/enmanuel-duran-olx/events{/privacy}","received_events_url":"https://api.github.com/users/enmanuel-duran-olx/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-08-15T17:59:42Z","updated_at":"2018-08-15T17:59:42Z","closed_at":null,"author_association":"NONE","body":"When sharing selectors across multiple instances we create a private copy of the selector for each instance, it works prefectly but it got me thinking about one thing, what if we want to memoize the selector even if the user _unmounted_ the component and came back to it immediatly _without_ mutating the selected state and props? could it reuse the last memoized result still?\r\n\r\nIn the documentation we have this example:\r\n```\r\nconst makeMapStateToProps = () => {\r\n  const getVisibleTodos = makeGetVisibleTodos()\r\n  const mapStateToProps = (state, props) => {\r\n    return {\r\n      todos: getVisibleTodos(state, props)\r\n    }\r\n  }\r\n  return mapStateToProps\r\n}`\r\n```\r\n\r\n`getVisibleTodos` is defined inside the `makeMapStateToProps` which means that  the selector is memoized as long as the component is not unmounted, when it gets unmounted the memoization is cleaned up which means that if we come back it will compute again.\r\n\r\nwhat if we do something like:\r\n\r\n```\r\nconst getVisibleTodos = makeGetVisibleTodos() // We take it out of the \r\nconst makeMapStateToProps = () => {\r\n  const mapStateToProps = (state, props) => {\r\n    return {\r\n      todos: getVisibleTodos(state, props)\r\n    }\r\n  }\r\n  return mapStateToProps\r\n}`\r\n```\r\n\r\n`getVisibleTodos` is not part of the _lifecycle_ anymore, which means that if the component is unmounted it'll still be available if you access that component again without changing the part of the state and props we selected in the selector.\r\n\r\nIs this a good idea? \r\nif not? what are the drawbacks of doing this? I've tested this hypothesis and it seems to work."}}
{"actor":{"display_login":"enmanuel-duran-olx"}}