Skip to content

Instantly share code, notes, and snippets.

@samyok
Created December 4, 2019 02:36
Show Gist options
  • Save samyok/ce149697ab8106e7c333eca5324013d6 to your computer and use it in GitHub Desktop.
Save samyok/ce149697ab8106e7c333eca5324013d6 to your computer and use it in GitHub Desktop.
musicblocks test
// Copyright (c) 2019 Samyok Nepal
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the The GNU Affero General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
//
// You should have received a copy of the GNU Affero General Public
// License along with this library; if not, write to the Free Software
// Foundation, 51 Franklin Street, Suite 500 Boston, MA 02110-1335 USA
function Storage(options) {
this.config = options;
this._forage = localforage.createInstance(this.config);
this.driver = localforage.driver();
this.log = logItem => console.log(`[${this.driver}] ${logItem}`);
this.setItem = (key, value, callback) => {
this._forage.setItem(key, value, (err) => {
this.log(`Saved ${key} as ${value}`);
if (err) throw err;
callback(err);
});
};
this.getItem = (key, callback) => {
this._forage.getItem(key, (err, result) => {
if (err) throw err;
callback(result);
});
};
this.removeItem = (key, callback) => {
this._forage.removeItem(key, (err) => {
if (err) throw err;
else this.log(`Cleared ${key}`);
callback();
})
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment