cloudflare/vinext
Publicmirrored from https://github.com/cloudflare/vinextAvailable
examples/hackernews/lib/get-comments.js
18lines · modecode
| 1 | import fetchData from './fetch-data' |
| 2 | |
| 3 | // hydrate comments based on an array of item ids |
| 4 | export default function fetch(ids) { |
| 5 | return Promise.all( |
| 6 | ids.map(async (id) => { |
| 7 | const val = await fetchData(`item/${id}`) |
| 8 | return { |
| 9 | id: val.id, |
| 10 | user: val.by, |
| 11 | text: val.text, |
| 12 | date: new Date(val.time * 1000).getTime() || 0, |
| 13 | comments: await fetch(val.kids || []), |
| 14 | commentsCount: val.descendants || 0, |
| 15 | } |
| 16 | }) |
| 17 | ) |
| 18 | } |
| 19 | |