...

/

Adding Local Storage and a Location to Our Entities

Adding Local Storage and a Location to Our Entities

Learn how to configure our entities to web storage using the url property.

Our goal in this chapter is to modify our app to deal with persisted data instead of the in-memory management we’ve used up to this point. We’ll be using web storage to persist our data.

Since this is more advanced, the implementation details of the persistence layer are covered in the “Appendix: Using Web Storage for Persistence” chapter at the end of this course. You won’t need to understand the implementation details to follow along as we continue developing our app. Using web storage persistence will work the same as saving data to a remote server.

Adding the storage plugin files

Let’s take a look at the storage plugin files and add them to our index.html file.

Press + to interact
<!-- edited for brevity -->
<script src="./assets/js/vendor/underscore.js"></script>
<script src="./assets/js/vendor/backbone.js"></script>
<script src="./assets/js/vendor/backbone.localstorage.js"></script>
<script src="./assets/js/vendor/backbone.marionette.js"></script>
<script src="./assets/js/app.js"></script>
<script src="./assets/js/apps/config/storage/localstorage.js"></script>
<script src="./assets/js/entities/contact.js"></script>

Adding the url property

Backbone models and collections need to indicate where they are located on a server. And since we said our persistence strategy would work just like using a remote server, our ContactCollection will need a url ...