rever load.js changes

This commit is contained in:
b 2021-04-02 14:53:18 -07:00
parent 97d5cf6e60
commit dbcba4ff18
2 changed files with 52 additions and 65 deletions

63
load.js
View file

@ -13,47 +13,40 @@ let itemLists = new Map();
* Load item set from local DB. Calls init() on success.
*/
async function load_local(init_func) {
if (!itemMap) {
let get_tx = db.transaction(['item_db', 'set_db'], 'readonly');
let sets_store = get_tx.objectStore('set_db');
let get_store = get_tx.objectStore('item_db');
let request = get_store.getAll();
request.onerror = function(event) {
console.log("Could not read local item db...");
let get_tx = db.transaction(['item_db', 'set_db'], 'readonly');
let sets_store = get_tx.objectStore('set_db');
let get_store = get_tx.objectStore('item_db');
let request = get_store.getAll();
request.onerror = function(event) {
console.log("Could not read local item db...");
}
request.onsuccess = function(event) {
console.log("Successfully read local item db.");
items = request.result;
//console.log(items);
let request2 = sets_store.openCursor();
sets = {};
request2.onerror = function(event) {
console.log("Could not read local set db...");
}
request.onsuccess = function(event) {
console.log("Successfully read local item db.");
items = request.result;
//console.log(items);
let request2 = sets_store.openCursor();
sets = {};
request2.onerror = function(event) {
console.log("Could not read local set db...");
request2.onsuccess = function(event) {
let cursor = event.target.result;
if (cursor) {
sets[cursor.primaryKey] = cursor.value;
cursor.continue();
}
request2.onsuccess = function(event) {
let cursor = event.target.result;
if (cursor) {
sets[cursor.primaryKey] = cursor.value;
cursor.continue();
}
else {
console.log("Successfully read local set db.");
//console.log(sets);
init_maps();
}
else {
console.log("Successfully read local set db.");
//console.log(sets);
init_maps();
}
}
await get_tx.complete;
db.close();
} else {
console.log("Item and Set dbs already loaded!");
}
if (itemMap) {
init_func();
}
await get_tx.complete;
db.close();
init_func();
}
/*

View file

@ -21,35 +21,29 @@ let recipeIDMap;
*/
async function ing_load_local(init_func) {
console.log("IngMap is: \n " + ingMap);
if (!ingMap) {
let get_tx = idb.transaction(['ing_db', 'recipe_db'], 'readonly');
let ings_store = get_tx.objectStore('ing_db');
let recipes_store = get_tx.objectStore('recipe_db');
let request3 = ings_store.getAll();
request3.onerror = function(event) {
console.log("Could not read local ingredient db...");
}
request3.onsuccess = function(event) {
console.log("Successfully read local ingredient db.");
ings = request3.result;
let request4 = recipes_store.getAll();
request4.onerror = function(event) {
console.log("Could not read local recipe db...");
}
request4.onsuccess = function(event) {
console.log("Successfully read local recipe db.");
recipes = request4.result;
init_ing_maps();
}
}
await get_tx.complete;
idb.close();
} else {
console.log("Ingredient and Recipe dbs already loaded!");
let get_tx = idb.transaction(['ing_db', 'recipe_db'], 'readonly');
let ings_store = get_tx.objectStore('ing_db');
let recipes_store = get_tx.objectStore('recipe_db');
let request3 = ings_store.getAll();
request3.onerror = function(event) {
console.log("Could not read local ingredient db...");
}
if (ingMap) {
init_func();
request3.onsuccess = function(event) {
console.log("Successfully read local ingredient db.");
ings = request3.result;
let request4 = recipes_store.getAll();
request4.onerror = function(event) {
console.log("Could not read local recipe db...");
}
request4.onsuccess = function(event) {
console.log("Successfully read local recipe db.");
recipes = request4.result;
init_ing_maps();
}
}
await get_tx.complete;
idb.close();
init_func();
}
function clean_ing(ing) {