Skip to content

Instantly share code, notes, and snippets.

@KyleWong2510
Forked from khalidwilliams/promises_review.md
Last active July 1, 2020 16:35
Show Gist options
  • Save KyleWong2510/4a08ddca96a5e1d71eada06c91f3dafb to your computer and use it in GitHub Desktop.
Save KyleWong2510/4a08ddca96a5e1d71eada06c91f3dafb to your computer and use it in GitHub Desktop.

Take 10 minutes to research the following in breakout groups. When you get back, I'm gonna call on some people to answer and explain.

1. What does the fetch api do?
	Allows us to access data from an api.  GET, POST, PATCH, PUT, DELETE
	
2. What does .fetch() return?
	A Promise (JS Object that represents the eventual completion of an action)

3. What does .then() do? What is the method called on? What does it return?
	Method called on a Promise, runs when Promise is returned successfully(resolves); returns another Promise
	
4. What does .catch() do? What is the method called on? What does it return?
	Called on a Promise; runs when Promise is rejected; also returns another Promise

And tackle this diagram:

someAsyncFunction() // What does this return? 
		A promise
		
	.then( (1) ) // When does this run? What does it return? 
		Runs when the promise is resolved. Returns a response that needs to be parsed
		
	.then( (2) ) // When does this run? What does it return?
		Runs after parsing the response. Returns data we want to manipulate in our app.
		
	.catch( (3) ) // When does this run? What does it return?
		Runs if any promise is rejected. Returns what you want to do with that error.
		
// What goes in place of (1), (2), and (3)?
	callback functions; evaluate to some value(x); that value(x) becomes the resolved value(y) of the Promise that .then/.catch returns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment