How to use the localforage.ready 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 davidgilbertson / know-it-all / app / data / store.js View on Github external
*   Then, when I update the store, I iterate over it, and if I have to update some data
 *   like 'selected' or 'expanded' or 'score'
 *   then I already have a reference to the item that needs to update, so
 *   I can say item.score = 1; item.update()
 *
 */

import localforage from 'localforage';
import {
  ANALYTICS_STRINGS,
  EVENTS,
  SCORES,
} from '../utils/constants';
import logTiming from '../utils/logTiming';

localforage.ready().catch(() => {
  console.warn(`localforage threw an error. If this is during webpack build, everything is OK`);
});

const diskStore = localforage.createInstance({
  name: `know-it-all`,
  version: 1,
});

// this is used to define if an item should be re-rendered
// it should contain anything that can be changed by a user
const serializeItemState = item => [
  item.scoreKey,
  !!item.visible,
  !!item.expanded,
  !!item.selected,
].join(``);
github jplusplus / the-accountant / src / index.js View on Github external
import Character from './components/character/character.service.js';
import Ending from './components/ending/ending.service.js';
import Var from './components/var/var.service.js';
// Configurations
import {routesConfig, gaRun} from './routes';
import chartRun from './chart';
import markedConfig from './marked.js';
import modernizrRun from './modernizr.js';
import {translateConfig, translateRun} from './translate.js';
// Import SCSS with webpack
import './index.scss';
// For specs
export const app = 'app';
// Fix an issue with localforage when the app is executed from an iframe
// @see https://github.com/localForage/localForage/issues/631#issuecomment-267265554
localforage.ready().catch(angular.noop);

angular
  .module(app, [
    'ngAnimate',
    'ngCookies',
    'hc.marked',
    'pascalprecht.translate',
    'ui.router',
    'luegg.directives',
    'cfp.hotkeys',
    'ngFitText',
    'LocalForageModule',
    'gridshore.c3js.chart',
    'duScroll',
    'tmh.dynamicLocale',
    '720kb.socialshare'
github paritytech / fether / packages / fether-react / src / utils / localForage.js View on Github external
const debug = Debug('localForage');

// Use RxJS as Observable in localforage-observable
// https://github.com/localForage/localForage-observable#using-a-different-observable-library
localForage.newObservable.factory = subscribeFn =>
  Observable.create(subscribeFn);

/**
 * Use localStorage.
 *
 * TODO: Maybe other drivers might be more appropriate?
 */
localForage.setDriver(localForage.LOCALSTORAGE);

// Initialize localForage
const ready$ = from(localForage.ready());

/**
 * Create an Observable that will fire when a localForage item updates.
 *
 * @param {string} item - The localForage key to query
 */
const localForage$ = memoize(item => {
  debug(`Listening to "${item}".`);
  return ready$.pipe(switchMap(() => localForage.getItemObservable(item)));
});

export default localForage$;
github johannesjo / super-productivity / src / app / core / persistence / database.service.ts View on Github external
      return localForage.ready().then(() => localForage.removeItem(key));
    } catch (e) {
github johannesjo / super-productivity / src / app / core / persistence / database.service.ts View on Github external
async clearDatabase(): Promise {
    try {
      return localForage.ready().then(() => localForage.clear());
    } catch (e) {
      this._snackService.open({type: 'ERROR', msg: T.GLOBAL_SNACK.ERR_DB_CLEAR});
    }
  }
github PokeAPI / pokeapi-js-wrapper / src / getter.js View on Github external
return new Promise((resolve, reject) => {
        localForage.ready()
            .then(() => {
                localForage.getItem(`${CACHE_PREFIX}${url}`)
                    .then(value => {
                        if (value === null) {
                            loadUrl(url).then(res => {resolve(res)})
                                .catch(err => {reject(err)});
                        } else {
                            resolve(addCacheMark(value))
                        }
                    })
                    .catch(error => {
                        loadUrl(url).then(res => {resolve(res)})
                            .catch(err => {reject(err)});
                    });
            })
            .catch(err => {
github johannesjo / super-productivity / src / app / core / persistence / database.service.ts View on Github external
async load(key: string): Promise {
    try {
      return localForage.ready().then(() => localForage.getItem(key));
    } catch (e) {
      this._snackService.open({type: 'ERROR', msg: T.GLOBAL_SNACK.ERR_DB_LOAD});
    }
  }
github johannesjo / super-productivity / src / app / core / persistence / database.service.ts View on Github external
async save(key: string, data: any): Promise {
    try {
      return localForage.ready().then(() => localForage.setItem(key, data));
    } catch (e) {
      this._snackService.open({type: 'ERROR', msg: T.GLOBAL_SNACK.ERR_DB_SAVE});
    }
  }