Simplify zapthreads embed initialization

This commit is contained in:
thePR0M3TH3AN committed 2025-10-13 13:35:43 -04:00
1 parent 5ce20e11dc
commit 6045dfd741
1 file changed
+8 -18
+8 -18
View File
@@ -21013,35 +21013,25 @@
}
return options;
}
const zapthreadsCleanupMap = new WeakMap();
async function initializeZapthreadsEmbed(element) {
if (!(element instanceof Element)) return;
const previousCleanup = zapthreadsCleanupMap.get(element);
if (typeof previousCleanup === "function") {
try {
previousCleanup();
} catch (error) {
console.error("[zapthreads] cleanup failed", error);
}
zapthreadsCleanupMap.delete(element);
async function mountZapthreadsEmbed(element) {
if (!(element instanceof Element) || !element.isConnected) {
return;
}
if (!element.isConnected) return;
try {
const cleanup = await initZapthreadsEmbed({
await initZapthreadsEmbed({
root: element,
options: getZapthreadsOptions(element),
dataUtils: zapthreadsDataUtils,
});
if (typeof cleanup === "function") {
zapthreadsCleanupMap.set(element, cleanup);
}
} catch (error) {
console.error("[zapthreads] failed to initialize embed", error);
}
}
function initializeZapthreadsEmbeds() {
document.querySelectorAll("zap-threads").forEach((element) => {
initializeZapthreadsEmbed(element);
const elements = document.querySelectorAll("zap-threads");
if (elements.length === 0) return;
elements.forEach((element) => {
mountZapthreadsEmbed(element);
});
}
if (document.readyState === "loading") {