Skip to content

Instantly share code, notes, and snippets.

@appsparkler
Created January 25, 2017 05:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save appsparkler/5baa128c1b54517026920e70c322e2cb to your computer and use it in GitHub Desktop.
Save appsparkler/5baa128c1b54517026920e70c322e2cb to your computer and use it in GitHub Desktop.
export default (store) => {
const
{ state, dispatch }
= store,
itemId
= state.route.params.itemId,
fetchItems
= ids => dispatch('FETCH_ITEMS', { ids }),
getFetchedItem
= () => Promise.resolve(state.items[itemId]),
getAllCommentsForItem
= item => item.kids ? fetchItems(item.kids).then(() => fetchKidComments(item.kids)) : null,
fetchKidComments
= kids => Promise.all(kids.map(kid => getAllCommentsForItem(state.items[kid])));
return fetchItems([ itemId ])
.then(getFetchedItem)
.then(getAllCommentsForItem)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment