Store models in localStorage

Now that you know how to store and retrieve data from localStorage, it's time to store your models. In the following figure, you can see how to make data storage in local instead of a remote server.

By default, when you call the save() method on a model Backbone, it transforms the action into an HTTP request for a RESTFul server. To store the data in local, you need to change the default behavior in order to use localStorage instead of making HTTP requests; you will learn how to do this in the next section.

To make the storage layer maintainable, you will need to create a Backbone driver for localStorage first. The responsibility of the driver is to store and retrieve data from localStorage so that the connection between Backbone and localStorage is simpler:

Store models in localStorage

Figure 6.3 Store models in localStorage

In the next section, I will show you how to construct the DataStore driver to store the Backbone models in localStorage.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.54.136