Skip to content

Instantly share code, notes, and snippets.

@dasa
Forked from diverted247/IN > Storage.ts
Last active August 29, 2015 13:57
Show Gist options
  • Save dasa/9646985 to your computer and use it in GitHub Desktop.
Save dasa/9646985 to your computer and use it in GitHub Desktop.
define(["require", "exports", "./Storage"], function(require, exports, Storage) {
Storage.fetch();
});
import Storage = require("./Storage");
Storage.fetch();
define(["require", "exports"], function(require, exports) {
var Storage = (function () {
function Storage() {
}
Storage.fetch = function () {
if (!Storage.todos) {
Storage.todos = JSON.parse(localStorage.getItem(Storage.STORAGE_KEY) || '[]');
}
return Storage.todos;
};
Storage.save = function () {
localStorage.setItem(Storage.STORAGE_KEY, JSON.stringify(Storage.todos));
};
Storage.STORAGE_KEY = 'todos-vuejs';
Storage.todos = null;
return Storage;
})();
return Storage;
});
class Storage{
static STORAGE_KEY:string = 'todos-vuejs';
static todos:any = null;
static fetch(){
if( !Storage.todos ){
Storage.todos = JSON.parse( localStorage.getItem( Storage.STORAGE_KEY ) || '[]' );
}
return Storage.todos;
}
static save(){
localStorage.setItem( Storage.STORAGE_KEY , JSON.stringify( Storage.todos ) );
}
}
export = Storage;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment