Consider this piece of code:
WordPress.getMediaById(res.data.featured_media)
.then(function (res) {
post.featuredMedia = res.data.source_url;
WordPress.getUserById(post.authorId)
.then(function (res) {
post.authorName = res.data.name;
$scope.post = {
title: post.title,
introAsHtml: post.introAsHtml,
authorName: post.authorName,
contentAsHtml: post.contentAsHtml,
featured_media: post.featuredMedia
};
});
});
Is there any way to make it more efficient in terms of nesting? In the future I will want to add more promised functions into it and I am not sure if it's the right way, otherwise, how does it really differ from callbacks...
Regards.