How to use the localforage.LOCALSTORAGE 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 destruc7i0n / nani / src / store / localForage.js View on Github external
init () {
    try {
      // IOS fixed crash IndexedDB
      // DOMException: Connection to Indexed Database server lost. Refresh the page to try again
      // Disable IndexedDB for Safari
      let driver = []
      // eslint-disable-next-line no-useless-escape
      if (!!navigator.userAgent.match(/Version\/[\d\.]+.*Safari/)) {
        // console.log('Safari: No IndexedDB usage')
        driver = [
          localForage.WEBSQL,
          localForage.LOCALSTORAGE
        ]
      } else {
        driver = [
          localForage.INDEXEDDB,
          localForage.WEBSQL,
          localForage.LOCALSTORAGE
        ]
      }
      localForage.config({
        driver
      })
      return localForage
    } catch (error) {
      console.error('localForage.config Error: ', error)
    }
  }
github alfg / somafm / app / core / Storage.js View on Github external
import localforage from 'localforage';
import _ from 'lodash';

localforage.config({
  name: 'somafm',
  driver: localforage.LOCALSTORAGE,
  size: 4980736  // Default.
});

const storage = {

  getItem(key, cb) {
    localforage.getItem(key).then((val) =>
      cb(val)
    )
    .catch((err) => {
      cb(err);
    });
  },

  setItem(key, value, cb) {
    localforage.setItem(key, value).then((val) =>
github thomasgazzoni / ng2-platform / src / storage / storage.utils.ts View on Github external
) {

        const dbConfig: LocalForageOptions = {
            name: platformService.appName,
            version: 3,
            size: 4980736, // Size of database, in bytes. WebSQL-only for now.
            storeName: `${platformService.appName}_db`,
            description: `${platformService.appName}`,
        };

        this._db = localForage.createInstance(dbConfig);

        this._db.setDriver([
            localForage.INDEXEDDB,
            localForage.WEBSQL,
            localForage.LOCALSTORAGE,
        ]);

        this._db.length(); // Init db now
    }
github goodmind / treact / src / app / helpers / Telegram / pool.ts View on Github external
import * as localforage from 'localforage';
import BrowserStorage from 'mtproto-storage-browser';
import MTProto from 'telegram-mtproto';
import { appSettings, serverConfig } from './config';

export const storage = localforage.createInstance({
  driver: localforage.LOCALSTORAGE,
});

const app = {
  debug: true,
  storage: new BrowserStorage(storage),
};

const pool = MTProto({
  server: serverConfig,
  api: appSettings,
  app,
});

// TODO: use generic params and options
export const api = (method: string, params?: object, options?: object): Promise =>
  pool(method, params, options);
github zenghongtu / Remu / src / utils.ts View on Github external
import Axios from 'axios';
import { Modal, notification, message } from 'antd';
import { setupCache, setup } from 'axios-cache-adapter';
import localforage from 'localforage';

const baseURL = 'https://api.github.com';

export const forageStore = localforage.createInstance({
  // List of drivers used
  driver: [localforage.INDEXEDDB, localforage.LOCALSTORAGE],
  // Prefix all storage keys to prevent conflicts
  name: 'remu-cache',
});

export const request = setup({
  baseURL,
  cache: {
    maxAge: 60 * 60 * 1000,
    exclude: { query: false },
    store: forageStore,
    invalidate: async (config, request) => {
      if (request.clearCacheEntry) {
        // @ts-ignore
        await config.store.removeItem(config.uuid);
      }
    },
github beaverbuilder / assistant / src / system / utils / wordpress / cache-helper.js View on Github external
this.cacheConfig = {
			...defaults,
			...cacheConfig
		}

		this.log = this.log.bind( this )
		this.clearCachePrefix = this.clearCachePrefix.bind( this )
		this.inferPrefixFromUrl = this.inferPrefixFromUrl.bind( this )
		this.generateCacheKey = this.generateCacheKey.bind( this )
		this.shouldInvalidate = this.shouldInvalidate.bind( this )


		this.cacheStore = localforage.createInstance( {
			driver: [
				localforage.LOCALSTORAGE,
			],

			// Prefix all storage keys to prevent conflicts
			name: storagePrefix
		} )
	}
github Cloud-Player / web / src / app / modules / main / main.module.ts View on Github external
constructor() {
    /* TODO remove when it is working again
     * With the latest version of localforage Firefox can not use indexDB
     * "A mutation operation was attempted on a database that did not allow mutations."
     * Therefor we have to use localstorage until it is fixed
     */
    if (ClientDetector.getClient().name === ClientNames.Firefox) {
      localforage.config({
        driver: localforage.LOCALSTORAGE
      });
    }
  }
github ionic-team / ionic-storage / src / storage.ts View on Github external
return driverOrder.map(driver => {
      switch (driver) {
        case 'sqlite':
          return CordovaSQLiteDriver._driver;
        case 'indexeddb':
          return LocalForage.INDEXEDDB;
        case 'websql':
          return LocalForage.WEBSQL;
        case 'localstorage':
          return LocalForage.LOCALSTORAGE;
      }
    });
  }
github joelshepherd / tabliss / src / store / storage.ts View on Github external
function createDataStorage() {
  return localForage.createInstance({
    name: 'tabliss',
    driver:
      process.env.BUILD_TARGET === 'web'
        ? localForage.LOCALSTORAGE
        : syncDriver._driver,
    storeName: 'data',
  });
}