Skip to content

Instantly share code, notes, and snippets.

@beattyml1
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save beattyml1/5d05cfcfa87bb2ecdfee to your computer and use it in GitHub Desktop.
Save beattyml1/5d05cfcfa87bb2ecdfee to your computer and use it in GitHub Desktop.
Functional First TypeScript Doodle
// really more a struct/interface
class DataStore {
store: (object: any) => string;
get: (key: string) => any;
}
class JsonDataStore: DataStore {
getRawJson: () => string;
static create(fileWriter: FileWriter): JsonDataStore {
return {
get: function(key: string): any {
return JSON.parse(fileWriter.readAll())[key];
},
store: function(object: any): string {
var allData = JSON.parse(fileWriter.readAll())[key];
allData[key] = object;
fileWriter.writeAll(JSON.stringify(allData);
},
getRawJson: function() {
return fileWriter.readAll();
}
}
}
}
var store = JsonDataStore.create(someRandomFileWriter);
store.store(myRandomObject);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment