Skip to content

Instantly share code, notes, and snippets.

@diverted247
Last active August 29, 2015 13:57
Show Gist options
  • Save diverted247/9626802 to your computer and use it in GitHub Desktop.
Save diverted247/9626802 to your computer and use it in GitHub Desktop.
TypeScript 0.9.7 AMD Modules using import and require()
import foo = require("./Storage");
foo.Storage.fetch();
export 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 ) );
}
}
define(["require", "exports", "./Storage"], function(require, exports, foo) {
foo.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;
})();
exports.Storage = Storage;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment