Created
November 17, 2013 20:36
-
-
Save HenriqueSilverio/7517959 to your computer and use it in GitHub Desktop.
This file contains 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
//------------------------------------------ | |
// localStorage API and JSON objects | |
var TodoApp = TodoApp || {}; | |
(function(App) { | |
App.storage = App.storage || {}; | |
App.storage.set = function set(key, value) { | |
if(!key || !value) { return; } | |
if(typeof value === 'object') { | |
var data = JSON.stringify(value); | |
} | |
window.localStorage.setItem(key, data); | |
}; | |
App.storage.get = function get(key) { | |
var data = window.localStorage.getItem(key); | |
if(!data) { return; } | |
if(data[0] === '{') { | |
data = JSON.parse(data); | |
} | |
return data; | |
}; | |
}(TodoApp)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment