How to use localforage - 10 common examples

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
},
  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 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 JohnSimerlink / branches_front_end_private / app / components / knawledgeMap / knawledgeMap.js View on Github external
LocalForage.getItem('g').then(async gFromLocalForage => {
                    // console.log("result of LocalForage is ", gFromLocalForage, JSON.stringify(gFromLocalForage), g, JSON.stringify(g))
                    if (window.fullCache && gFromLocalForage){
                        g = gFromLocalForage
                    }
                    else {
                        LocalForage.setItem('g', g)
                        console.log("LOAD DATA AND INIT ABOUT TO BE CALLED")
                        loadDataAndInit()
                    }
                })
            })
github gnosis / dx-react / src / actions / blockchain.ts View on Github external
case 'NONE':
        console.error('No Web3 instance detected - please check your wallet provider.')
        break

      default:
        console.log('Detected connection to an UNKNOWN network -- localhost?')
        defaultTokens = {
          hash: 'local',
          tokens: await tokensMap('1.0'),
        }
        console.log('LocalHost Token List: ', defaultTokens.tokens.elements)
        break
    }

    // set tokens to localForage
    await localForage.setItem('defaultTokens', defaultTokens)
  }

  // Set user's custom IPFS hash for tokens exists in localForage
  if (customListHash) dispatch(setIPFSFileHashAndPath({ fileHash: customListHash }))

  if (customTokens) {
    const customTokensWithDecimals = await getAllTokenDecimals(customTokens)

    // reset localForage customTokens w/decimals filled in
    localForage.setItem('customTokens', customTokensWithDecimals)
    dispatch(setCustomTokenList({ customTokenList: customTokensWithDecimals }))
    dispatch(setTokenListType({ type: 'CUSTOM' }))
  } else if (customListHash) {
    const fileContent = await ipfsFetchFromHash(customListHash)

    const json = fileContent
github MadLittleMods / postcss-css-variables / playground / src / js / services / PlaygroundPersistentSettingsDAO.js View on Github external
function retrieveSettingsFromPersistantStorage() {
	console.log('Retrieving settings from persistent storage...');


	return localforage.getItem(playgroundSettingsStoreKey).then((value) => {
		let parsedObject = JSON.parse(value) || {};
		settings = settings.mergeDeep(parsedObject);
	})
	.then(function() {
		// Look through the settings and fire off the actions since we just updated them from localforage
		iterateOverObjectRecursively(settings, (path, value) => {
			if(Immutable.Map.isMap(value)) {
				let actionCallback = value.get('action');

				if(actionCallback) {
					actionCallback(value.get('value'));
				}
			}
		});
	})
	.catch(function(e) {
github nolanlawson / serviceworker-update-demo / sw.js View on Github external
event.waitUntil((async () => {
    var activeVersionPromise = localForage.getItem('active-version');
    var cache = await caches.open('cache-' + version);

    await cache.addAll(staticContent);

    var activeVersion = await activeVersionPromise;

    console.log('activeVersion:', activeVersion, 'current version:', version);
    if (!activeVersion ||
      semver.parse(activeVersion).major === semver.parse(version).major) {
      // wrapping in an if while Chrome 40 is still around
      if (self.skipWaiting) {
        console.log('skipWaiting()');
        self.skipWaiting();
      }
    }
  })());
github MicroPad / Electron / preload.ts View on Github external
async function initSpellcheck(): Promise {
	shouldSpellCheck = (await localforage.getItem('should spell check')) !== false;
	if (!shouldSpellCheck) {
		ContextMenu({ showInspectElement: false });
		return;
	}

	const dictAU = new Typo('en_AU', await readFile(path.join(__dirname, 'node_modules/dictionary-en-au/index.aff')), await readFile(path.join(__dirname, '/node_modules/dictionary-en-au/index.dic')));
	const dictUS = new Typo('en_US', await readFile(path.join(__dirname, 'node_modules/dictionary-en-us/index.aff')), await readFile(path.join(__dirname, '/node_modules/dictionary-en-us/index.dic')));

	userDict = new Set(await localforage.getItem('user dict'));

	setTimeout(() => {
		webFrame.setSpellCheckProvider('en-AU', false, {
			spellCheck(word) {
				// Don't spellcheck anything with a number in it
				if (/\d/.test(word)) return true;

				return userDict.has(word) || dictAU.check(word) || dictUS.check(word);
			}
		});
	}, 1000);

	ContextMenu({
		prepend: (actions, params) => {
			const word: string = params.misspelledWord;
			if (!word) return [];
github johannesjo / super-productivity / src / app / core / persistence / database.service.ts View on Github external
private _init() {
    localForage.config({
      driver: [localForage.INDEXEDDB, localForage.WEBSQL, localForage.LOCALSTORAGE],
      name: 'SUP',
      // version: 1.0,
      storeName: 'SUP_STORE', // Should be alphanumeric, with underscores.
      description: 'All data for Super Productivity 2'
    });
  }
}
github rakannimer / react-orchestra / web / src / platforms / web / stores / index.js View on Github external
init() {
    localforage.config({
      // driver: localforage.INDEXEDDB, // Force WebSQL; same as using setDriver()
      name: 'react_orchestra',
      version: 1.0,
      size: 4980736, // Size of database, in bytes. WebSQL-only for now.
      storeName: 'react_orchestra', // Should be alphanumeric, with underscores.
      description: 'React Orchestra storage to cache mp3 notes and store app state',
    });
    this.db = localforage.createInstance({
      name: 'react_orchestra',
    });
  },
  async set(key, value) {
github xyfir / illuminsight / lib / app / index.ts View on Github external
enve: Illuminsight.Env;
    }
  }
}
/* eslint-enable */

if ('serviceWorker' in navigator) {
  window.addEventListener('load', () => {
    navigator.serviceWorker
      .register('/sw.js')
      .then((r) => console.log('SW', r))
      .catch((e) => console.error('SW', e));
  });
}

localForage.config({ driver: localForage.INDEXEDDB, name: 'illuminsight' });

render(React.createElement(hot(App)), document.getElementById('content'));