aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOmar Rizwan <omar.rizwan@gmail.com>2020-10-28 14:14:57 -0700
committerOmar Rizwan <omar.rizwan@gmail.com>2020-10-28 14:14:57 -0700
commitc85bb26264767f533e955013c4c5b8d7795164b7 (patch)
treec08b1cafb767bbf355e2110398256752649aa57e
parenta9cb8e14af87af949e44f20fc40591eebeadcb66 (diff)
ancestor-building kind of works.
-rw-r--r--README.md4
-rw-r--r--extension/background.js33
2 files changed, 24 insertions, 13 deletions
diff --git a/README.md b/README.md
index 9425907..7f152cb 100644
--- a/README.md
+++ b/README.md
@@ -71,6 +71,10 @@ marshalling)
TODO: make diagrams?
+## license
+
+GPLv3
+
## hmm
it's way too hard to make an extension. even 'make an extension' is
diff --git a/extension/background.js b/extension/background.js
index eb120a7..15ac2db 100644
--- a/extension/background.js
+++ b/extension/background.js
@@ -119,21 +119,23 @@ router["/tabs/by-title/*"] = {
* },
*/
-// ensure that there are entries for all parents
+
+// ensure that there are entries for all ancestors
for (let key in router) {
let path = key;
while (path !== "/") { // walk upward through the path
path = path.substr(0, path.lastIndexOf("/"));
+ if (path == '') path = '/';
if (!router[path]) {
// find all direct children
- const children = Object.keys(router)
- .filter(k => k.startsWith(path) &&
- (k.match(/\//g) || []).length ===
- (path.match(/\//g) || []).length + 1)
- .map(k => k.substr(path.length + 1))
+ let children = Object.keys(router)
+ .filter(k => k.startsWith(path) &&
+ (k.match(/\//g) || []).length ===
+ (path.match(/\//g) || []).length + 1)
+ .map(k => k.substr((path === '/' ? 0 : path.length) + 1).split('/')[0]);
+ children = [...new Set(children)];
- if (path == '') path = '/';
router[path] = {entries() {
return children;
}}
@@ -145,6 +147,9 @@ if (TESTING) {
(async () => {
assert.deepEqual(await router['/tabs/by-id/*'].entries(), ['url', 'title', 'text', 'control']);
assert.deepEqual(await router['/'].entries(), ['tabs']);
+ assert.deepEqual(await router['/tabs'].entries(), ['by-id', 'by-title']);
+
+ assert.deepEqual(findRoute('/tabs/by-id/TABID/url'), router['/tabs/by-id/*/url']);
})()
}
@@ -158,13 +163,15 @@ function findRoute(path) {
let routingPath = "";
for (let segment of pathSegments) {
- if (router[routingPath + "/" + segment]) {
+ if (routingPath === "/") { routingPath = ""; }
+
+ if (router[routingPath + "/*"]) {
+ routingPath += "/*";
+ } else if (router[routingPath + "/" + segment]) {
routingPath += "/" + segment;
} else {
- routingPath += "/*";
+ throw new UnixError(unix.ENOENT);
}
-
- if (!router[routingPath]) throw new UnixError(unix.ENOENT);
}
return router[routingPath];
}
@@ -227,12 +234,12 @@ const ops = {
},
async readdir({path}) {
let route = findRoute(path);
- if (route.readdir) return { entries: await route.readdir(path) };
- return { entries: [".", "..", ...Object.keys(route)] };
+ if (route.entries) return { entries: await route.entries(path) };
},
async releasedir({path}) {
let route = findRoute(path);
if (route.releasedir) return route.releasedir(path);
+ else return {};
}
};