Val - Edges - Trek#34
Conversation
…, only works for trip id 1 - and adjust jQuery selectors
TREKWhat We're Looking For
Val, I think your code looks wonderful on this project! I see mastery over functions and closures and callbacks. Well done! I have a few comments-- Well done on this project, I think it's very successful! |
|
|
||
| const capitalize = (string) => { | ||
| return string.replace(/^\w/, c => c.toUpperCase()); | ||
| } |
| if (response.status === 204) { | ||
| displayNoContentError(response); | ||
| } else { | ||
| let callback = response.data.length ? parseTripCollection : parseIndividualTrip |
There was a problem hiding this comment.
I like this code! It shows the depth of your knowledge about this response: if there is a non-zero length of data (it's an array) then it'll be a trip collection. I'm excited that it was so readable for me!
| } else { | ||
| let callback = response.data.length ? parseTripCollection : parseIndividualTrip | ||
| parseGetResponse(response, callback) | ||
| } |
There was a problem hiding this comment.
nice detail and handling the different responses
| displayError(error); | ||
| }); | ||
| }; | ||
| return buildGetRequest; |
There was a problem hiding this comment.
I think this is super clever and a great way to work the functions and name them so they are both flexible and specific. Nicely done!
|
|
||
| const parseGetResponse = (response, callback) => { | ||
| let tripData = response.data | ||
| let element = callback === parseTripCollection ? $('#trip-list') : $('#trip-detail-list') |
|
|
||
| const parseGetResponse = (response, callback) => { | ||
| let tripData = response.data | ||
| let element = callback === parseTripCollection ? $('#trip-list') : $('#trip-detail-list') |
There was a problem hiding this comment.
Missing semicolons in the above two lines
| let tripData = response.data | ||
| let element = callback === parseTripCollection ? $('#trip-list') : $('#trip-detail-list') | ||
| element.empty(); | ||
| callback(tripData, element); |
There was a problem hiding this comment.
This logic allows you to be flexible about exactly which action is happening at this time. Niiice.
| }; | ||
|
|
||
| const parseTripCollection = (tripData, element) => { | ||
| reportStatus(`Successfully loaded ${tripData.length} trips.`) |
| } | ||
|
|
||
| const parseIndividualTrip = (tripData, element) => { | ||
| reportStatus(`Successfully loaded ${tripData.name}.`) |
| element.append(`<h3>${tripData.name}</h3>`); | ||
| const tripProperties = ['continent', 'category', 'weeks', 'cost'] | ||
| tripProperties.forEach((prop) => { | ||
| let header = capitalize(prop); |
There was a problem hiding this comment.
this can be a const. I like this line! very readable about what's going on.
| <label for="email">Email</label> | ||
| <input type="text" name="email" /> | ||
| </div> | ||
| <input type="submit" name="add-res" value="Submit"/>`) |
TREK
Congratulations! You're submitting your assignment!
Comprehension Questions
Tripin the list by it's ID field. Would it be advantageous to keep the list in order by the id field? Explain why or why not.