TypesScript Playground

In this example below you will see how to do a TypesScript Playground with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by alaneicker, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright alaneicker ©
  • HTML
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>JavaScript Promise.all</title>
  
  
  
  
  
</head>

<body>

  
  <script src='https://cdnjs.cloudflare.com/ajax/libs/axios/0.17.1/axios.min.js'></script>

  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/alaneicker/typesscript-playground-QQbgwO */
// This example demonstrates how Promise.all can be used 
// to initiate multiple simultaneous asynchronous requests 
// and return the the results as an array of responses

const url = topic => {
  return `https://newsapi.org/v1/articles?source=${topic}&sortBy=top&apiKey=2f3f282949a14b0a935c9d4df985723b`;
};

const bbcNews       = axios.get(url('bbc-news')).catch(err => console.log(err));
const buzzFeedNews  = axios.get(url('buzzfeed')).catch(err => console.log(err));
const bloombergNews = axios.get(url('bloomberg')).catch(err => console.log(err));

Promise.all([
  bbcNews,
  buzzFeedNews,
  bloombergNews
]).then(function(responses) {
  responses.forEach(res => {
    console.log(res.data.articles);
  });
}).catch(err => {
  console.log(err);
});

Comments