{"action":"created","issue":{"url":"https://api.github.com/repos/erikras/react-redux-universal-hot-example/issues/141","labels_url":"https://api.github.com/repos/erikras/react-redux-universal-hot-example/issues/141/labels{/name}","comments_url":"https://api.github.com/repos/erikras/react-redux-universal-hot-example/issues/141/comments","events_url":"https://api.github.com/repos/erikras/react-redux-universal-hot-example/issues/141/events","html_url":"https://github.com/erikras/react-redux-universal-hot-example/issues/141","id":102574077,"number":141,"title":"How should I call API to get initialWidgets?","user":{"login":"LarryEitel","id":299221,"avatar_url":"https://avatars.githubusercontent.com/u/299221?v=3","gravatar_id":"","url":"https://api.github.com/users/LarryEitel","html_url":"https://github.com/LarryEitel","followers_url":"https://api.github.com/users/LarryEitel/followers","following_url":"https://api.github.com/users/LarryEitel/following{/other_user}","gists_url":"https://api.github.com/users/LarryEitel/gists{/gist_id}","starred_url":"https://api.github.com/users/LarryEitel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LarryEitel/subscriptions","organizations_url":"https://api.github.com/users/LarryEitel/orgs","repos_url":"https://api.github.com/users/LarryEitel/repos","events_url":"https://api.github.com/users/LarryEitel/events{/privacy}","received_events_url":"https://api.github.com/users/LarryEitel/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-08-22T23:23:40Z","updated_at":"2015-08-25T15:18:17Z","closed_at":null,"body":"My goal at this point is to achieve a working `Widgets` CRUD example using my API.\r\n\r\nI decided to create a live widgets API endpoint, ie, `/api/loadWidgets`. To start off, it successfully reloads the list of widgets when I hit refresh.\r\n\r\nWhere I am hung up in how/where to make an ajax call to **initially** load the list of widgets. Currently, you do so in `loadWidgets`. In an experiment elsewhere, middleware was used to accomplish this. What do you recommend?\r\n\r\nThank You :)\r\n\r\n```\r\nconst initialWidgets = [\r\n  {id: 1, color: 'Red', sprocketCount: 7, owner: 'John'},\r\n  {id: 2, color: 'Taupe', sprocketCount: 1, owner: 'George'},\r\n  {id: 3, color: 'Green', sprocketCount: 8, owner: 'Ringo'},\r\n  {id: 4, color: 'Blue', sprocketCount: 2, owner: 'Paul'}\r\n];\r\n\r\nexport function getWidgets(req) {\r\n  let widgets = req.session.widgets;\r\n  if (!widgets) {\r\n    widgets = initialWidgets;\r\n    req.session.widgets = widgets;\r\n  }\r\n  return widgets;\r\n}\r\n\r\nexport default function loadWidgets(req) {\r\n  return new Promise((resolve, reject) => {\r\n    // make async call to database\r\n    setTimeout(() => {\r\n      if (Math.floor(Math.random() * 3) === 0) {\r\n        reject('Widget load fails 33% of the time. You were unlucky.');\r\n      } else {\r\n        resolve(getWidgets(req));\r\n      }\r\n    }, 1000); // simulate async load\r\n  });\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/erikras/react-redux-universal-hot-example/issues/comments/134620100","html_url":"https://github.com/erikras/react-redux-universal-hot-example/issues/141#issuecomment-134620100","issue_url":"https://api.github.com/repos/erikras/react-redux-universal-hot-example/issues/141","id":134620100,"user":{"login":"LarryEitel","id":299221,"avatar_url":"https://avatars.githubusercontent.com/u/299221?v=3","gravatar_id":"","url":"https://api.github.com/users/LarryEitel","html_url":"https://github.com/LarryEitel","followers_url":"https://api.github.com/users/LarryEitel/followers","following_url":"https://api.github.com/users/LarryEitel/following{/other_user}","gists_url":"https://api.github.com/users/LarryEitel/gists{/gist_id}","starred_url":"https://api.github.com/users/LarryEitel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LarryEitel/subscriptions","organizations_url":"https://api.github.com/users/LarryEitel/orgs","repos_url":"https://api.github.com/users/LarryEitel/repos","events_url":"https://api.github.com/users/LarryEitel/events{/privacy}","received_events_url":"https://api.github.com/users/LarryEitel/received_events","type":"User","site_admin":false},"created_at":"2015-08-25T15:18:17Z","updated_at":"2015-08-25T15:18:17Z","body":"Forgive me. I am this and other projects to quickly acquaint myself with these tools. I am aware of the static `fetchData()` function. I have noticed other project(s) placing this in a component. What may be confusing me is where/how others are baking in `immutable`.\r\n\r\nCould you be more specific as to where/what file `fetchData()` should go? A code snippet/example would be a huge bonus. :)"}}