How to use localforage

Comprehensive localforage code examples:

How to use localforage.clear:

333
334
335
336
337
338
339
340
341
342
 * Remove all manifest and fragment store
 * @returns {Promise} promise asynchronously resolved
 * @instance
 */
function dropAll() {
    return localforage.clear().then(function () {
        return Promise.resolve();
    }).catch(function (err) {
        return Promise.reject(err);
    });

How to use localforage.default:

694
695
696
697
698
699
700
701
702
703
};
var EMPTY = Symbol();
var createListsAtom = (storeName, reducer, initialState) => {
  function IndexedDBStorage(dbName) {
    if (typeof window !== "undefined") {
      const db = import_localforage.default.createInstance({
        name: dbName,
        storeName
      });
      return {

How to use localforage.config:

44
45
46
47
48
49
50
51
52

if (typeof window === 'undefined') {
    return;
}

localforage.config({
    driver: localforage.INDEXEDDB,
    name: 'dash_offline_db'
});

How to use localforage.dropInstance:

346
347
348
349
350
351
352
353
354
355
 * Remove framgent store given its name
 * @param {string} storeName
 * @instance
 */
function dropFragmentStore(storeName) {
    localforage.dropInstance({
        driver: localforage.INDEXEDDB,
        name: 'dash_offline_db',
        version: 1.0,
        storeName: storeName

How to use localforage.createInstance:

395
396
397
398
399
400
401
402
403
404
 * @param {string} storeName
 * @returns {Promise} promise asynchronously resolved
 * @instance
 */
function deleteFragmentStore(storeName) {
    localforage.createInstance({
        name: 'dash_offline_db',
        storeName: storeName
    });
    return localforage.dropInstance({

How to use localforage.removeItem:

73
74
75
76
77
78
79
80
81
82
    this.#storageId = storageId;
}

async destroy(storageId) {
    if (storageId || this.#storageId)
        await localforage.removeItem(storageId || this.#storageId);
}

init(values) {
    const listeners = [];

How to use localforage.setItem:

44
45
46
47
48
49
50
51
52
53
    console.log("Saving", this.#storageId);
    this.onBeforeSave?.();
    clearTimeout(this.#timeout);
    this.#timeout = 0;
    this.#dirtyCount = 0;
    localforage.setItem(this.#storageId, this.toJSON());
    this.onAfterSave?.();
}

toJSON() {

How to use localforage.getItem:

63
64
65
66
67
68
69
70
71
72
    return json;
}

async useStorage(storageId){
    this.#storageId = null;
    const data = await localforage.getItem(storageId);
    if (data) {
        for (let k in data)
            this.set(k, data[k]);
    }