Skip to content

Instantly share code, notes, and snippets.

@dannycoates
Created July 21, 2017 18:31
Show Gist options
  • Save dannycoates/975c6bd58df2d19a617ce8b5dbac27c0 to your computer and use it in GitHub Desktop.
Save dannycoates/975c6bd58df2d19a617ce8b5dbac27c0 to your computer and use it in GitHub Desktop.
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