How to use the localforage.getItem 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 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 gnosis / dx-react / src / actions / blockchain.ts View on Github external
export const getTokenList = (network?: number | string) => async (dispatch: Function, getState: () => State): Promise => {
  let [defaultTokens, customTokens, customListHash] = await Promise.all<{ hash: string, tokens: DefaultTokens}, DefaultTokens['elements'], string>([
    localForage.getItem('defaultTokens'),
    localForage.getItem('customTokens'),
    localForage.getItem('customListHash'),
  ])

  const { ipfsFetchFromHash } = await promisedIPFS
  const { getNetwork } = await promisedWeb3()

  // when switching Networks, NetworkListeners in events.js should delete localForage tokenList
  // meaning this would be FALSE on network change and app reset
  // check that localForage has both something in defaultTokens AND that the localForage hash === the local latest hash in globals
  const areTokensAvailableAndUpdated = defaultTokens && defaultTokens.hash === TokenListHashMap[network]

  if (!areTokensAvailableAndUpdated) {
    network = network || await getNetwork() || 'NONE'

    // user has tokens in localStorage BUT hash is not updated
    if (defaultTokens) await localForage.removeItem('defaultTokens')
github codecasts / spa-starter-kit / client / src / app / auth / vuex / actions.js View on Github external
export const checkUserToken = ({ dispatch, state }) => {
  // If the token exists then all validation has already been done
  if (!isEmpty(state.token)) {
    return Promise.resolve(state.token)
  }

  /**
   * Token does not exist yet
   * - Recover it from localstorage
   * - Recover also the user, validating the token also
   */
  return localforage.getItem(userTokenStorageKey)
    .then((token) => {
      if (isEmpty(token)) {
        // Token is not saved in localstorage
        return Promise.reject('NO_TOKEN') // Reject promise
      }
      // Put the token in the vuex store
      return dispatch('setToken', token) // keep promise chain
    })
    // With the token in hand, retrieves the user's data, validating the token
    .then(() => dispatch('loadUser'))
}
github bimohxh / jsonon / src / views / _tool_box.vue View on Github external
restoreHistory: function (history) {
      localforage.getItem('history_' + history.key, (err, value) => {
        if (!err) {
          this.$emit('setVal', value.data)
        }
      })
    },
github resonatecoop / stream2own / beta / stores / app.js View on Github external
emitter.on('users:auth', async (reload = true) => {
      try {
        const { user, clientId } = await promiseHash({
          user: storage.getItem('user'),
          clientId: storage.getItem('clientId')
        })

        if (user && clientId) {
          state.api = generateApi({ clientId, user })
          state.user = Object.assign(state.user, user)

          emitter.emit(state.events.RENDER)

          const response = await state.api.auth.tokens({ uid: user.uid })

          if (response.status !== 401) {
            const { accessToken: token, clientId } = response
            state.api = generateApi({ token, clientId, user: state.api.user })
          } else {
            emitter.emit('logout')
github gokulkrishh / fuel-price / src / routes / mylist / index.js View on Github external
getMyFavList() {
		let { myList } = this.state;
		var showEmptyMsg = false;
		localForage.getItem("myList").then(myList => {
			if (!myList || isEmpty(myList)) {
				myList = {};
				showEmptyMsg = true;
			} else {
				this.getMyListFuelPrices();
			}
			this.setState({ myList, showEmptyMsg });
		});
	}
github resonatecoop / stream2own / embed / stores / app.js View on Github external
emitter.on('users:auth', async () => {
    try {
      const { user, clientId } = await promiseHash({
        user: storage.getItem('user'),
        clientId: storage.getItem('clientId')
      })

      if (user && clientId) {
        state.api = generateApi({ clientId, user })

        const response = await state.api.auth.tokens({ uid: user.uid })

        if (response) {
          const { accessToken: token, clientId } = response
          state.api = generateApi({ token, clientId, user: state.api.user })
        }
      }
    } catch (err) {
      log.error(err)
    }