feat: Refactor worker.js to use dynamic function dispatch

This commit is contained in:
Harvey Zack committed 2024-06-04 19:12:11 +08:00
1 parent d57a13a2bd
commit 69d99cc478
4 files changed
+15 -7

No files matched your search

@@ -129,10 +129,14 @@ function getDanmuTop({ target, visibles, clientWidth, clientHeight, marginBottom
onmessage = (event) => {
const { data } = event;
if (!data.id) return;
const top = getDanmuTop(data);
if (!data.id || !data.type) return;
const fns = { getDanmuTop };
const fn = fns[data.type];
const result = fn(data);
self.postMessage({
top,
result,
id: data.id,
});
};