Created
March 18, 2014 18:57
-
-
Save diverted247/9626944 to your computer and use it in GitHub Desktop.
TypeScript 0.9.7 CommonJS Modules using import and require()
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
| import foo = require("./Storage"); | |
| foo.Storage.fetch(); |
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
| 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 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
| var foo = require("./Storage"); | |
| foo.Storage.fetch(); |
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
| 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