How to use the idb-keyval.get function in idb-keyval

To help you get started, we’ve selected a few idb-keyval 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 DestinyItemManager / DIM / src / app / inventory / advanced-write-actions.ts View on Github external
export async function getAwaToken(
  account: DestinyAccount,
  action: AwaType,
  item?: D2Item
): Promise {
  if (!awaCache) {
    // load from cache first time
    awaCache = (await get('awa-tokens')) || {};
  }

  let info = awaCache[action];
  if (!info || !tokenValid(info)) {
    try {
      // Note: Error messages should be handled by other components. This is just to tell them to check the app.
      showNotification({
        type: 'info',
        title: t('AWA.ConfirmTitle'),
        body: t('AWA.ConfirmDescription')
      });

      info = awaCache[action] = {
        ...(await requestAdvancedWriteActionToken(account, action, item)),
        used: 0
      };
github facebookarchive / atom-ide-ui / modules / atom-ide-ui / pkg / atom-ide-terminal / lib / main.js View on Github external
async function openTerminalInNewPaneItem(
  options: atom$WorkspaceOpenOptions & {
    terminalInfo: TerminalInfo,
  },
): Promise {
  const existingPane = atom.workspace.paneForURI(TERMINAL_URI);

  // TODO: The flow types are wrong. paneForURI returns a nullable pane
  if (!existingPane) {
    // eslint-disable-next-line nuclide-internal/atom-apis
    return atom.workspace.open(TERMINAL_URI, options);
  }

  const [item, hasShownNux] = await Promise.all([
    atom.workspace.createItemForURI(TERMINAL_URI, options),
    AsyncStorage.get(MOVED_TERMINAL_NUX_SHOWN_KEY),
  ]);
  existingPane.activateItem(item);
  existingPane.activate();

  if (!hasShownNux) {
    invariant(item instanceof TerminalView);
    showTooltipForPaneItem(item);
    AsyncStorage.set(MOVED_TERMINAL_NUX_SHOWN_KEY, true);
  }

  return item;
}
github DestinyItemManager / DIM / src / app / storage / indexed-db-storage.js View on Github external
get: function() {
      return idbKeyval.get('DIM-data').then((value) => {
        // Fall back to local storage as a migration aid
        if (!value || _.isEmpty(value)) {
          return JSON.parse(localStorage.getItem('DIM'));
        }
        return value;
      });
    },
github ritz078 / raaga / workers / loadInstrument.worker.ts View on Github external
const fetchInstrumentFromRemote = async (
  instrument = DRUMS_NAME,
  isDrums?: boolean
) => {
  const instrumentId = getInstrumentIdByValue(instrument);
  const { drums, tracks } = midiFontData;

  if (isDrums && drums) {
    return drums;
  } else if (tracks[instrumentId]) {
    return tracks[instrumentId];
  }

  if (isDrums) {
    const _drums = await getInIDB(DRUMS_NAME);
    if (drums) {
      return _drums;
    }
  } else {
    const track = await getInIDB(getIdbKey(instrumentId));
    if (track) return track;
  }

  let url = !process.env.DEV
    ? `https://midifonts.s3.ap-south-1.amazonaws.com/${instrument}-mp3.js`
    : `https://gleitz.github.io/midi-js-soundfonts/MusyngKite/${instrument}-mp3.js`;

  if (isDrums) {
    url =
      "https://raw.githubusercontent.com/dave4mpls/midi-js-soundfonts-with-drums/gh-pages/drums-mp3.js";
  }
github facebookarchive / atom-ide-ui / modules / atom-ide-ui / pkg / atom-ide-diagnostics-ui / lib / main.js View on Github external
        .switchMap(() => AsyncStorage.get(NUX_ASYNC_STORAGE_KEY))
        .filter(seen => !seen)
github DestinyItemManager / DIM / src / app / manifest / manifest-service.ts View on Github external
private loadManifestFromCache(version): IPromise {
    if (alwaysLoadRemote) {
      return $q.reject(new Error("Testing - always load remote"));
    }

    this.statusText = `${t('Manifest.Load')}...`;
    const currentManifestVersion = localStorage.getItem(this.localStorageKey);
    if (currentManifestVersion === version) {
      return $q.when(idbKeyval.get(this.idbKey)).then((typedArray: Uint8Array) => {
        if (!typedArray) {
          throw new Error("Empty cached manifest file");
        }
        return typedArray;
      });
    } else {
      ga('send', 'event', 'Manifest', 'Need New Manifest');
      return $q.reject(new Error(`version mismatch: ${version} ${currentManifestVersion}`));
    }
  }
}
github deckgo / deckdeckgo / studio / src / app / pages / core / app-signin / app-signin.tsx View on Github external
return new Promise(async (resolve) => {
            const mergeInfo: MergeInformation = await get('deckdeckgo_redirect_info');

            if (mergeInfo && mergeInfo.userId && mergeInfo.userToken) {
                resolve();
                return;
            }

            await set('deckdeckgo_redirect', this.redirect ? this.redirect : '/');

            const observables = [];
            observables.push(this.authService.watch().pipe(take(1)));
            observables.push(this.userService.watch().pipe(take(1)));
            observables.push(this.deckEditorService.watch().pipe(take(1)));

            forkJoin(observables).subscribe(async ([authUser, user, deck]: [AuthUser, User, Deck]) => {
                await set('deckdeckgo_redirect_info', {
                    deckId: deck ? deck.id : null,
github ritz078 / raaga / workers / loadInstrument.worker.ts View on Github external
const instrumentId = getInstrumentIdByValue(instrument);
  const { drums, tracks } = midiFontData;

  if (isDrums && drums) {
    return drums;
  } else if (tracks[instrumentId]) {
    return tracks[instrumentId];
  }

  if (isDrums) {
    const _drums = await getInIDB(DRUMS_NAME);
    if (drums) {
      return _drums;
    }
  } else {
    const track = await getInIDB(getIdbKey(instrumentId));
    if (track) return track;
  }

  let url = !process.env.DEV
    ? `https://midifonts.s3.ap-south-1.amazonaws.com/${instrument}-mp3.js`
    : `https://gleitz.github.io/midi-js-soundfonts/MusyngKite/${instrument}-mp3.js`;

  if (isDrums) {
    url =
      "https://raw.githubusercontent.com/dave4mpls/midi-js-soundfonts-with-drums/gh-pages/drums-mp3.js";
  }
  const response = await fetch(url);
  const data = await response.text();
  const result = midiJsToJson(data);

  if (isDrums) {
github ritz078 / raaga / utils / Player.ts View on Github external
public loadSoundFont = async (instrument = instruments[0].value) => {
    let audio;
    try {
      audio = await getFromIDB(instrument);
      if (!audio) audio = await this.fetchInstrumentFromRemote(instrument);
    } catch (e) {
      audio = await this.fetchInstrumentFromRemote(instrument);
    }

    const promises = Object.keys(audio).map(
      key => new Promise(resolve => this.sampler.add(key, audio[key], resolve))
    );
    return Promise.all(promises);
  };

idb-keyval

A super-simple-small keyval store built on top of IndexedDB

Apache-2.0
Latest version published 1 year ago

Package Health Score

70 / 100
Full package analysis