stores/indexeddb.js
function db(op, fn){
  if(!indexedDB){
    return fn(new Error('store `indexeddb` not supported by this browser'));
  }
  if(typeof op === 'function'){
    fn = op;
    op = 'readwrite';
  }

  if(source !== null){
    return fn(null, source.transaction(module.exports.prefix, op).objectStore(module.exports.prefix));
  }
  var req = indexedDB.open(module.exports.prefix, 1);
  req.onerror = function(e){
    fn(e);
  };
  req.onupgradeneeded = function(){
    // First time setup: create an empty object store
    req.result.createObjectStore(module.exports.prefix);
  };
  req.onsuccess = function() {
    source = req.result;
    db(op, fn);
  };
}
function db(op, fn){
  if(!indexedDB){
    return fn(new Error('store `indexeddb` not supported by this browser'));
  }
  if(typeof op === 'function'){
    fn = op;
    op = 'readwrite';
  }

  if(source !== null){
    return fn(null, source.transaction(module.exports.prefix, op).objectStore(module.exports.prefix));
  }
  var req = indexedDB.open(module.exports.prefix, 1);
  req.onerror = function(e){
    fn(e);
  };
  req.onupgradeneeded = function(){
    // First time setup: create an empty object store
    req.result.createObjectStore(module.exports.prefix);
  };
  req.onsuccess = function() {
    source = req.result;
    db(op, fn);
  };
}
function db ( op , fn ) { if ( ! indexedDB ) { return fn ( new Error ( 'store `indexeddb` not supported by this browser' ) ) ; } if ( typeof op === 'function' ) { fn = op ; op = 'readwrite' ; } if ( source !== null ) { return fn ( null , source . transaction ( module . exports . prefix , op ) . objectStore ( module . exports . prefix ) ) ; } var req = indexedDB . open ( module . exports . prefix , 1 ) ; req . onerror = function ( e ) { fn ( e ) ; } ; req . onupgradeneeded = function ( ) { // First time setup: create an empty object store req . result . createObjectStore ( module . exports . prefix ) ; } ; req . onsuccess = function ( ) { source = req . result ; db ( op , fn ) ; } ; }
Wrapper function that handles creating or acquiring the object store if it hasn't been already.
Wrapper function that handles creating or acquiring the object store if it hasn t been already .