Jacob Ruiz

View Original

Improving the render method in TodoMVC

Today's exercise was to improve the render method in TodoMVC. The problem with the render method was that it did more than just render the view. It also stored data to local storage. Here's a look at the method:

See this content in the original post

We can add comments to group these lines by functionality:

See this content in the original post

So to clean up the render method, we can move the call to util.store into its own method simply named save.

See this content in the original post

Then, everywhere where we call render in the app, we can follow it with a call to save. The intention here is to make for more readable and honest code.

Here's a look at the commit that shows the difference between the old app.js file and the new one: See commit

The full code is below.

See this content in the original post