aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorjahoti <jahoti@tilde.team>2021-07-21 00:00:00 +0000
committerjahoti <jahoti@tilde.team>2021-07-21 00:00:00 +0000
commitefce4e9807889e9269534b19c8e0cbb4df527ecd (patch)
tree0a951d1b2b5c1470f7baf2be41585f5f08a09a9a /common
parentefd6ae83e6e48008988a2a11ac1658ec71dc82d2 (diff)
parentc483ae19e110ef5c1e539883a38fbc79b3dd4e4e (diff)
downloadbrowser-extension-efce4e9807889e9269534b19c8e0cbb4df527ecd.tar.gz
browser-extension-efce4e9807889e9269534b19c8e0cbb4df527ecd.zip
Merge remote-tracking branch 'origin/koszko' into jahoti
Diffstat (limited to 'common')
-rw-r--r--common/ajax.js39
-rw-r--r--common/storage_client.js17
-rw-r--r--common/stored_types.js3
3 files changed, 45 insertions, 14 deletions
diff --git a/common/ajax.js b/common/ajax.js
new file mode 100644
index 0000000..8082bbe
--- /dev/null
+++ b/common/ajax.js
@@ -0,0 +1,39 @@
+/**
+ * part of Hachette
+ * Wrapping XMLHttpRequest into a Promise.
+ *
+ * Copyright (C) 2021 Wojtek Kosior
+ * Redistribution terms are gathered in the `copyright' file.
+ */
+
+function ajax_callback()
+{
+ if (this.readyState == 4)
+ this.resolve_callback(this);
+}
+
+function initiate_ajax_request(resolve, reject, method, url)
+{
+ const xhttp = new XMLHttpRequest();
+ xhttp.resolve_callback = resolve;
+ xhttp.onreadystatechange = ajax_callback;
+ xhttp.open(method, url, true);
+ try {
+ xhttp.send();
+ } catch(e) {
+ console.log(e);
+ setTimeout(reject, 0);
+ }
+}
+
+function make_ajax_request(method, url)
+{
+ return new Promise((resolve, reject) =>
+ initiate_ajax_request(resolve, reject, method, url));
+}
+
+/*
+ * EXPORTS_START
+ * EXPORT make_ajax_request
+ * EXPORTS_END
+ */
diff --git a/common/storage_client.js b/common/storage_client.js
index 4849a65..2b2f495 100644
--- a/common/storage_client.js
+++ b/common/storage_client.js
@@ -8,7 +8,6 @@
/*
* IMPORTS_START
* IMPORT CONNECTION_TYPE
- * IMPORT TYPE_PREFIX
* IMPORT list_prefixes
* IMPORT make_once
* IMPORT browser
@@ -47,20 +46,10 @@ function handle_message(message)
setTimeout(resolve, 0, message.result);
}
-function list(name, prefix)
-{
- return {prefix, name, listeners : new Set()};
-}
-
-var scripts = list("scripts", TYPE_PREFIX.SCRIPT);
-var bags = list("bags", TYPE_PREFIX.BAG);
-var pages = list("pages", TYPE_PREFIX.PAGE);
+const list_by_prefix = {};
-const list_by_prefix = {
- [TYPE_PREFIX.SCRIPT] : scripts,
- [TYPE_PREFIX.BAG] : bags,
- [TYPE_PREFIX.PAGE] : pages
-};
+for (const prefix of list_prefixes)
+ list_by_prefix[prefix] = {prefix, listeners : new Set()};
var resolve_init;
diff --git a/common/stored_types.js b/common/stored_types.js
index a6f1f2f..304842b 100644
--- a/common/stored_types.js
+++ b/common/stored_types.js
@@ -14,6 +14,7 @@
*/
const TYPE_PREFIX = {
+ REPO: "r",
PAGE : "p",
BAG : "b",
SCRIPT : "s",
@@ -21,12 +22,14 @@ const TYPE_PREFIX = {
};
const TYPE_NAME = {
+ [TYPE_PREFIX.REPO] : "repo",
[TYPE_PREFIX.PAGE] : "page",
[TYPE_PREFIX.BAG] : "bag",
[TYPE_PREFIX.SCRIPT] : "script"
}
const list_prefixes = [
+ TYPE_PREFIX.REPO,
TYPE_PREFIX.PAGE,
TYPE_PREFIX.BAG,
TYPE_PREFIX.SCRIPT