DEV Community

Richard Dewey Hammers
Richard Dewey Hammers

Posted on • Updated on

JavaScript Frontend

Moving into more of the frontend side of things using JS as a frontend language besides using rails erb I can see how I'm able to make a more friendly user experience. Even though I can add a button with rails erb and have it load a new page, with JS I can make it Fetch JSON from a rails api and give me back that info to use without having to have the user wait for the page to load. With that same power I can also Post, Edit and Delete through Fetch and being able to update the DOM without a refresh. This makes the user experience friendlier and they don't have to sit there waiting for the page to refresh.

The hardest part of working on this webpage was trying to figure out how I wanted to structure my app. I first started by making everything as a class then calling each method on the main file. But that got really messy and those classes served no function besides calling class methods. So I got rid of all the classes and only made two classes Task and Item which served a purpose to store each Object that was fetched from the Rails API. Next I built out generator functions that would return back some raw html to render a Task or a Item to the DOM to clean up the code in the main file.
In the end the code looks a lot cleaner now and a lot more readable .

I can't wait till I get to learn React next which will take a lot of the pain of writing out all the code myself to interact with the DOM and focus more on the meat of the app.

Top comments (0)