aboutsummaryrefslogtreecommitdiff
path: root/common/indexeddb.js
diff options
context:
space:
mode:
Diffstat (limited to 'common/indexeddb.js')
-rw-r--r--common/indexeddb.js27
1 files changed, 13 insertions, 14 deletions
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-<file's-sha256-sum>`.
*
@@ -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