How to use the localforage.defineDriver function in localforage

To help you get started, we’ve selected a few localforage examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github championswimmer / vuex-persist / test / async-plugin-emits-restored.spec.ts View on Github external
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++
github tdlib / td / example / web / tdweb / src / worker.js View on Github external
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);
}
github RESTEDClient / RESTED / src / index.js View on Github external
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(
github Automattic / wp-calypso / client / lib / localforage / index.js View on Github external
/**
 * 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 ) );
	};
};
github RESTEDClient / RESTED / src / index.js View on Github external
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(
github RasCarlito / axios-cache-adapter / test / spec / index.spec.js View on Github external
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'
github querycap / reactorx / @reactorx / persister / src / __tests__ / index.spec.tsx View on Github external
beforeAll(async () => {
    await localforage.defineDriver(memoryStorageDriver);
  });
github championswimmer / vuex-persist / test / vuex-asyncstorage.spec.ts View on Github external
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: {
github ionic-team / ionic-storage / src / storage.ts View on Github external
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));
    });
  }