Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
},
iterate() {},
key() {},
keys() {},
length() {},
removeItem() {},
setItem(key: string, data: T): Promise {
return Promise.resolve((objectStore[key] = data))
}
}
/* tslint:enable:no-empty */
Vue.use(Vuex)
localForage.defineDriver(MockForageStorage as any)
localForage.setDriver('objectStorage')
const vuexPersist = new VuexPersistence({
key: 'restored_test',
asyncStorage: true,
storage: localForage,
reducer: (state) => ({ count: state.count })
})
const storeOpts = {
state: {
count: 0
},
mutations: {
increment(state) {
state.count++
}
// LICENSE : MIT
"use strict";
import Immutable from "immutable-store"
import localforage from "localforage"
localforage.setDriver([localforage.INDEXEDDB, localforage.WEBSQL]);
export var keys = {
restore: Symbol("restore")
};
export function setStorage(storeName, state) {
return new Promise((resolve, reject) => {
var serialized = JSON.stringify(state);
resolve(serialized);
}).then(serialized => {
return localforage.setItem(storeName, serialized);
});
}
export function getStorage(storeName) {
return localforage.getItem(storeName).then(state => {
if (state == null) {
return {}
}
import Debug from '../utils/debug';
const debug = Debug('localForage');
// Use RxJS as Observable in localforage-observable
// https://github.com/localForage/localForage-observable#using-a-different-observable-library
localForage.newObservable.factory = subscribeFn =>
Observable.create(subscribeFn);
/**
* Use localStorage.
*
* TODO: Maybe other drivers might be more appropriate?
*/
localForage.setDriver(localForage.LOCALSTORAGE);
// Initialize localForage
const ready$ = from(localForage.ready());
/**
* Create an Observable that will fire when a localForage item updates.
*
* @param {string} item - The localForage key to query
*/
const localForage$ = memoize(item => {
debug(`Listening to "${item}".`);
return ready$.pipe(switchMap(() => localForage.getItemObservable(item)));
});
export default localForage$;
const store = createStore(
rootReducer,
initialState,
enhancer,
);
// Configure localforage Indexeddb setting ( for redux-persist)
localforage.config({
driver : localforage.INDEXEDDB, // Force WebSQL; same as using setDriver()
name : 'bookie',
version : 1.0,
// storeName : 'store_name', // Should be alphanumeric, with underscores.
description : 'desc'
});
localforage.setDriver(localforage.INDEXEDDB);
// Create filter to whitelist only subset of the redux store
const subsetFilterTransform = createTransform(
(inboundState, key) => {
if (key ==='rawHistory') {
// Only persist rawHistoryByAccountId for history reducer
const savedState = inboundState.filter((v, k) => k === 'rawHistoryByAccountId');
return savedState;
} else {
return inboundState;
}
},
(outboundState, key) => {
return outboundState
},
);
return Promise.resolve(objectStore[key])
},
iterate() { },
key() { },
keys() { },
length() { },
removeItem() { },
setItem(key: string, data: T): Promise {
return Promise.resolve((objectStore[key] = data))
}
}
Vue.use(Vuex)
localForage.defineDriver(MockForageStorage as any)
localForage.setDriver('objectStorage')
const vuexPersist = new VuexPersistence({
storage: localForage,
asyncStorage: true,
key: 'dafuq',
reducer: (state) => ({ dog: state.dog }),
filter: (mutation) => (mutation.type === 'dogBark')
})
const store = new Store({
state: {
dog: {
barks: 0
},
cat: {
mews: 0
async testLocalForage() {
await initLocalForage();
const DRIVERS = [
localforage.INDEXEDDB,
'memoryDriver',
localforage.LOCALSTORAGE,
localforage.WEBSQL,
localForageDrivers
];
for (const driverName of DRIVERS) {
console.log('Test ', driverName);
try {
await localforage.setDriver(driverName);
console.log('A');
await localforage.setItem('hello', 'world');
console.log('B');
const x = await localforage.getItem('hello');
console.log('got ', x);
await localforage.clear();
console.log('C');
} catch (error) {
console.log('Error', error);
}
}
}
constructor(driver)
{
if (driver) {
localforage.setDriver(driver);
}
}
Persist.prototype.driver = function (val) {
if (val !== undefined) {
switch (val.toUpperCase()) {
case 'LOCALSTORAGE':
localforage.setDriver(localforage.LOCALSTORAGE);
break;
case 'WEBSQL':
localforage.setDriver(localforage.WEBSQL);
break;
case 'INDEXEDDB':
localforage.setDriver(localforage.INDEXEDDB);
break;
default:
throw('ForerunnerDB.Persist: The persistence driver you have specified is not found. Please use either IndexedDB, WebSQL or LocalStorage!');
}
return this;
}
return localforage.driver();
};
.then(() => localforage.setDriver('webExtensionLocalStorage'))
.then(() => localforage.getItem('options'))
.then(options => {
if (options && options.sync) {
return localforage.setDriver('webExtensionSyncStorage');
}
return null;
})
.then(() => {