{"action":"created","issue":{"url":"https://api.github.com/repos/yoshuawuyts/choo/issues/447","repository_url":"https://api.github.com/repos/yoshuawuyts/choo","labels_url":"https://api.github.com/repos/yoshuawuyts/choo/issues/447/labels{/name}","comments_url":"https://api.github.com/repos/yoshuawuyts/choo/issues/447/comments","events_url":"https://api.github.com/repos/yoshuawuyts/choo/issues/447/events","html_url":"https://github.com/yoshuawuyts/choo/issues/447","id":217664408,"number":447,"title":"Best pattern to fetch data based on a path","user":{"login":"qzapaia","id":1208547,"avatar_url":"https://avatars1.githubusercontent.com/u/1208547?v=3","gravatar_id":"","url":"https://api.github.com/users/qzapaia","html_url":"https://github.com/qzapaia","followers_url":"https://api.github.com/users/qzapaia/followers","following_url":"https://api.github.com/users/qzapaia/following{/other_user}","gists_url":"https://api.github.com/users/qzapaia/gists{/gist_id}","starred_url":"https://api.github.com/users/qzapaia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/qzapaia/subscriptions","organizations_url":"https://api.github.com/users/qzapaia/orgs","repos_url":"https://api.github.com/users/qzapaia/repos","events_url":"https://api.github.com/users/qzapaia/events{/privacy}","received_events_url":"https://api.github.com/users/qzapaia/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-03-28T19:17:26Z","updated_at":"2017-03-28T22:42:19Z","closed_at":null,"body":"### Expected behavior\r\n\r\n```javascript\r\nvar html = require('choo/html')\r\nvar choo = require('choo')\r\n\r\nvar app = choo()\r\napp.use(productStore)\r\napp.route('/product/:id', mainView)\r\napp.mount('body')\r\n\r\nfunction mainView (state, emit) {\r\n\r\n  return html`  <body onload=${pullData}>\r\n      <h1>product is ${state.product.name}</h1>\r\n    </body>\r\n  `\r\n  function pullData(){\r\n    emitter.emit('fetchProduct');\r\n  }\r\n}\r\n\r\nfunction productStore (state, emitter) {\r\n  emitter.on('fetchProduct', function () {\r\n    fetch('/product/'+state.params.id,function (product) {\r\n       state.product = product;\r\n       emitter.emit('render')\r\n    })\r\n  })\r\n}\r\n```\r\nI was wondering if this is a good pattern in order to fetch some data when access some URL."},"comment":{"url":"https://api.github.com/repos/yoshuawuyts/choo/issues/comments/289927668","html_url":"https://github.com/yoshuawuyts/choo/issues/447#issuecomment-289927668","issue_url":"https://api.github.com/repos/yoshuawuyts/choo/issues/447","id":289927668,"user":{"login":"fraserxu","id":1183541,"avatar_url":"https://avatars0.githubusercontent.com/u/1183541?v=3","gravatar_id":"","url":"https://api.github.com/users/fraserxu","html_url":"https://github.com/fraserxu","followers_url":"https://api.github.com/users/fraserxu/followers","following_url":"https://api.github.com/users/fraserxu/following{/other_user}","gists_url":"https://api.github.com/users/fraserxu/gists{/gist_id}","starred_url":"https://api.github.com/users/fraserxu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fraserxu/subscriptions","organizations_url":"https://api.github.com/users/fraserxu/orgs","repos_url":"https://api.github.com/users/fraserxu/repos","events_url":"https://api.github.com/users/fraserxu/events{/privacy}","received_events_url":"https://api.github.com/users/fraserxu/received_events","type":"User","site_admin":false},"created_at":"2017-03-28T22:42:19Z","updated_at":"2017-03-28T22:42:19Z","body":"@qzapaia I'm wondering this too. Though I have some issue with this approach. \r\n\r\nThe `onload` hook seems only get triggered when refreshing the page. But if it was triggered by `emit('pushState', '/page/userB')` from `/page/userA` (using same component) and the dom has already \"loaded\" before, the `onload` will not be triggered. \r\n\r\nI have tried to emit the `fetchProduct` event inside the `mainView` function, but the problem is that it will run into an infinite loop if `emit('render')` is get called in store handler and `mainView` function will be called all the time. \r\n\r\nI have worked with React for a while, and normally we could simply use `componentDidMount` and that event will be triggered when switch from page to page(or component being mount to view). Not sure if `onload` is the best solution here though.\r\n"}}
{"actor":{"display_login":"fraserxu"}}