demo/wasm-util.js
function openDatabase() {
    return new Promise((resolve, reject) => {
      var request = indexedDB.open(dbName, dbVersion);
      request.onerror = reject.bind(null, 'Error opening wasm cache database');
      request.onsuccess = () => { resolve(request.result) };
      request.onupgradeneeded = event => {
        var db = request.result;
        if (db.objectStoreNames.contains(storeName)) {
            console.log(`Clearing out version ${event.oldVersion} wasm cache`);
            db.deleteObjectStore(storeName);
        }
        console.log(`Creating version ${event.newVersion} wasm cache`);
        db.createObjectStore(storeName)
      };
    });
  }
function openDatabase() {
    return new Promise((resolve, reject) => {
      var request = indexedDB.open(dbName, dbVersion);
      request.onerror = reject.bind(null, 'Error opening wasm cache database');
      request.onsuccess = () => { resolve(request.result) };
      request.onupgradeneeded = event => {
        var db = request.result;
        if (db.objectStoreNames.contains(storeName)) {
            console.log(`Clearing out version ${event.oldVersion} wasm cache`);
            db.deleteObjectStore(storeName);
        }
        console.log(`Creating version ${event.newVersion} wasm cache`);
        db.createObjectStore(storeName)
      };
    });
  }
function openDatabase ( ) { return new Promise ( ( resolve , reject ) => { var request = indexedDB . open ( dbName , dbVersion ) ; request . onerror = reject . bind ( null , 'Error opening wasm cache database' ) ; request . onsuccess = ( ) => { resolve ( request . result ) } ; request . onupgradeneeded = event => { var db = request . result ; if ( db . objectStoreNames . contains ( storeName ) ) { console . log ( ` ${ event . oldVersion } ` ) ; db . deleteObjectStore ( storeName ) ; } console . log ( ` ${ event . newVersion } ` ) ; db . createObjectStore ( storeName ) } ; } ) ; }
This helper function Promise-ifies the operation of opening an IndexedDB database and clearing out the cache when the version changes.
This helper function Promise - ifies the operation of opening an IndexedDB database and clearing out the cache when the version changes .