Coder Social home page Coder Social logo

countries's Introduction

JS Templating with AJAX Lab

The goal of this lab is to implement a basic Handlebars.js template. What you have to start with is a basic rails app that shows a list of countries, their abbreviation, and a flag. Rendering all this data on page load can be inefficient, especially if there is a large dataset. What can help server load is to acquire the data after page load using AJAX, template it using Handlebars.js, and append it to the DOM.

  1. First, bundle install the app
  2. Migrate and seed the database
  3. Run the app and navigate to localhost:3000 to see what it looks like
  4. Investigate the current templates and become familiar what exists
    • You should find an index.html.erb file that uses a partial to display the list of countries
    • You should find a home.js file that includes the JS event bindings and the empty named functions.
    • There should also be a number of support files (JS libraries, CSS files, and an image that serves as the flag sprite)
  5. Implement the erb partial as a Handlebars template
  6. Give the "Populate" and "All Data" buttons functionality
  7. Implement the concept of "infinite scrolling" to dynamically load the page as a user scrolls down
  8. As you scroll, the countries should populate until you reach the end. Use your browsers inspector to investigate the network activity if you keep trying to scroll. Refactor as necessary to mitigate any potential issues you identify.

###Bonus Exercise 1 (Handlebars conditional) One of the parameters in the model is north_america. This is a boolean value, defaulting to false. When a country is in North America, add the class "na" to the <p> tag to show that country in bold red text. This should be implemented in the country's Handlebars template.

###Bonus Exercise 2 (Event binding + AJAX) Create a click event on each country element to find the date when that country was created in the database and display in an alert box with the country's id.

###Bonus Exercise 3 (DRY AJAX) You should have already implemented the functionality for populating the entire page as well as piecemeal on window scroll (potentially the click event bonus exercise too). Writing AJAX calls can be cumbersome especially as you add more options/parameters. In order to remain DRY, rewrite some of your code to use one AJAX call. This function should handle the necessary parameters, setup the AJAX call, and and implement a callback/handler function to call when the AJAX call finishes. Perhaps also we need to be sure the callback is a valid function.

countries's People

Contributors

rrails avatar

Watchers

James Cloos avatar  avatar

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.