JSFiddle - React, Tailwind, and code Playground
by Travis Harris
JavaScript
function getByID(child_type, id) {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve({
'child_type': child_type,
'id': id,
'some': 'very',
'important': 'information',
'children': [
id + '_first',
id + '_second'
]
});
}, 1);
})
}
getByID("Movie", "first")
.then(movie => {
Promise.all(movie.children, actor_id => {
return getByID('actor', actor_id)
.then(actor => {
Promise.map(actor.children, role_id => {
return getByID('role', role_id)
})
.then(roles => {
actor.roles = roles;
})
})
})
.then(actors => {
movie.actors = actors;
})
}).then(movie=>{
console.log(movie);
});