-
Notifications
You must be signed in to change notification settings - Fork 47
Val - Edges - Trek #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
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()); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice helper method!
| if (response.status === 204) { | ||
| displayNoContentError(response); | ||
| } else { | ||
| let callback = response.data.length ? parseTripCollection : parseIndividualTrip |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice detail and handling the different responses
| displayError(error); | ||
| }); | ||
| }; | ||
| return buildGetRequest; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice ternary!
|
|
||
| const parseGetResponse = (response, callback) => { | ||
| let tripData = response.data | ||
| let element = callback === parseTripCollection ? $('#trip-list') : $('#trip-detail-list') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
semicolon
| } | ||
|
|
||
| const parseIndividualTrip = (tripData, element) => { | ||
| reportStatus(`Successfully loaded ${tripData.name}.`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
semicolon
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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"/>`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
semicolon. Nicely done on this
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.