Created
July 21, 2017 18:31
-
-
Save dannycoates/975c6bd58df2d19a617ce8b5dbac27c0 to your computer and use it in GitHub Desktop.
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
class Storage { | |
constructor(engine) { | |
this.engine = engine | |
} | |
get totalDownloads() { | |
return Number(this.engine.getItem('totalDownloads')) | |
} | |
set totalDownloads(n) { | |
this.engine.setItem('totalDownloads', n) | |
} | |
get files() { | |
const fs = [] | |
for (let i = 0; i < this.engine.length; i++) { | |
const k = this.engine.key(i) | |
if (isFile(k)) { | |
fs.push(JSON.parse(this.engine.getItem(k))) // parse or whatever else | |
} | |
} | |
return fs | |
} | |
addFile(file) { | |
// something something engine.setItem(...) | |
} | |
// etc | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment