benjaminapetersen / auto-app

An auto app built in collaboration with jonathanyiv
0 stars 0 forks source link

Persistence #9

Open benjaminapetersen opened 9 years ago

benjaminapetersen commented 9 years ago

Initially we may use localStorage because it is quick and easy. However, its probably essential for us to decide on what is best for a mobile/desktop/laptop experience. Can they all use the same? Probably not. LocalStorage is in-browser/on-device. There is no sync. We can worry about sync at some point, definitely will be a paid feature somehow.

benjaminapetersen commented 9 years ago

Some clues for this:

angular.module('auto.main')
  .factory('storage', [
    '$log', 
    function($log) {
        $log.log('hi, im the storage service....');
    }
  ]);
<username>:<pass>:<item>  {object_to_store}

actual javascript code looks kind of like this:

// things to think about here... should we store each vehicle individually?
window.localStorage.setItem('ben:vehicles:sienna', JSON.stringify({name: "sienna"}));
// OR, could we store the whole array of vehicles?
// this may be a performance improvement. 
// we don't necessarily need to read from & write to localStorage constantly,
// we can read once & get the whole list loaded into the service & return individual 
// vehicles to the user's view, and just write the whole list of vehicles every time the user
// saves one of them.  It really depends on how many vehicles we expect a user to have.
// if the list is small, this may be fine.  If a user was reading & writing 1000 vehicles, this 
// may be an inefficient idea.
window.localStorage.setItem('ben:vehicles', JSON.stringify([{ },{ }.{ }]));

so, your controller must ask for the storage service and be able to .get(), .get(), .remove() things.

  // service must at least provide this as the return object (API)
  return {
    get: function(id) {

    },   // userid:vehicle:vid
    set: function(id_of_item, object_to_save) {
       window.localStorage.setItem(id_of_item, JSON.stringify(object_to_save));
    },  // userid:vehicle:vid, {    }
    remove: function(id) {}  
  }
benjaminapetersen commented 9 years ago

Oh, from your current branch, feature/vehicle-list-flow, create a new branch, called feature/persistence and work from there.