Skip to content

Instantly share code, notes, and snippets.

@masters3d
Created July 30, 2017 01:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masters3d/e7efbf231e817289cf8c67ad24fad127 to your computer and use it in GitHub Desktop.
Save masters3d/e7efbf231e817289cf8c67ad24fad127 to your computer and use it in GitHub Desktop.
This code saves a loads data from the localStorage object on the browser.
'use strict';
class DataController {
}
DataController.load = loadLocalStorage
DataController.save = saveLocalStorage
function loadLocalStorage() {
let rawData = localStorage.getItem('masters3d');
if (rawData !== null) {
let data = JSON.parse(rawData)
return {success:true, data}
} else {
return {success:false, data:{}}
}
}
/** @param {Object} data */
function saveLocalStorage(data) {
localStorage.setItem('masters3d', JSON.stringify(data))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment