Refractoring the LocalStorage module

We are going to treat the tags as data instead of string. Before that, we will refractor the storage as an individual module inside data object.

 1// Storage Module
 3 = {};
 4 = function(name, list) {
 5    localStorage.setItem(name, JSON.stringify(list));
 6  }
 7 = function(name) {
 8    return JSON.parse(localStorage.getItem(name)) || [];
 9  }

Note: we used .call(data) so the this inside that annonymous function refers to the data object.

When we load the books list:

1data.books ="books");

When we need to save the book list, we call the following:"books", this.books);

What’s next? We’re going to take a look at “Planning the tags data structure”.

overlaied image when clicked on thumbnail

Makzan | Mobile web app dev with phonegap | Table of Content