Git Product home page Git Product logo

phase-1-stitching-together-the-three-pillars's Introduction

Stitching Together the Three Pillars

Learning Goals

  • Identify the three essential pillars of front-end web programming
  • Cause a change to given code so that DOM updating effect is seen
  • Cause a change to given code so that server-side behavior is stubbed in
  • Cause a change to given code so that event listening has an effect

Introduction

Knowing what web programming is and how its elements work together conceptually is an essential first step, but in order to help orient our upcoming lessons, let's see it in action. In this lesson we've provided you a simple social media application called "Simple Liker." You'll see several posts which can be "liked" by clicking on the heart...well, they could be if the critical code hadn't been commented out. This lesson will guide you in uncommenting the critical code so that you restore the "like" functionality. In subsequent lessons, you'll learn the skills needed to create the pieces that you'll stitch together in this lesson.

Although this code-along is structured as a lab, you don't need to do anything to get the tests passing. In fact, if you run the one test, you should see that it's already passing. Instead, you just need to follow along with the instructions and pay attention to how the different parts of the code are working together to create the desired functionality.

Identify the Three Essential Pillars of Front-End Web Programming

We've introduced our three essential pillars of front-end web programming:

  • Manipulating the Document Object Model (DOM)
  • Recognizing JS events
  • Communicating with the server

We also described the interaction that we want to make: "favoriting" an item on social media to turn an empty heart to red. Now, let's pull it all together and see how it works by walking through some code.

Cause a Change to Given Code So That DOM Updating Effect Is Seen

Meet our app, Simple Liker! It demos the favoriting action we've talked about and alerts you to what is happening at each step of the process. When all is working as it should, the action looks like this:

working example of favoriting a post

Go ahead and open up index.html in your browser. To do this, first go to your terminal and make sure you're in the directory where this README lives. If you're on a Mac, run open index.html and if you're using Windows, run explorer.exe index.html. If that doesn't work, you can open the file directly from Chrome. Choose Open file... from the File menu, navigate to the directory where this README is located, and open the file.

If you try clicking one of the "Like" buttons on the page, your experience will look something like this:

non-working example of favoriting a post

... which is, nothing happens. That's because we haven't switched on the working code yet. We're going to go through, step by step, find the code that makes each step work, and demo it to see how it looks in the browser.

Open up your demo.js file and take a look at everything there. Find the comments that begin with "Step 1." Follow the instructions there to un-comment the code that locates the page element we want — in this case, the heart.

demonstration of un-commenting step one

Once you uncomment the line of code and refresh the page, you can use the console to verify that the articleHearts variable contains a nodeList with five elements.

Cause a Change to Given Code So That Server-Side Behavior Is Stubbed in

Next, in your demo.js file, find the comments describing Step 2, which sets up the mock server communication (our third pillar):

demonstration of un-commenting step two

Once you've uncommented out the code and refreshed the page, try clicking one of the "Like" buttons again. You'll see that it's still not working. That's because we've uncommented the code that mocks our communication with the server, but we haven't yet told JavaScript to listen for the "click" event.

Cause a Change to Given Code So That Event Listening Has an Effect

Find Step 3 in the commented code. It's time to bring in the second pillar, events:

demonstration of un-commenting step three

We've activated all the parts of our code that stitch together the three pillars of front-end web programming. Let's go back to your browser and see what Simple Liker looks like in action. You should now be able to like and unlike each post.

working example of favoriting a post

Conclusion

We're starting to see how the pieces work together now! Which means we're ready to dive into the individual pillars and learn more about how each one functions. We'll start by reviewing how to manipulate the DOM.

phase-1-stitching-together-the-three-pillars's People

Contributors

alveem avatar aspenjames avatar dependabot[bot] avatar jenmyers avatar jlboba avatar lizbur10 avatar maxwellbenton avatar micahshute avatar sgharms avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

phase-1-stitching-together-the-three-pillars's Issues

3 Pillars and Canvas update suggestions

Canvas Link

https://my.learn.co/courses/650/assignments/32962?module_item_id=83207

Concern

Very much enjoying this course. Thank you!

I know this probably will sound “pedantic”, but to quote Steve Jobs:

  “Details matter. It's worth waiting to get it right."

In both lessons: Defining Front-End Web Programming and the beginning of Stitching Together the Three Pillars -
The 3 pillars are listed in this order:

•	Recognize Events
•	Manipulate the DOM
•	Communicate with the Server

but then for some reason, the order is switched mid lesson (grrr :):

Identify the Three Essential Pillars of Front-End Web Programming
We've introduced our three essential pillars of front-end web programming:
• Manipulating the Document Object Model (DOM)
• Recognizing JS events
• Communicating with the server

It would be helpful to keep the order consistent.

•	Recognizing JS events
•	Manipulating the Document Object Model (DOM)
•	Communicating with the server

This would also require updating the lesson comments.
In demo.js, the comments say:

// STEP 1: The line of code below is what lets JavaScript find the elements that
// we want to make clickable. Without JavaScript, clicking on these heart shapes
// does nothing. Uncomment the code and refresh the demo page.

const articleHearts = document.querySelectorAll(".like-glyph");

If you keep the order of the 3 pillars consistent (Events, Manipulate, Communicate),
Then the Step 1 comment in demo.js could logically be connected to the first pillar.
We are using the ".like-glyph" element in our effort to “Recognize the Event”.
The comment would need to reflect that this is just the initial part of the first pillar.
The second part of the first pillar will be the click event, which comes later in the Step 3 comment.
So an updated Step 1 comment might look like this:

// STEP 1: The line of code below is what lets JavaScript find the elements that
// we want to make clickable. Without JavaScript, clicking on these heart shapes
// does nothing. This is the first part of Pillar 1. The other part of Pillar one will come later.
// Uncomment the code and refresh the demo page.

Then, the comment for Step 2 could logically be connected to the second pillar -
Manipulate the DOM
So this comment would need to be updated from this

  // STEP 2: Uncomment the 3 lines after the alert.
  // Here we're using Pillar 1 (DOM Manipulation) to update the screen and
  // mimicking Pillar 3 (Server Communication) to only update the screen if
  // the sending of information to the server succeeds.

to something like this:

  // STEP 2: Uncomment the 3 lines after the alert.
  // Here we’re using Pillar 2 (DOM Manipulation) to update the screen and
  // mimick Pillar 3 (Server Communication) to only update the screen if
  // the sending of information to the server succeeds.

Finally, in the Step 3 comment
change this:

// STEP 3: In order for the call to the server and the update of the screen to
// work, we need to add a click event listener to the elements we identified in
// STEP 1. That's Pillar 2, event handling. Uncomment this code:

to something like this:

// STEP 3: In order for the call to the server and the update of the screen to
// work, we need to add a click event listener to the elements we identified in
// STEP 1. That's the other part of Pillar 1, event handling. Uncomment this code:

for (const glyph of articleHearts) {
glyph.addEventListener("click", likeCallback);
}

I very much believe this would be more consistent and more logical for students.


Additional Context

Also, while I’m being a pain in the butt,
the professional look of the Canvas app would benefit much by addressing the many translation warnings in the console.

Canvas looks to be Rails based.
RAILS is referenced in the view source, and there are a lot of forum questions online about missing translation -spans issues with Rails.

In a course on web development, it would be a big win to address those “Translation for _ is missing” warnings in the console.

My Rails experience is almost non existent, so this is way over my head, but I found these recommendations below online may which may be helpful. They seem to depend on the version of Rails you’re using.

https://guides.rubyonrails.org/v4.0.0/i18n.html

https://stackoverflow.com/questions/12914019/rails-remove-missing-translation-errors

https://stackoverflow.com/questions/59731391/how-to-selectively-deactivate-rails-i18n-translation-missing-spans

Sorry to be such a nuisance, but I think it comes with the territory.
On the bright side, I'll be out of your hair in a few months :).

Thanks for your patience.

Suggested Changes

No response

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.