Created
July 30, 2017 01:58
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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