PlugOS refactor and other tweaks (#631)

* Prep for in-process plug loading (e.g. for CF workers, Deno Deploy)
* Prototype of fixed in-process loading plugs
* Fix: buttons not to scroll with content
* Better positioning of modal especially on mobile
* Move query caching outside query
* Fix annoying mouse behavior when filter box appears
* Page navigator search tweaks
This commit is contained in:
Zef Hemel
2024-01-15 16:43:12 +01:00
committed by GitHub
parent a9eb252658
commit a2dbf7b3db
65 changed files with 591 additions and 617 deletions
-23
View File
@@ -1,23 +0,0 @@
import { sleep } from "$sb/lib/async.ts";
import { assertEquals } from "../test_deps.ts";
import { LimitedMap } from "./limited_map.ts";
Deno.test("limited map", async () => {
const mp = new LimitedMap<string>(3);
mp.set("a", "a");
mp.set("b", "b", 5);
mp.set("c", "c");
assertEquals(mp.get("a"), "a");
assertEquals(mp.get("b"), "b");
assertEquals(mp.get("c"), "c");
// Drops the first key
mp.set("d", "d");
// console.log(mp.toJSON());
assertEquals(mp.get("a"), undefined);
await sleep(10);
// "b" should have been dropped
assertEquals(mp.get("b"), undefined);
assertEquals(mp.get("c"), "c");
console.log(mp.toJSON());
});
-63
View File
@@ -1,63 +0,0 @@
type LimitedMapRecord<V> = { value: V; la: number };
export class LimitedMap<V> {
private map: Map<string, LimitedMapRecord<V>>;
constructor(
private maxSize: number,
initialJson: Record<string, LimitedMapRecord<V>> = {},
) {
this.map = new Map(Object.entries(initialJson));
}
/**
* @param key
* @param value
* @param ttl time to live (in ms)
*/
set(key: string, value: V, ttl?: number) {
if (ttl) {
setTimeout(() => {
this.map.delete(key);
}, ttl);
}
if (this.map.size >= this.maxSize) {
// Remove the oldest key before adding a new one
const oldestKey = this.getOldestKey();
this.map.delete(oldestKey!);
}
this.map.set(key, { value, la: Date.now() });
}
get(key: string): V | undefined {
const entry = this.map.get(key);
if (entry) {
// Update the last accessed timestamp
entry.la = Date.now();
return entry.value;
}
return undefined;
}
remove(key: string) {
this.map.delete(key);
}
toJSON() {
return Object.fromEntries(this.map.entries());
}
private getOldestKey(): string | undefined {
let oldestKey: string | undefined;
let oldestTimestamp: number | undefined;
for (const [key, entry] of this.map.entries()) {
if (!oldestTimestamp || entry.la < oldestTimestamp) {
oldestKey = key;
oldestTimestamp = entry.la;
}
}
return oldestKey;
}
}
+1 -1
View File
@@ -4,7 +4,7 @@ import { System } from "../plugos/system.ts";
const indexVersionKey = ["$indexVersion"];
// Bump this one every time a full reinxex is needed
const desiredIndexVersion = 2;
const desiredIndexVersion = 3;
let indexOngoing = false;
+1 -3
View File
@@ -16,9 +16,7 @@ export function languageSyscalls(): SysCallMapping {
}
return parse(lang, code);
},
"language.listLanguages": (
_ctx,
): string[] => {
"language.listLanguages": (): string[] => {
return Object.keys(builtinLanguages);
},
};