Skip to content

Latest commit

 

History

History
138 lines (81 loc) · 5.6 KB

MAKEME.md

File metadata and controls

138 lines (81 loc) · 5.6 KB

Homework Week 8

Topics discussed this week:
• Structure for a basic SPA
• XMLHttpRequests
• API calls
• Async VS Sync

Here you find the readings you have to complete before the ninth lecture.

Step 1: Feedback

Deadline Monday

Please provide feedback in an issue.

Deadline Monday

Step 2: FINISH ALL YOUR JAVASCRIPT HOMEWORK

Deadline Saturday

☝️

Step 3: Async challenge

Deadline Saturday

  1. Rewrite the code below to Async:
1.

let sum = calculateSum(2, 6);
console.log(sum);

2.

let results = $.getJSON('http://myapi.com');
showResults(results);

3.

let sum = calculateSum(2, 6);
if (sum > 8) {
    console.log('larger than 8');
}

4.

let data = $.getJSON('http://myapi.com');
data = data.map(function (x) { return x * 8; });

writeDataToFile(data);

Step 4: SPA 💦

Deadline Saturday

You are going to write a SPA (Single Page Application) that uses the Github API. Make sure that your app uses a logical pattern just like this codepen.

Just like last week:

Make a website that fetches (= to get) data asynchronously.

  1. Create a new website with external js file

  2. Add a button (e.g. 'click me') that when clicked console.logs 'you clicked me!'

  3. Create a function that fetches from The Github API. For example from [this page] (https://api.github.com/orgs/HackYourFuture/repos). For help on this check this SO post

  4. Display the data that you get from the Github API on your web page.

  5. Now link the two together: When you click the button -> get the data from the Github API and display it on your website

Cool we are back where we left of.

  1. Take a look at this:
https://api.github.com/repos/HackYourFuture/CommandLine
  1. Make a function which takes a single argument. The function should make an XHR request to https://api.github.com/repos/HackYourFuture/[SearchTerm] where the search term will be the argument. This argument will be the input the user has given you, so make sure that when the user clicks the button you call this function with the argument.

  2. Make all the repositories link their own page in Github. Use the value of the key: name to make this work (hint: Github urls always look like this https://api.github.com/repos/HackYourFuture/[repositoryName] where [repositoryName] would be replaced by the actual name of the repository, for example CommandLine). Make sure the link opens in a new tab.

  • Make sure you handle user input well. That means you need to think about empty input, and input that doesn't yield any results.

So Github has this really nice documentation :octocat: : Check these out for example https://developer.github.com/v3/repos/collaborators/ https://developer.github.com/v3/repos/commits/

  1. Extend your page with an input element. This is so the user will be able to type in text.

  2. For each repository, show (in the right column) who the contributers are. You will need to use the contributors_url for this.

!Important

  • Do not duplicate code! This is especially important for making requests since we are making multiple ones with different urls and we want to do different actions based on the call we are making. Here are some handles to get you started:
    • So write a function called makeRequest which accepts (at least) the following parameters: url and callback.
    • Make sure your callback is called when the request errors or when it sends a response (look at the documentation)
    • Your callback functions should accept two parameters so it can handle both errors: err and response. So based on your users actions (input, hovering, clicking) you want to call makeRequest with a different url and supply it with a function that handles both errors (display an error message to the user for example) and responses (render it correctly, as described below).
  • Make your functions small and reusable (modular)! That means create separate functions to handle certain steps.
  1. GO WILD

Again, check out the Github API documentation to see what kind of magic stuff you can do with it.

The assignment is to implement something extra that is not in the assignment 😱 (nice and vague right?)

So for example, we have teams in our organization. You can find out who are in there and make a call to 'https://api.github.com/users/' + userInput (where userInput is a string typed into a search field by a user). You can show the users name, avatar image (not the link to the image!) and the number of public repos they have. Or you could make an API call to 'https://api.github.com/users/user/repos' to find out the public repo's they have. Or you can show how many people starred a specific repository.

Anyway, endless fun and possibilities. Need inspiration, check out the Github API documentation. Oh and please make it look nice (hint: use the stuff you learned in HTML/CSS)!

BONUS : Code Kata Race

Step 5: Read before next lecture

Deadline Sunday morning

Go trough the reading material in the README.md to prepare for your next class

Upload your homework in your "hyf-javascript3" Github repository. Make sure to create a new folder "week2" first. Upload your homework files inside the week2 folder and write a description for this “commit”. Your hyf-javascript3/week2 should now contain all your homework files. Place the link to your repository folder in Trello.