Skip to content

Instantly share code, notes, and snippets.

@PatrickJS
Created December 12, 2023 00:42
Show Gist options
  • Select an option

  • Save PatrickJS/24493db00e89b741ef0f1e7900281492 to your computer and use it in GitHub Desktop.

Select an option

Save PatrickJS/24493db00e89b741ef0f1e7900281492 to your computer and use it in GitHub Desktop.
if (attrValue) {
const container = element.closest("[q\\:container]");
const base = new URL(getAttribute(container, "q:base"), doc.baseURI);
for (const qrl of attrValue.split("\n")) {
const url = new URL(qrl, base);
const symbolName = url.hash.replace(/^#?([^?[|]*).*$/, "$1") || "default";
const reqTime = performance.now();
let handler = container.qFuncs?.get?.(qrl);
const isSync = qrl.startsWith("#");
if (!handler) {
const module = import(
/* @vite-ignore */
url.href.split("#")[0]);
resolveContainer(container);
handler = (await module)[symbolName];
}
const previousCtx = doc.__q_context__;
if (element.isConnected) {
try {
doc.__q_context__ = [ element, ev, url ];
isSync || emitEvent("qsymbol", {
symbol: symbolName,
element: element,
reqTime: reqTime
});
await handler(ev, element);
} finally {
doc.__q_context__ = previousCtx;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment