{"action":"created","issue":{"url":"https://api.github.com/repos/gaearon/redux/issues/316","labels_url":"https://api.github.com/repos/gaearon/redux/issues/316/labels{/name}","comments_url":"https://api.github.com/repos/gaearon/redux/issues/316/comments","events_url":"https://api.github.com/repos/gaearon/redux/issues/316/events","html_url":"https://github.com/gaearon/redux/issues/316","id":96993497,"number":316,"title":"How to create nested reducers?","user":{"login":"michalkvasnicak","id":174716,"avatar_url":"https://avatars.githubusercontent.com/u/174716?v=3","gravatar_id":"","url":"https://api.github.com/users/michalkvasnicak","html_url":"https://github.com/michalkvasnicak","followers_url":"https://api.github.com/users/michalkvasnicak/followers","following_url":"https://api.github.com/users/michalkvasnicak/following{/other_user}","gists_url":"https://api.github.com/users/michalkvasnicak/gists{/gist_id}","starred_url":"https://api.github.com/users/michalkvasnicak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michalkvasnicak/subscriptions","organizations_url":"https://api.github.com/users/michalkvasnicak/orgs","repos_url":"https://api.github.com/users/michalkvasnicak/repos","events_url":"https://api.github.com/users/michalkvasnicak/events{/privacy}","received_events_url":"https://api.github.com/users/michalkvasnicak/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":28,"created_at":"2015-07-24T07:58:49Z","updated_at":"2015-07-29T20:57:38Z","closed_at":null,"body":"Maybe I am missing something but how can I define reducer that will handle actions for instance of some resource which is stored in parent.\r\n\r\nSimple example:\r\n\r\n```js\r\nconst initialState = {\r\n  articles: {\r\n    total: 1,\r\n    articles: [{ id: 1, /* some article props */}]\r\n  }\r\n}\r\n```\r\n\r\nAnd I want to increase views for the article with id 1 but I don't want to have all logic in articles store.\r\n\r\n```js\r\nstore.dispatch({ type: 'ARTICLE_VIEW', id: 1 });\r\n```\r\n\r\nI know I can handle it in articles store, but can it be done in the way I described? That I can dynamically define reducers and not only in one level but nested?\r\n"},"comment":{"url":"https://api.github.com/repos/gaearon/redux/issues/comments/126093870","html_url":"https://github.com/gaearon/redux/issues/316#issuecomment-126093870","issue_url":"https://api.github.com/repos/gaearon/redux/issues/316","id":126093870,"user":{"login":"rrag","id":10691183,"avatar_url":"https://avatars.githubusercontent.com/u/10691183?v=3","gravatar_id":"","url":"https://api.github.com/users/rrag","html_url":"https://github.com/rrag","followers_url":"https://api.github.com/users/rrag/followers","following_url":"https://api.github.com/users/rrag/following{/other_user}","gists_url":"https://api.github.com/users/rrag/gists{/gist_id}","starred_url":"https://api.github.com/users/rrag/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rrag/subscriptions","organizations_url":"https://api.github.com/users/rrag/orgs","repos_url":"https://api.github.com/users/rrag/repos","events_url":"https://api.github.com/users/rrag/events{/privacy}","received_events_url":"https://api.github.com/users/rrag/received_events","type":"User","site_admin":false},"created_at":"2015-07-29T20:57:38Z","updated_at":"2015-07-29T20:57:38Z","body":"good question. nothing wrong and you are not missing anything also :) \r\n\r\nStore shape\r\n```\r\n{\r\n  rows: [\r\n    { id:0, height:100, width, 100, query: \"bar\", results: [ ... ], showMenu: true },\r\n    { id:1, height:200, width, 200, query: \"\", results: [], showMenu: false },\r\n    { id:2, height:300, width, 300, query: \"\", results: [], showMenu: false },\r\n  ]\r\n}\r\n```\r\n\r\nTable.jsx\r\n```\r\nrender() {\r\n  return (\r\n    this.props.rows.map(each => <Row ...each {...bindActionCreators()}/>\r\n  );\r\n}\r\n```\r\n\r\nActions.js\r\n```\r\n...\r\nexport function resize(id, width, height) {\r\n...\r\nexport function search(id, query) {\r\n...\r\nexport function showDropDown(id) {\r\n...\r\nexport function clearSearch(id) {\r\n...\r\n```\r\n\r\nRow.jsx\r\n```\r\nrender() {\r\n  var actions = bindActionCreators(Actions, this.props.dispatch);\r\n  return (\r\n    <Resizeable width={this.props.width} height={this.props.height} onResize={actions.resize} id={this.props.id}>\r\n      <DropDownComponent showMenu={this.props.showMenu} onClick={actions.showDropDown}  id={this.props.id} />\r\n      <SearchBar query={this.props.query} onSearch={actions.search} id={this.props.id} />\r\n      <SearchResults results={this.props.results} onClear={actions.clearSearch} id={this.props.id} />\r\n    </Resizeable>\r\n  )\r\n}\r\n```\r\n\r\nif you see the `Row` I end up passing the id to all its children, and each of its children need to know the id, and the actions on the children of `Row` have to call the action with the id and anything else relevant.\r\n\r\nNow I have leaked the id into `SearchBar` which does not need to know the `id`\r\n\r\nI saw the TODO example and the way it handles arrays and I convinced myself this is the right way, but now I had to use `SearchBar` outside of the array and it does not make sense for it to have an `id`"}}