From 7218849ae2f43aee6b3462a30e07caf5bac3d22b Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Sat, 22 Jan 2022 13:49:40 +0100 Subject: add a mapping/resources installation dialog --- common/indexeddb.js | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'common/indexeddb.js') diff --git a/common/indexeddb.js b/common/indexeddb.js index a18c9be..1b8e574 100644 --- a/common/indexeddb.js +++ b/common/indexeddb.js @@ -61,8 +61,8 @@ const version_nr = ver => Array.reduce(ver.slice(0, 3), nr_reductor, [2, 0])[1]; const stores = [ ["files", {keyPath: "hash_key"}], ["file_uses", {keyPath: "hash_key"}], - ["resources", {keyPath: "identifier"}], - ["mappings", {keyPath: "identifier"}], + ["resource", {keyPath: "identifier"}], + ["mapping", {keyPath: "identifier"}], ["settings", {keyPath: "name"}], ["blocking", {keyPath: "pattern"}], ["repos", {keyPath: "url"}] @@ -175,8 +175,8 @@ function make_context(transaction, files) } /* - * item_store_names should be an array with either string "mappings", string - * "resources" or both. files should be a dict with values being contents of + * item_store_names should be an array with either string "mapping", string + * "resource" or both. files should be an object with values being contents of * files that are to be possibly saved in this transaction and keys of the form * `sha256-`. * @@ -292,7 +292,7 @@ async function finalize_transaction(context) */ async function save_items(data) { - const item_store_names = ["resources", "mappings"]; + const item_store_names = ["resource", "mapping"]; const context = await start_items_transaction(item_store_names, data.files); return _save_items(data.resources, data.mappings, context); @@ -323,15 +323,13 @@ async function _save_items(resources, mappings, context) */ async function save_item(item, context) { - const store_name = {resource: "resources", mapping: "mappings"}[item.type]; - for (const file_ref of entities.get_files(item)) await incr_file_uses(context, file_ref); - broadcast.prepare(context.sender, `idb_changes_${store_name}`, + broadcast.prepare(context.sender, `idb_changes_${item.type}`, item.identifier); - await _remove_item(store_name, item.identifier, context, false); - await idb_put(context.transaction, store_name, item); + await _remove_item(item.type, item.identifier, context, false); + await idb_put(context.transaction, item.type, item); } #EXPORT save_item @@ -360,10 +358,10 @@ async function remove_item(store_name, identifier, context) await idb_del(context.transaction, store_name, identifier); } -const remove_resource = (id, ctx) => remove_item("resources", id, ctx); +const remove_resource = (id, ctx) => remove_item("resource", id, ctx); #EXPORT remove_resource -const remove_mapping = (id, ctx) => remove_item("mappings", id, ctx); +const remove_mapping = (id, ctx) => remove_item("mapping", id, ctx); #EXPORT remove_mapping /* Function to retrieve all items from a given store. */ @@ -460,7 +458,8 @@ async function track_change(tracking, key) /* * Monitor changes to `store_name` IndexedDB object store. * - * `store_name` should be either "resources", "mappings" or "settings". + * `store_name` should be either "resource", "mapping", "settings", "blocking" + * or "repos". * * `onchange` should be a callback that will be called when an item is added, * modified or removed from the store. The callback will be passed an object @@ -491,7 +490,7 @@ async function start_tracking(store_name, onchange) } const track = {}; -const trackable = ["resources", "mappings", "settings", "blocking", "repos"]; +const trackable = ["resource", "mapping", "settings", "blocking", "repos"]; for (const store_name of trackable) track[store_name] = onchange => start_tracking(store_name, onchange); #EXPORT track -- cgit v1.2.3