LocalStorage paginated

Hello guys,

Contributing with more a tutorial, localStorage paginated:

 (function(){

     angular
        .module('started.app')
        .factory('LocalStorageTravel', LocalStorageTravel);

     function LocalStorageTravel(){

     var RESULT_BY_PAGE = 2;

     var services = {
       get: get,
       set: set,
       remove: remove,
       listar: listar
     }

    return services;

    function get(key) {
         return JSON.parse(localStorage.getItem(key));
     }

     function set(key, data) {
         localStorage.setItem(key, JSON.stringify(data));
    }

     function remove(key) {
         localStorage.removeItem(key);
     }

     function list(page) {

       var travels = [];

       var itemsLocalStorage = get('travels');

       var minResult = (page-1) * RESULT_BY_PAGE;
       var maxResult = page * RESULT_BY_PAGE;

       return itemsLocalStorage.slice(minResult, maxResult);

     }

}

})();
1 Like