Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return Promise.resolve(objectStore[key])
},
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++
length: async function() {
return this._map.size();
},
removeItem: async function(key) {
this._map.delete(key);
},
setItem: async function(key, value) {
const originalValue = this._map.get(key);
console.log('setItem', this._map, key, value);
this._map.set(key, value);
return originalValue;
}
};
// Add the driver to localForage.
localforage.defineDriver(memoryDriver);
}
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import localforage from 'localforage';
import localDriver from 'localforage-webextensionstorage-driver/local';
import syncDriver from 'localforage-webextensionstorage-driver/sync';
import { initializeInterceptors } from 'utils/requestInterceptors';
const env = process.env.NODE_ENV === 'production' ? 'prod' : 'dev';
/* eslint-disable import/no-dynamic-require */
const configureStore = require(`./store/configureStore.${env}.js`);
const Root = require(`./components/Root/Root.${env}.js`);
// Ensure drivers are loaded and ready before rendering
Promise.all([
localforage.defineDriver(localDriver),
localforage.defineDriver(syncDriver),
])
.then(() => localforage.setDriver('webExtensionLocalStorage'))
.then(() => localforage.getItem('options'))
.then(options => {
if (options && options.sync) {
return localforage.setDriver('webExtensionSyncStorage');
}
return null;
})
.then(() => {
const store = configureStore.default();
initializeInterceptors(store);
ReactDOM.render(
/**
* Module variables
*/
const log = debug( 'calypso:localforage' );
const config = {
name: 'calypso',
storeName: 'calypso_store',
version: 1.0,
description: 'Calypso Browser Storage',
driver: [ localforage.INDEXEDDB, localforage.WEBSQL, localforage.LOCALSTORAGE ],
};
let _ready = false;
// Promise that resolves when our localforage configuration has been applied
const localForagePromise = localforage
.defineDriver( localforageBypass )
.then( () => {
localforage.config( config );
_ready = true;
return localforage;
} )
.catch( error => log( 'Configuring localforage: %s', error ) );
// Wraps a function to run after waiting until a promise has resolved.
// The promise should contain the original object for context.
const wrapOriginalFunc = ( promise, original ) => {
return function( ...args ) {
return promise.then( context => original.apply( context, args ) );
};
};
import { Provider } from 'react-redux';
import localforage from 'localforage';
import localDriver from 'localforage-webextensionstorage-driver/local';
import syncDriver from 'localforage-webextensionstorage-driver/sync';
import { initializeInterceptors } from 'utils/requestInterceptors';
const env = process.env.NODE_ENV === 'production' ? 'prod' : 'dev';
/* eslint-disable import/no-dynamic-require */
const configureStore = require(`./store/configureStore.${env}.js`);
const Root = require(`./components/Root/Root.${env}.js`);
// Ensure drivers are loaded and ready before rendering
Promise.all([
localforage.defineDriver(localDriver),
localforage.defineDriver(syncDriver),
])
.then(() => localforage.setDriver('webExtensionLocalStorage'))
.then(() => localforage.getItem('options'))
.then(options => {
if (options && options.sync) {
return localforage.setDriver('webExtensionSyncStorage');
}
return null;
})
.then(() => {
const store = configureStore.default();
initializeInterceptors(store);
ReactDOM.render(
it('Should take a localforage instance as store', async () => {
await localforage.defineDriver(memoryDriver)
const store = localforage.createInstance({
driver: memoryDriver._driver
})
const apiWithStore = setup({
cache: {
store
}
})
const url = 'https://httpbin.org/get'
const response = await apiWithStore({
url,
method: 'get'
beforeAll(async () => {
await localforage.defineDriver(memoryStorageDriver);
});
getItem(key: string): Promise {
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: {
this._dbPromise = new Promise((resolve, reject) => {
if (typeof process !== 'undefined') {
const noopDriver = getNoopDriver();
resolve(noopDriver);
return;
}
let db: LocalForage;
const defaultConfig = getDefaultConfig();
const actualConfig = Object.assign(defaultConfig, config || {});
LocalForage.defineDriver(CordovaSQLiteDriver)
.then(() => {
db = LocalForage.createInstance(actualConfig);
})
.then(() =>
db.setDriver(this._getDriverOrder(actualConfig.driverOrder))
)
.then(() => {
this._driver = db.driver();
resolve(db);
})
.catch(reason => reject(reason));
});
}