Skip to content
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

Pipes - Tamira - Trek #27

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open

Pipes - Tamira - Trek #27

wants to merge 20 commits into from

Conversation

tvojnar
Copy link

@tvojnar tvojnar commented Nov 27, 2017

TREK

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
What does it mean for code to be asynchronous? Having code be asynchronous means that you can do multiple things at once -- you don't have to wait for one api call to return before you make a second, you can make multiple api calls at the same time!
Describe a piece of your code that executes asynchronously. How did this affect the way you structured it? You could ask for multiple trips details without waiting for each api call to return.
What kind of errors might the API give you? How did you choose to handle them? If the trip was/was not booked. I displayed different messages to the page depending on whether or not the post request worked.
Do you have any recommendations on how we could improve this project for the next cohort? More clarity of if we should nest our calls or use attributes (Dan seems to prefer nesting, and Jamie prefers attribute tags).

@droberts-sea
Copy link

TREK

What We're Looking For

Feature Feedback
Core Requirements
Git hygiene yes
Comprehension questions yes - Regarding asynchronous code, anything that runs at some unspecified time in the future is asynchronous, including everything from AJAX success / failure callbacks to button click handlers.
Functionality
Click a button to list trips yes
Click a trip to see trip details yes
Fill out a form to reserve a spot yes
Errors are reported to the user I only see one failure callback. This API doesn't actually return errors, which makes this requirement less interesting, but it's good to be in the habit of always providing an error callback that at least logs the response, to aid in debugging.
Styling, Foundation grid layout yes
Under the Hood
Trip data is retrieved using jQuery AJAX yes
JavaScript is well-organized and easy to read could be better - see inline
HTML is semantic yes - good work
Overall

Great job overall! In my estimation there are two difficult things in JavaScript we've never had to do in Ruby/Rails:

  • Working with callback functions, especially in an asynchronous context
  • Manipulating the DOM (and structuring the DOM to make it easy to manipulate)

Based on this submission I'd say you have a good handle on both. These topics will get substantially more complex as we continue to build bigger apps with more moving parts, and having strong organization in your JavaScript code will be even more important. Keep up the focus and hard work!

// create a click event for the button to book a trip
$(`#trip${id}`).click((event) => {
// stops the tripHTML click event from running
event.stopPropagation();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a callback inside a callback inside a callback inside a callback inside a callback! To me, this is a good indicator that you should break some of these out into separate named functions, defined at the top of the file. Each jQuery event handler and AJAX success or failure callback should get its own function.

See also callback hell

let form = $(
`<div id="book">
<form action="${action}" method="post" id="book${id}">
<label for="name">Name:</label>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't close this <div>

// create click event for each trip name
tripHTML.on('click', '.details', (event) => {
let tripId = $(event.target).attr('id');
getTripDetails(tripId);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good effort at refactoring (certainly better than the original), but you're still in a triply nested callback here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants