Created
January 25, 2017 05:17
-
-
Save appsparkler/5baa128c1b54517026920e70c322e2cb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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