How to use the localforage.setItem 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 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 cybersemics / em / src / util / loadLocalState.js View on Github external
Object.keys(newState.contextIndex).map(key => {
        const contexts = newState.contextIndex[key]
        contexts.forEach(context => {
          context.value = context.value || context.key
          delete context.key // eslint-disable-line fp/no-delete
        })
        return localForage.setItem('contextIndex-' + key, contexts)
      }),
github xyfir / illuminsight / components / Edit.tsx View on Github external
async function onDelete(): Promise {
    if (!pub) return;

    // Remove pub from list
    let pubs: Illuminsight.Pub[] = await localForage.getItem('pub-list');
    pubs = pubs.filter((p) => p.id != pub.id);
    await localForage.setItem('pub-list', pubs);

    // Delete pub files
    await localForage.removeItem(`pub-${pub.id}`);
    await localForage.removeItem(`pub-cover-${pub.id}`);

    // Update tags
    await saveTags(pubs);

    // Take us home and notify user
    history.replace('/');
    enqueueSnackbar(`${pub.name} was deleted`);
  }
github MadLittleMods / postcss-css-variables / playground / src / js / services / PlaygroundPersistentSettingsDAO.js View on Github external
function savePersistently() {
	console.log('Saving settings persistently...');
	return localforage.setItem(
		playgroundSettingsStoreKey,
		JSON.stringify(settings.toJS())
	)
	.then(function() {
		console.log('Settings saved!', settings.toJS());
	})
	.catch(function(e) {
		console.log('Error saving:', e);

		throw e;
	});
}
github Procempa / meteor-keycloak-auth / keycloak-client.js View on Github external
.then( ( adapter ) => {
							localforage
								.setItem( KEYCLOAK_INPROGESS_KEY, true )
								.then( () => {
									adapter.init( { onLoad: 'login-required', checkLoginIframe: false } )
										.success( () => {
											this._user = this._buildUser( adapter );
											localforage.setItem( KEYCLOAK_TOKEN_EXPIRES_KEY, adapter.tokenParsed.exp );
											this._trigger( 'login', this._user );
											this._logout = adapter.logout;
											this._loggedIn = true;
											localforage
												.removeItem( KEYCLOAK_INPROGESS_KEY )
												.then( () => {
													let event = new HashChangeEvent( 'hashchange' );
													event.oldURL = '_oauth';
													event.newURL = location.hash;
													window.dispatchEvent( event );
github adregan / sw-redux / js / service / middleware.js View on Github external
export const reset = store => next => action => {
  if (action.type !== 'ACTIVATE') return next(action);

  if (typeof action.count !== 'undefined') {
    localforage.setItem('state', action.count)
      .then(localforage.setItem('id', action.id));

    return store.dispatch({type: 'RESET', state: action.count, id: action.id});
  }

  let state;
  localforage.getItem('state')
    .then(savedState => {
      state = savedState;
      return localforage.getItem('id');
    })
    .then(id => store.dispatch({type: 'RESET', state, id}))
    .catch(err => console.error(err) && next(action));
};
github cyrilletuzi / angular-async-local-storage / projects / localforage / src / app / app.component.ts View on Github external
ngOnInit() {

    const key = 'key';
    const value = 'hello world';

    localForage.setItem(key, value).then(() => {

      this.storageMap.get(key, { type: 'string' }).subscribe((result) => {
        this.title = result || 'not ok';
      });

    });

  }
github devnews / web / src / data / index.js View on Github external
.end((error, response) => {
                let data = [];
                for (let product of response.body.data.posts) {
                    data.push({
                        id: product.id,
                        name: product.name,
                        tagline: product.tagline,
                        url: product.redirect_url,
                        votesCount: product.votes_count,
                        commentsCount: product.comments_count,
                        discussionUrl: product.discussion_url,
                    });
                }

                localforage.setItem('producthunt', {
                    expires: moment().add(expiresDuration, expiresUnit).valueOf(),
                    data
                });

                callback(data);
            });
    });