Jesse Aldridge
Jesse Aldridge

Reputation: 8149

Best way to separate data from DOM

I have this time tracking / task managment tool I'm working on called Task Ranger. Basically you make a tree of tasks and sub-tasks, click on whichever task you're currently working on, and your time for that task is tracked.

I want to add a feature where the user can look at their times for a specific date range (ie. "What did I spend my time on last week?") I'm thinking I want to have a tab that I can click to jump from the "Main" view to the "History" view.

The problem is that right now I'm persisting my data by simply storing everything in the DOM and dumping the entire html structure into localStorage. In order to get the history view to work I'm going to need to separate the data from the html, right? I guess an MVC framework is the typical way of doing that, right? I was looking at Backbone, but I'm feeling like it might be a little overkill for this. I'm thinking maybe I should roll my own simple little thing. What do you think?

I'm using Javascript + Jquery for all of this right now.

Upvotes: 1

Views: 347

Answers (1)

Raynos
Raynos

Reputation: 169383

Backbone is about as lightweight as you can get MVC. If I were to write my own micro MVC framework it would convert to backbone within a week.

I would highly recommend Backbone over writing your own because it's well structured and loosely coupled. You can only use the features of backbone that you want. Since your already including jQuery there is little overhead of including backbone aswell.

Backbone is great for structuring and organizing your code.

You can use the backbone-localstorage adapter to save your models to localStorage.

You can then save a backlog of all your models or get them from a RESTful server for your history view.

A solid alternative to backbone would be spine which is also a lightweight MVC library. Spine has a more traditional MVC attitude and is only 2kB

Upvotes: 2

Related Questions