Last active
August 29, 2015 13:57
-
-
Save diverted247/9626802 to your computer and use it in GitHub Desktop.
TypeScript 0.9.7 AMD Modules using import and require()
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
import foo = require("./Storage"); | |
foo.Storage.fetch(); |
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
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 ) ); | |
} | |
} |
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
define(["require", "exports", "./Storage"], function(require, exports, foo) { | |
foo.Storage.fetch(); | |
}); |
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
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