function writeFile (filename, contents, options, callback) { // Options do not matter in browser setup if (typeof options === 'function') { callback = options; } localforage.setItem(filename, contents, function () { return callback(); }); }
async remove (key) { delete this.cache[key] if (this.storage) { return this.storage.removeItem(key) } }
function rename (filename, newFilename, callback) { localforage.getItem(filename, function (err, value) { if (value === null) { localforage.removeItem(newFilename, function () { return callback(); }); } else { localforage.setItem(newFilename, value, function () { localforage.removeItem(filename, function () { return callback(); }); }); } }); }
constructor (storage) { this.cache = {} try { this.storage = localForage.createInstance({ name: 'countdown_1' }) } catch (e) { console.log(e) console.warn('Failed to create localForage instance. Settings will not be saved after page closes.') } }
get keys () { if (this.storage) { return this.storage.keys() } else { return Object.keys(this.cache) } }
localforage.getItem('user_token').then(token => { if (token && !store.state.user_token) { store.commit('USER_TOKEN', token) api .getUser(token) .then(user_info => { console.log(user_info) store.commit('USER_INFO', user_info.data.user) }) .catch(console.error) } })
getUser(token) { return http .get('/', { headers: { Authorization: 'Bearer ' + token } }) .catch(err => { console.log('remove user_token') localforage.removeItem('user_token') }) }
function appendFile (filename, toAppend, options, callback) { // Options do not matter in browser setup if (typeof options === 'function') { callback = options; } localforage.getItem(filename, function (err, contents) { contents = contents || ''; contents += toAppend; localforage.setItem(filename, contents, function () { return callback(); }); }); }
function unlink (filename, callback) { localforage.removeItem(filename, function () { return callback(); }); }
async set (key, value) { this.cache[key] = value if (this.storage) { try { await this.storage.setItem(key, value) } catch (e) { console.warn(e) console.warn('Could not save to database') } } }
function readFile (filename, options, callback) { // Options do not matter in browser setup if (typeof options === 'function') { callback = options; } localforage.getItem(filename, function (err, contents) { return callback(null, contents || ''); }); }
function exists (filename, callback) { localforage.getItem(filename, function (err, value) { if (value !== null) { // Even if value is undefined, localforage returns null return callback(true); } else { return callback(false); } }); }
constructor () { this.cache = {} this.initialized = false try { this.storage = localForage.createInstance({ name: 'countdown_1' }) } catch (e) { console.log(e) console.warn('Failed to create localForage instance. Settings will not be saved after page closes.') } }
function readFile (filename, options, callback) { // Options do not matter in browser setup if (typeof options === 'function') { callback = options; } localforage.getItem(filename, function (err, contents) { return callback(null, contents || ''); }); }